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
constructor: (@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)
# Create and anchor using the saved Range selector.
......@@ -86,16 +88,17 @@ class RangeAnchor extends Anchor
end: selector.endContainer
endOffset: selector.endOffset
}
range = new xpathRange.SerializedRange(data).normalize(root).toRange()
range = new xpathRange.SerializedRange(data).normalize(root)
return new RangeAnchor(range)
toRange: ->
return @range
toRange: (options = {}) ->
root = options.root or document.body
return @range.toRange()
toSelector: (options = {}) ->
root = options.root or document.body
ignoreSelector = options.ignoreSelector
range = new xpathRange.BrowserRange(@range).serialize(root, ignoreSelector)
range = @range.serialize(root, ignoreSelector)
return {
type: 'RangeSelector'
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