X-Git-Url: https://jasonwoof.com/gitweb/?p=peach-html5-editor.git;a=blobdiff_plain;f=editor.coffee;h=9f6d8eb34473d0b762c37e059887afa244d57378;hp=29cf7e366d3d0747bc9884e0608f42a349c1ff4a;hb=e63123d22c65f954f27b830f149c1a1500ba0c97;hpb=0742a687c380cc5b39aeb6eb8707342c14ca69e7
diff --git a/editor.coffee b/editor.coffee
index 29cf7e3..9f6d8eb 100644
--- a/editor.coffee
+++ b/editor.coffee
@@ -1030,6 +1030,11 @@ class PeachHTML5Editor
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
@@ -1092,7 +1097,7 @@ class PeachHTML5Editor
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
+ # FIXME clean up this hack for looking for
(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]
@@ -1126,7 +1131,7 @@ class PeachHTML5Editor
# 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
@@ -1153,7 +1158,7 @@ class PeachHTML5Editor
# 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
@@ -1284,6 +1289,7 @@ class PeachHTML5Editor
# 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'
@@ -1301,6 +1307,7 @@ class PeachHTML5Editor
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.
@@ -1308,9 +1315,11 @@ class PeachHTML5Editor
# 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'
@@ -1419,9 +1428,10 @@ class PeachHTML5Editor
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