From: Jason Woofenden Date: Fri, 18 Mar 2016 15:05:02 +0000 (-0400) Subject: fix click offset bug X-Git-Url: https://jasonwoof.com/gitweb/?p=peach-html5-editor.git;a=commitdiff_plain;h=ed31e427bb738c1673b1fbf9465aa4f5324f9a3c fix click offset bug --- diff --git a/editor.coffee b/editor.coffee index 9b4ad4f..8290b37 100644 --- a/editor.coffee +++ b/editor.coffee @@ -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 diff --git a/editor_tests_compiled.html b/editor_tests_compiled.html index 4c55b41..23517cb 100644 --- a/editor_tests_compiled.html +++ b/editor_tests_compiled.html @@ -42,7 +42,7 @@ </div> </div> </div> -<p> Above, there's a div containing 4 divs. The third contains just an NBSP and the fourth is completely empty</p> +<p> Above, there's a white div containing 4 divs. The third contains just an NBSP and the fourth is completely empty</p> <p>final paragraph.</p> </div>