From ab13f4d01dc8c466542fe2df7ca6bcf8cc823148 Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Tue, 24 May 2016 23:02:48 -0400 Subject: [PATCH] remove debugging code, fix indentation --- editor.coffee | 77 +++++++++++++++++++++++++++------------------------------ 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/editor.coffee b/editor.coffee index c6b13d6..a3f493b 100644 --- a/editor.coffee +++ b/editor.coffee @@ -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 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 @@ -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 - 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 -- 1.7.10.4