@kill_cursor
return
else if @cursor.i is 0
- console.log 'not implemented yet'
+ 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
# TODO handle case of removing last char
- @remove_character @cursor.n, @cursor.i - 1
+ # CONTINUE
+ if @is_only_char_in_tag @cursor.n
+ if is_display_block @cursor.n.parent.el
+ @cursor.n.el.textContent = @cursor.n.text = ' '
+ else
+ console.log "unimplemented: delete last char in inline" # FIXME
+ return
+ else
+ @remove_character @cursor.n, @cursor.i - 1
@adjust_whitespace_style @cursor.n
@changed()
new_cursor = new_cursor_position n: @cursor.n, i: @cursor.i - 1
@move_cursor new_cursor
else
@kill_cursor()
+ return
clear_dom: -> # remove all the editable content (and cursor, overlays, etc)
while @idoc.body.childNodes.length
@idoc.body.removeChild @idoc.body.childNodes[0]
if needle is n.attrs.style.substr n.attrs.style.length - needle
n.attrs.style = n.attrs.style.substr 0, n.attrs.style.length - needle
n.el.setAttribute n.attrs.style
+ # true if n is text node with only one caracter, and the only child of a tag
+ is_only_char_in_tag: (n, i) ->
+ return false unless n.type is 'text'
+ return false unless n.text.length is 1
+ return false if n.parent is @tree_parent
+ return false unless n.parent.children.length is 1
+ return true
# true if n is text node with just a space in it, and the only child of a tag
is_lone_space: (n, i) ->
return false unless n.type is 'text'
return false unless n.text is ' '
return false if n.parent is @tree_parent
- if n.parent.children.length is 1
- if n.parent.children[0] is n
- # n is only child
- return true
- return false
+ return false unless n.parent.children.length is 1
+ return true
# detect special case: typing before a space that's the only thing in a block/doc
# reason: enter key creates blocks with just a space in them
insert_should_replace: (n, i) ->