From: Jason Woofenden Date: Sat, 2 Apr 2016 18:07:44 +0000 (-0400) Subject: incomplete: deleting barrier between blocks X-Git-Url: https://jasonwoof.com/gitweb/?p=peach-html5-editor.git;a=commitdiff_plain;h=9b0a8adcd553683463cc338e6ad4d95523e7939f incomplete: deleting barrier between blocks --- diff --git a/editor.coffee b/editor.coffee index dd39c62..2ad0acc 100644 --- a/editor.coffee +++ b/editor.coffee @@ -1042,6 +1042,7 @@ class PeachHTML5Editor else @kill_cursor() else + # cursor at the begining of an element that contains only a space parent = @cursor.n.parent new_cursor = find_prev_cursor_position @tree, @cursor if new_cursor? @@ -1069,11 +1070,41 @@ class PeachHTML5Editor else @kill_cursor return - else if @cursor.i is 0 - console.log 'unimplemented: backspace at start of non-empty tag' - # TODO if block, merge parent into prev - # TODO if inline, delete char from prev text node - return false + else if @cursor.i is 0 # start of non-empty tag + # TODO factor out function for moving children around + # find containing block + containing_block = @cursor.n + loop + containing_block = containing_block.parent + return unless containing_block? + return if containing_block is @tree_parent + break if is_display_block containing_block + # FIXME only continue if first child, else inline merge here + # find contaning_block's previous sibling + prev = null + for n, contaning_block_i in contaning_block.parent.children + break if n is containing_block + prev = n + containing_block.el.parent.removeChild containing_block.el + containing_block.parent.children.splice contaning_block_i, 1 + if prev is null + console.log "inimplemented: backspace at start of nested blocks" # FIXME + return + if is_display_block prev + # insert contents of containing_block into prev + ws_cleanup = false + if prev.children.length > 0 + prev_last = prev.children[prev.children.length - 1] + if prev_last.type is 'text' and containing_block.children[0].type is 'text' + prev_last.text = prev_last.el.textContent = prev_last.text + containing_block.children[0].text + ws_cleanup = true + containing_block.children.shift() + for n in containing_block.children + # TODO insert into prev + # TODO adjust whitespace property of prev_last if ws_cleanup + else + # TODO insert contents of containing_block into prev.parent after prev + return else # TODO handle case of removing last char # CONTINUE