JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
remove debugging code, fix indentation
authorJason Woofenden <jason@jasonwoof.com>
Wed, 25 May 2016 03:02:48 +0000 (23:02 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Wed, 25 May 2016 03:02:48 +0000 (23:02 -0400)
editor.coffee

index c6b13d6..a3f493b 100644 (file)
@@ -1104,11 +1104,6 @@ class PeachHTML5Editor
                if @cursor.i is 0 # cursor is at start of text node
                        run ?= @get_text_run @cursor.n
                        run_i = run.indexOf(@cursor.n)
                if @cursor.i is 0 # cursor is at start of text node
                        run ?= @get_text_run @cursor.n
                        run_i = run.indexOf(@cursor.n)
-                       if run_i is -1
-                               console.log 'run', run
-                               console.log 'cursor', @cursor
-                               throw 'fffffff'
-                               return
                        if run_i is 0 # if at start of text run
                                block = @find_block_parent @cursor.n
                                prev_cursor = find_prev_cursor_position @tree, n: @cursor.n, i: 0
                        if run_i is 0 # if at start of text run
                                block = @find_block_parent @cursor.n
                                prev_cursor = find_prev_cursor_position @tree, n: @cursor.n, i: 0
@@ -1164,42 +1159,42 @@ class PeachHTML5Editor
                        if @cursor.n.text.length is 1 # if emptying text node
                                if run.length is 1 # if emptying text run (of text/br/hr/inline-block)
                                        # remove inline-parents of @cursor.n
                        if @cursor.n.text.length is 1 # if emptying text node
                                if run.length is 1 # if emptying text run (of text/br/hr/inline-block)
                                        # remove inline-parents of @cursor.n
-                                               block = @find_block_parent @cursor.n
-                                               changed = false
-                                               n = @cursor.n.parent
-                                               while n and n isnt block
-                                                       changed = true
-                                                       while n.children.length > 0
-                                                               @move_node n.children[0], n.parent, n
-                                                       @remove_node n
-                                                       n = n.parent
-                                               # replace @cursor.n with a single (preserved) space
-                                               if @cursor.n.text != ' '
-                                                       changed = true
-                                                       @cursor.n.text = @cursor.n.el.textContent = ' '
-                                               if changed
-                                                       @text_cleanup @cursor.n
-                                               # place the cursor to the left of that space
-                                               new_cursor = new_cursor_position n: @cursor.n, i: 0
-                                       else # emptying a text node (but not a whole text run)
-                                               # figure out where cursor should land
-                                               block = @find_block_parent @cursor.n
-                                               new_cursor = find_prev_cursor_position @tree, n: @cursor.n, i: 0
-                                               ncb = @find_block_parent new_cursor
-                                               if ncb isnt block
-                                                       new_cursor = find_next_cursor_position @tree, n: @cursor.n, i: 1
-                                               # delete text node
-                                               @remove_node @cursor.n
-                                               # delete any inline parents
-                                               n = @cursor.n.parent
-                                               while n and n isnt block
-                                                       while n.children.length > 0
-                                                               @move_node n.children[0], n.parent, n
-                                                       @remove_node n
-                                                       n = n.parent
-                                               # update cursor dest in case things moved around
-                                               if new_cursor?
-                                                       new_cursor = new_cursor_position n: new_cursor.n, i: new_cursor.i
+                                       block = @find_block_parent @cursor.n
+                                       changed = false
+                                       n = @cursor.n.parent
+                                       while n and n isnt block
+                                               changed = true
+                                               while n.children.length > 0
+                                                       @move_node n.children[0], n.parent, n
+                                               @remove_node n
+                                               n = n.parent
+                                       # replace @cursor.n with a single (preserved) space
+                                       if @cursor.n.text != ' '
+                                               changed = true
+                                               @cursor.n.text = @cursor.n.el.textContent = ' '
+                                       if changed
+                                               @text_cleanup @cursor.n
+                                       # place the cursor to the left of that space
+                                       new_cursor = new_cursor_position n: @cursor.n, i: 0
+                               else # emptying a text node (but not a whole text run)
+                                       # figure out where cursor should land
+                                       block = @find_block_parent @cursor.n
+                                       new_cursor = find_prev_cursor_position @tree, n: @cursor.n, i: 0
+                                       ncb = @find_block_parent new_cursor
+                                       if ncb isnt block
+                                               new_cursor = find_next_cursor_position @tree, n: @cursor.n, i: 1
+                                       # delete text node
+                                       @remove_node @cursor.n
+                                       # delete any inline parents
+                                       n = @cursor.n.parent
+                                       while n and n isnt block
+                                               while n.children.length > 0
+                                                       @move_node n.children[0], n.parent, n
+                                               @remove_node n
+                                               n = n.parent
+                                       # update cursor dest in case things moved around
+                                       if new_cursor?
+                                               new_cursor = new_cursor_position n: new_cursor.n, i: new_cursor.i
                        else # there's a char left of cursor that we can delete without emptying anything
                                # delete character
                                need_text_cleanup = true
                        else # there's a char left of cursor that we can delete without emptying anything
                                # delete character
                                need_text_cleanup = true