X-Git-Url: https://jasonwoof.com/gitweb/?p=peach-html5-editor.git;a=blobdiff_plain;f=editor.coffee;h=45d505b717ee33972f0183ab7356b6c73ed2b5fc;hp=da7b3935fe350340dbf42ea522b1ed70b50687c4;hb=e6a74ba720a95ea89a2c244ea08437fd23e55c1c;hpb=2cd394146a6b75a69a00fdf91530fa2fe6e3a3c3 diff --git a/editor.coffee b/editor.coffee index da7b393..45d505b 100644 --- a/editor.coffee +++ b/editor.coffee @@ -352,8 +352,8 @@ tree_dedup_space = (tree) -> if n.type is TYPE_TEXT i = 0 while i < n.text.length # don't foreach, cb might remove chars - removed = cb n, i - unless removed + advance = cb n, i + if advance i += 1 if n.type is TYPE_TAG block = is_display_block n.el @@ -434,8 +434,14 @@ tree_dedup_space = (tree) -> next = n next_i = i next_px = null + advance = true if cur? removed = operate() + # don't advance (to the next character next time) if we removed a + # character from the same text node as ``next``, because doing so + # renumbers the indexes in that string + if removed and cur is next + advance = false else removed = false unless removed @@ -445,7 +451,7 @@ tree_dedup_space = (tree) -> cur = next cur_i = next_i cur_px = next_px - return removed + return advance queue null iterate tree, queue queue null