Commit f9ba24da authored by Randall Leeds's avatar Randall Leeds

Store the normalized range in the RangeAnchor

This makes it more robust against change by storing its description
at the container level rather than a DOM Range object that could get
mutated unpredictably by text node splitting.
parent 619c1cbf
...@@ -74,7 +74,9 @@ class RangeAnchor extends Anchor ...@@ -74,7 +74,9 @@ class RangeAnchor extends Anchor
constructor: (@range) -> constructor: (@range) ->
unless @range? then missingParameter('range') unless @range? then missingParameter('range')
@fromRange: (range) -> @fromRange: (range, options = {}) ->
root = options.root or document.body
range = xpathRange.sniff(range).normalize(root)
return new RangeAnchor(range) return new RangeAnchor(range)
# Create and anchor using the saved Range selector. # Create and anchor using the saved Range selector.
...@@ -86,16 +88,17 @@ class RangeAnchor extends Anchor ...@@ -86,16 +88,17 @@ class RangeAnchor extends Anchor
end: selector.endContainer end: selector.endContainer
endOffset: selector.endOffset endOffset: selector.endOffset
} }
range = new xpathRange.SerializedRange(data).normalize(root).toRange() range = new xpathRange.SerializedRange(data).normalize(root)
return new RangeAnchor(range) return new RangeAnchor(range)
toRange: -> toRange: (options = {}) ->
return @range root = options.root or document.body
return @range.toRange()
toSelector: (options = {}) -> toSelector: (options = {}) ->
root = options.root or document.body root = options.root or document.body
ignoreSelector = options.ignoreSelector ignoreSelector = options.ignoreSelector
range = new xpathRange.BrowserRange(@range).serialize(root, ignoreSelector) range = @range.serialize(root, ignoreSelector)
return { return {
type: 'RangeSelector' type: 'RangeSelector'
startContainer: range.start startContainer: range.start
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment