TYPE_COMMENT = peach_parser.TYPE_COMMENT
TYPE_DOCTYPE = peach_parser.TYPE_DOCTYPE
+# text nodes don't have getBoundingClientRect(), so wrap it in a span, measure
+# and then put it back
+get_text_bounding_rect = (el) ->
+ span = el.ownerDocument.createElement 'span'
+ el.parentNode.replaceChild span, el
+ span.appendChild el
+ ret = span.getBoundingClientRect()
+ span.parentNode.replaceChild el, span
+ return ret
get_el_bounds = (el) ->
- rect = el.getBoundingClientRect()
+ if el.getBoundingClientRect
+ rect = el.getBoundingClientRect()
+ else
+ rect = get_text_bounding_rect el
doc = el.ownerDocument.documentElement
win = el.ownerDocument.defaultView
y_fix = win.pageYOffset - doc.clientTop
console.log tree, loc
for c in tree
if c.type is TYPE_TAG or c.type is TYPE_TEXT
- # FIXME get_el_bounds doesn't work on TYPE_TEXT
bounds = get_el_bounds c.el
console.log bounds
continue if loc.left < bounds.x
continue if loc.top < bounds.y
continue if loc.top > bounds.y + bounds.h
if c.type is TYPE_TEXT
- # FIXME find position, don't just pass 0
- return [c, 0]
+ # click is within bounding box that contains all text.
+ return [c, 0] if c.text.length is 0
+ #if c.text.length is 1
+ # definitely no linebreak in it
+ #if loc
+ #
+ # for inline elements, this can include text in other tags on
+ # the first or last lines.
+ #
+ # they clicked on text. now determine where in the text
+ tries = {}
+ cur = Math.floor(c.text.length / 2)
+ #loop
+ # xy = tries[cur] = cursor_to_loc c, cur
+ return [c, cur]
if c.children.length
console.log "in"
ret = find_loc_cursor_position c.children, loc