JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
remove obsolete debugging code
[peach-html5-editor.git] / editor.coffee
index 238625c..2bb3d99 100644 (file)
@@ -76,13 +76,6 @@ multi_sp_regex = new RegExp '[\u0020\u0009\u000a\u000c\u000d][\u0020\u0009\u000a
 str_has_ws_run = (str) ->
        return multi_sp_regex.test str
 
-debug_dot_at = (doc, x, y) ->
-       return # disabled
-       el = doc.createElement 'div'
-       el.setAttribute 'style', "position: absolute; left: #{x}px; top: #{y}px; width: 1px; height: 3px; background-color: red"
-       doc.body.appendChild el
-       #console.log(new Error().stack)
-
 # text nodes don't have getBoundingClientRect(), so use selection api to find
 # it.
 get_el_bounds = window.bounds = (el) ->
@@ -524,8 +517,10 @@ tree_remove_empty_text_nodes = (tree) ->
                                n.parent.children.splice i, 1
                                break
 
-# pass a array of nodes (from parser library, ie it should have .el and .text)
-tree_dedup_space = (tree) ->
+# remove whitespace that would be trimmed
+# replace whitespace that would collapse with a single space
+# FIXME delete this, use @collapse_whitespace instead
+collapse_whitespace = (tree) ->
        prev = cur = next = null
        prev_i = cur_i = next_i = 0
        prev_pos = pos = next_pos = null
@@ -1348,7 +1343,7 @@ class PeachHTML5Editor
                @tree_parent.el = @idoc.body
                @clear_dom()
                instantiate_tree @tree, @tree_parent.el
-               tree_dedup_space @tree
+               @collapse_whitespace @tree
                @changed()
        changed: ->
                @in_el.onchange = null
@@ -1461,10 +1456,18 @@ class PeachHTML5Editor
                else
                        if n.attrs.style?
                                delete n.attrs.style
+       # remove whitespace that would be trimmed
+       # replace whitespace that would collapse with a single space
+       collapse_whitespace: (tree = @tree) ->
+               return collapse_whitespace tree # FIXME CONTINUE
+               return
        # call this after you insert or remove inline nodes. It will:
        #    merge consecutive text nodes
        #    remove empty text nodes
        #    adjust white-space property
+       # note: this assumes that all whitespace in text nodes should be displayed
+       # (ie not collapse or be trimmed) and will change the white-space property
+       # as needed to achieve this.
        text_cleanup: (n) ->
                if @is_display_block n
                        block = n