JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
use new text_cleanup in place of old func
authorJason Woofenden <jason@jasonwoof.com>
Tue, 12 Apr 2016 06:34:48 +0000 (02:34 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Tue, 12 Apr 2016 06:34:48 +0000 (02:34 -0400)
editor.coffee

index 4b26b31..ec9f9f9 100644 (file)
@@ -951,7 +951,7 @@ class PeachHTML5Editor
                                return false unless @cursor?
                                return false unless @cursor.i < @cursor.n.text.length
                                @remove_character @cursor.n, @cursor.i
-                               @adjust_whitespace_style @cursor.n
+                               @text_cleanup @cursor.n
                                @changed()
                                new_cursor = new_cursor_position n: @cursor.n, i: @cursor.i
                                if new_cursor?
@@ -987,7 +987,7 @@ class PeachHTML5Editor
                if char and @cursor?
                        char = String.fromCharCode char
                        @insert_character @cursor.n, @cursor.i, char
-                       @adjust_whitespace_style @cursor.n
+                       @text_cleanup @cursor.n
                        @changed()
                        new_cursor = new_cursor_position n: @cursor.n, i: @cursor.i + 1
                        if new_cursor
@@ -1190,7 +1190,7 @@ class PeachHTML5Editor
                                        return
                        else
                                @remove_character @cursor.n, @cursor.i - 1
-                       @adjust_whitespace_style @cursor.n
+                       @text_cleanup @cursor.n
                        @changed()
                        new_cursor = new_cursor_position n: @cursor.n, i: @cursor.i - 1
                        if new_cursor?
@@ -1333,51 +1333,6 @@ class PeachHTML5Editor
                                        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.
-       #
-       # FIXME stop using this and delete it. use @text_cleanup instead
-       adjust_whitespace_style: (n) ->
-               loop
-                       break if @is_display_block n
-                       n = n.parent
-                       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'
-               if ws_props[ws].space
-                       preserve_rule = ws
-               else
-                       preserve_rule = ws_props[ws].to_preserve
-               preserve_rule = "white-space: #{preserve_rule}"
-               if @has_collapsable_space n
-                       # make sure preserve_rule exists
-                       if n.el.style['white-space']
-                               # FIXME check that it matches
-                               return
-                       if n.attrs[style]?
-                               n.attrs.style += "; #{preserve_rule}"
-                       else
-                               n.attrs.style = preserve_rule
-                       n.el.setAttribute 'style', n.attrs.style
-               else
-                       # remove preserve_rule if it exists
-                       return unless n.attrs.style?
-                       # FIXME don't assume whitespace is just so
-                       if n.attrs.style is "white-space: #{ws}"
-                               delete n.attrs.style
-                               n.el.removeAttribute 'style'
-                       else
-                               # FIXME find it in the middle and at the start
-                               needle = "; white-space: #{ws}"
-                               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'
@@ -1403,7 +1358,7 @@ class PeachHTML5Editor
                                # n is only child
                                return true
                return false
-       # after calling this, you MUST call changed() and adjust_whitespace_style()
+       # after calling this, you MUST call changed() and text_cleanup()
        insert_character: (n, i, char) ->
                return if n.parent is @tree_parent # FIXME implement text nodes at top level
                # insert the character
@@ -1420,7 +1375,7 @@ class PeachHTML5Editor
                                char +
                                n.text.substr(i)
                n.el.nodeValue = n.text
-       # WARNING: after calling this, you MUST call changed() and adjust_whitespace_style()
+       # WARNING: after calling this, you MUST call changed() and text_cleanup()
        remove_character: (n, i) ->
                n.text = n.text.substr(0, i) + n.text.substr(i + 1)
                n.el.nodeValue = n.text