throw 'bork bork' unless new_cursor?
@move_cursor new_cursor
# TODO move content past cursor into this new block
+ # unlike the global function, this takes a Node, not an element
+ is_display_block: (n) ->
+ # TODO stop calling global function, merge it into here, use iframe's window object
+ return false unless n.type is 'tag'
+ return is_display_block n.el
find_block_parent: (n) ->
loop
n = n.parent
prev_pos_block = @find_block_parent prev_pos.n
if prev_pos_block is block
# context: there is text before the cursor within the same block.
- # FIXME clean up this hack for looking for <br>
+ # FIXME clean up this hack for looking for <br> (see above)
cursor_text_pi = @cursor.n.parent.children.indexOf @cursor.n
if cursor_text_pi > 0
prev_node = @cursor.n.parent.children[cursor_text_pi - 1]
# FIXME prev_sib should be the previous in-flow element
# ie it should skip comments, hidden things, floating things, etc.
prev_sib = parent.children[parent_i - 1]
- if is_display_block prev_sib.el
+ if @is_display_block prev_sib
dest = prev_sib
before = null # null means append
else
# TODO handle case of removing last char
# CONTINUE
if @is_only_char_in_tag @cursor.n
- if is_display_block @cursor.n.parent.el
+ if @is_display_block @cursor.n.parent
@cursor.n.el.textContent = @cursor.n.text = ' '
else
console.log "unimplemented: delete last char in inline" # FIXME
# does this node have whitespace that would be collapsed by white-space: normal?
# note: this checks direct text children, and does _not_ recurse into child tags
# tag is a node with type:"tag"
+ # FIXME use new textrun api
has_collapsable_space: (tag) ->
for n in tag.children
if n.type is 'text'
return true
if is_space_code n.text.charCodeAt n.text.length - 1
return true
+ return false
# add/remove "white-space: pre[-wrap]" to/from style="" on tags with direct
# child text nodes with multiple spaces in a row, or spaces at the
# start/end.
# text inside child tags are not consulted. Child tags are expected to have
# this function applied to them when their content changes.
adjust_whitespace_style: (n) ->
- if n.type is 'text'
+ loop
+ break if @is_display_block n
n = n.parent
- return unless n?.el?
+ return unless n?
+ return if n is @tree_parent
# which css rule should be used to preserve spaces (should we need to)
style = @iframe.contentWindow.getComputedStyle n.el, null
ws = style.getPropertyValue 'white-space'
before_i = new_parent.children.indexOf insert_before
if i is -1
throw "Error: tried to move a node to be before a non-existent node"
+ insert_before = insert_before.el
@remove_node n
if insert_before?
- new_parent.insertBefore n.el, insert_before
+ new_parent.el.insertBefore n.el, insert_before
new_parent.children.splice before_i, 0, n
else
new_parent.el.appendChild n.el, insert_before