From 67a448db5d77ea7b467daf21a35cc2365b5ea9b2 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Tue, 12 Jan 2016 11:25:01 -0800 Subject: [PATCH] fix(selection): ExportedSelection must properly represent "None" --- .../contenteditable/exported-selection.coffee | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/components/contenteditable/exported-selection.coffee b/src/components/contenteditable/exported-selection.coffee index e0ab02a5d..d2d84b2ab 100644 --- a/src/components/contenteditable/exported-selection.coffee +++ b/src/components/contenteditable/exported-selection.coffee @@ -9,12 +9,15 @@ # class ExportedSelection constructor: (@rawSelection, @scopeNode) -> - @anchorNode = @rawSelection.anchorNode.cloneNode(true) - @anchorOffset = @rawSelection.anchorOffset - @anchorNodeIndex = DOMUtils.getNodeIndex(@scopeNode, @rawSelection.anchorNode) - @focusNode = @rawSelection.focusNode.cloneNode(true) - @focusOffset = @rawSelection.focusOffset - @focusNodeIndex = DOMUtils.getNodeIndex(@scopeNode, @rawSelection.focusNode) + @type = @rawSelection.type + + unless @type is 'None' + @anchorNode = @rawSelection.anchorNode.cloneNode(true) + @anchorOffset = @rawSelection.anchorOffset + @anchorNodeIndex = DOMUtils.getNodeIndex(@scopeNode, @rawSelection.anchorNode) + @focusNode = @rawSelection.focusNode.cloneNode(true) + @focusOffset = @rawSelection.focusOffset + @focusNodeIndex = DOMUtils.getNodeIndex(@scopeNode, @rawSelection.focusNode) @isCollapsed = @rawSelection.isCollapsed ### Public: Tests for equality amongst exported selections @@ -32,7 +35,10 @@ class ExportedSelection and `endNodeIndex` fields via the `DOMUtils.getNodeIndex` method. ### isEqual: (otherSelection) -> - return true if not otherSelection? + return false unless otherSelection? + return false if @type isnt otherSelection.type + + return true if @type is 'None' and otherSelection.type is 'None' return false if not otherSelection.anchorNode? or not otherSelection.focusNode? anchorIndex = DOMUtils.getNodeIndex(@scopeNode, otherSelection.anchorNode)