#
# 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 = []
# 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
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
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
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