X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=editor.coffee;h=df8ad8accb7ec9036e1303a03f6ca3bcab6c8ed2;hb=ae38e0db8cb6eba45ffb6c1a3e76c1b20efba696;hp=f4d0efd6593147088fdd63b2611cae1a5947a03d;hpb=e09f7373d066a5965a24adb72a2f2c02e8ac01b9;p=peach-html5-editor.git diff --git a/editor.coffee b/editor.coffee index f4d0efd..df8ad8a 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 @@ -175,17 +174,15 @@ css += 'height: 1em;' css += 'width: 2px;' css += 'margin-left: -1px;' css += 'margin-right: -1px;' -css += 'background: #000;' -css += '-webkit-animation: 1s blink step-end infinite;' -css += 'animation: 1s blink step-end infinite;' +css += 'background: #444;' +css += '-webkit-animation: blink 1s steps(2, start) infinite;' +css += 'animation: blink 1s steps(2, start) infinite;' css += '}' -css += '@-webkit-keyframes "blink" {' -css += 'from, to { background: #000; }' -css += '50% { background: transparent; }' +css += '@-webkit-keyframes blink {' +css += 'to { visibility: hidden; }' css += '}' -css += '@keyframes "blink" {' -css += 'from, to { background: #000; }' -css += '50% { background: transparent; }' +css += '@keyframes blink {' +css += 'to { visibility: hidden; }' css += '}' # key codes: @@ -270,6 +267,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 +281,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 +301,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