JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
fix click offset bug
authorJason Woofenden <jason@jasonwoof.com>
Fri, 18 Mar 2016 15:05:02 +0000 (11:05 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Fri, 18 Mar 2016 15:05:02 +0000 (11:05 -0400)
editor.coffee
editor_tests_compiled.html

index 9b4ad4f..8290b37 100644 (file)
@@ -51,7 +51,7 @@ debug_dot_at = (doc, x, y) ->
 
 # text nodes don't have getBoundingClientRect(), so use selection api to find
 # it.
-get_el_bounds = (el) ->
+get_el_bounds = window.bounds = (el) ->
        if el.getBoundingClientRect?
                rect = el.getBoundingClientRect()
        else
@@ -623,7 +623,7 @@ class PeachHTML5Editor
                @cursor_el = null
                @cursor_visible = false
                @poll_for_blur_timeout = null
-               @iframe_offset = null
+               @wrap2_offset = null
                @iframe_height = null
                opt_fragment = @options.fragment ? true
                @parser_opts = {}
@@ -703,12 +703,11 @@ class PeachHTML5Editor
                if @options.on_init?
                        @options.on_init()
        overlay_event_to_inner_xy: (e) ->
-               unless @iframe_offset?
-                       @iframe_offset = get_el_bounds @iframe
-               x = e.pageX # TODO ?cross-browserify
-               y = e.pageY + @wrap2.scrollTop # TODO ?cross-browserify
-               # TODO adjust for scrolling
-               return x: x - @iframe_offset.x, y: y - @iframe_offset.y
+               unless @wrap2_offset?
+                       @wrap2_offset = get_el_bounds @wrap2
+               x = e.pageX - overlay_padding
+               y = e.pageY - overlay_padding + @wrap2.scrollTop
+               return x: x - @wrap2_offset.x, y: y - @wrap2_offset.y
        onclick: (e) ->
                xy = @overlay_event_to_inner_xy e
                new_cursor = find_loc_cursor_position @tree, xy
index 4c55b41..23517cb 100644 (file)
@@ -42,7 +42,7 @@
 &lt;/div&gt;
 &lt;/div&gt;
 &lt;/div&gt;
-&lt;p>  Above, there's a div containing 4 divs. The third contains just an NBSP and the fourth is completely empty&lt;/p>
+&lt;p>  Above, there's a white div containing 4 divs. The third contains just an NBSP and the fourth is completely empty&lt;/p>
 &lt;p>final paragraph.&lt;/p>
 &lt;/div>
        </textarea></p>