JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
bugfix in ws dedup when rm 1st space in inline
authorJason Woofenden <jason@jasonwoof.com>
Mon, 7 Mar 2016 01:24:28 +0000 (20:24 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Mon, 7 Mar 2016 01:24:28 +0000 (20:24 -0500)
editor.coffee
editor_tests_compiled.html

index da7b393..45d505b 100644 (file)
@@ -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
index 13338cf..8a51f25 100644 (file)
@@ -16,7 +16,7 @@
        <h1>Peach HTML5 Editor test page (compiled version)</h1>
        <p>This version of the editor test page requires that you've compiled all the source files. (Just run <code>make</code>).</p>
        <form action="#" method="get">
-       <p>HTML view. Changes here propagate when you remove your cursor (press tab or click outside)<br><textarea rows="9" cols="22" name="in" id="in">&lt;p&gt;  a b c d e f g h i j k l m n o p q r s t u v w x y z  a b c d e f g h i j k l m n o p q r s t u v w x y z                                                                a b c d e f g h i j k l m n o p q r s t u v w x y z  &lt;strong&gt;Bold &lt;em&gt; Italic+Bold&lt;/strong&gt; Italic&lt;/em&gt; Normal&lt;/p&gt;
+       <p>HTML view. Changes here propagate when you remove your cursor (press tab or click outside)<br><textarea rows="9" cols="22" name="in" id="in">&lt;p&gt;  a b c d e f g h i j k l m n o p q r s t u v w x y z  a b c d e f g h i j k l m n o p q r s t u v w x y z                                                                a b c d e f g h i j k l m n o p q r s t u v w x y z  &lt;strong&gt;Bold &lt;em&gt; Italic+Bold&lt;/strong&gt; Italic &lt;/em&gt; Normal&lt;/p&gt;
 
 &lt;div&gt;
        &lt;div&gt;I'm in a div&lt;/div&gt;