From 7eb32af0eb10fd084b9179b1a266bd5236caebc9 Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Wed, 24 Feb 2016 10:19:11 -0500 Subject: [PATCH] fix cursor on inlines that start mid-row --- editor.coffee | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/editor.coffee b/editor.coffee index f4d0efd..e3b922e 100644 --- a/editor.coffee +++ b/editor.coffee @@ -49,8 +49,7 @@ get_el_bounds = (el) -> # # implementation: insert a span tag where we want the cursor, and ask the # browser where it put that span -cursor_to_xyh = (n, i) -> - span = domify span: style: "height: 1em; border-left: 1px solid black; margin-left: -1px" +window.cursor_to_xyh = cursor_to_xyh = (n, i) -> parent = n.el.parentNode els = [] txts = [] @@ -93,7 +92,7 @@ cursor_to_xyh = (n, i) -> # fudge case where bounds are BS because we're on non-significant whitespace if i > 0 first = cursor_to_xyh n, 0 - if ret.x <= first.x + if ret.x <= first.x and ret.y is first.y # no need for a loop here, because recursion ret = cursor_to_xyh n, i - 1 return ret @@ -270,6 +269,9 @@ find_loc_cursor_position = (tree, loc) -> continue if loc.x > bounds.x + bounds.w continue if loc.y < bounds.y continue if loc.y > bounds.y + bounds.h + if c.children.length + ret = find_loc_cursor_position c.children, loc + return ret if ret? if c.type is TYPE_TEXT # click is within bounding box that contains all text. return [c, 0] if c.text.length is 0 @@ -281,6 +283,12 @@ find_loc_cursor_position = (tree, loc) -> continue # before first char on first line if loc.y > after.y and loc.x > after.x continue # after last char on last line + if loc.y < before.y + console.log "Warning: click in bounding box but above first line" + continue # above first line (runaround?) + if loc.y > after.y + after.h + console.log "Warning: click in bounding box but below last line", loc.y, after.y, after.h + continue # below last line (shouldn't happen?) while after_i - before_i > 1 cur_i = Math.round((before_i + after_i) / 2) cur = cursor_to_xyh c, cur_i @@ -295,9 +303,6 @@ find_loc_cursor_position = (tree, loc) -> return [c, before_i] else return [c, after_i] - if c.children.length - ret = find_loc_cursor_position c.children, loc - return ret if ret? return null class PeachHTML5Editor -- 1.7.10.4