Skip to content

Commit

Permalink
Fix slab#181
Browse files Browse the repository at this point in the history
In firefox 31 with two consecutive newlines it would remove the first
div but the 2nd break on backspace (with ids added for clarity):

<div id='line-1'><br id='br-1'></div>
<div id='line-2'><br id='br-2'></div>

would result in:

<div id='line-1'><br id='br-2'></div>

Line 1 would incorrectly not rebuild() since the outerHTML did not
change. In FF31 a node can have a non-null parentNode even if the node
has been removed from the DOM. Thus our check if a rebuild is necessary
became insufficient. We now check all leaf nodes are descendants of the
line node, not just a parentNode exists.
  • Loading branch information
jhchen committed Aug 1, 2014
1 parent f0925e1 commit 9e0886d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/dom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ DOM =
DOM.removeNode(curNode.nextSibling)
curNode = nextNode

isAncestor: (ancestor, node, inclusive = false) ->
return inclusive if ancestor == node
while node
return true if node == ancestor
node = node.parentNode
return false

isIE: (maxVersion) ->
version = document.documentMode
return version and maxVersion >= version
Expand Down
4 changes: 2 additions & 2 deletions src/line.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ class Line extends LinkedList.Node

rebuild: (force = false) ->
if !force and @outerHTML? and @outerHTML == @node.outerHTML
if _.all(@leaves.toArray(), (leaf) ->
return leaf.node.parentNode?
if _.all(@leaves.toArray(), (leaf) =>
return DOM.isAncestor(@node, leaf.node)
)
return false
@node = Normalizer.normalizeNode(@node)
Expand Down

0 comments on commit 9e0886d

Please sign in to comment.