X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=editor.coffee;h=44b5fb6d5aa5d9f2203dc00f42eecdcf7998cfaa;hb=304ed69c871ccb27353b213816617fd8ea328ef7;hp=0d9d495ccaf68f729ca471a2ef670f754416ab9f;hpb=60bdb823e686628c9831bb16f7f1b27abd4a6610;p=peach-html5-editor.git diff --git a/editor.coffee b/editor.coffee index 0d9d495..44b5fb6 100644 --- a/editor.coffee +++ b/editor.coffee @@ -806,6 +806,44 @@ class PeachHTML5Editor @move_cursor new_cursor return false when KEY_DOWN + if @cursor? + new_cursor = @cursor + # go next until we move on the y axis + while new_cursor.y <= @cursor.y + new_cursor = find_next_cursor_position @tree, new_cursor + return false unless new_cursor? + # done early if we're already right of old cursor position + if new_cursor.x >= @cursor.x + # this would be strange, but could happen due to runaround + @move_cursor new_cursor + return false + target_y = new_cursor.y + # search rightward, until we find the closest position + # new_cursor is the next-most position we've checked + # prev_cursor is the older value, so it's not as next as new_cursor + while new_cursor.x < @cursor.x and new_cursor.y is target_y + prev_cursor = new_cursor + new_cursor = find_next_cursor_position @tree, new_cursor + break unless new_cursor? + # move cursor to prev_cursor or new_cursor + if new_cursor? + if new_cursor.y is target_y + # both valid, and on the same line, use closest + if (new_cursor.x - @cursor.x) < (@cursor.x - prev_cursor.x) + @move_cursor new_cursor + else + @move_cursor prev_cursor + else + # new_cursor on wrong line, use prev_cursor + @move_cursor prev_cursor + else + # can't go any further prev, use prev_cursor + @move_cursor prev_cursor + else + # move cursor to first position in document + new_cursor = last_cursor_position @tree + if new_cursor? + @move_cursor new_cursor return false when KEY_END return false @@ -889,7 +927,7 @@ class PeachHTML5Editor @cursor_el.parentNode.removeChild @cursor_el @cursor_visible = false @cursor = null - @matt null + @annotate null move_cursor: (cursor) -> @cursor = cursor unless @cursor_visible @@ -903,8 +941,8 @@ class PeachHTML5Editor height = cursor.h @cursor_el.style.top = "#{cursor.y + overlay_padding + Math.round(height * .07)}px" @cursor_el.style.height = "#{Math.round height * 0.82}px" - @matt cursor.n - matt: (n) -> + @annotate cursor.n + annotate: (n) -> while @matting.length > 0 @overlay.removeChild @matting[0] @matting.shift() @@ -920,12 +958,12 @@ class PeachHTML5Editor if bounds.x is prev_bounds.x and bounds.y is prev_bounds.y and bounds.w is prev_bounds.w and bounds.h is prev_bounds.h n = n.parent continue - matt = domify @outer_idoc, div: class: 'ann_box', style: "left: #{bounds.x - 1 + overlay_padding}px; top: #{bounds.y - 2 + overlay_padding}px; width: #{bounds.w}px; height: #{bounds.h}px" # outline: 1000px solid rgba(0,153,255,#{alpha}); - @overlay.appendChild matt - @matting.push matt - ann = domify @outer_idoc, div: class: 'ann_tag', style: "left: #{bounds.x + 1 + overlay_padding}px; top: #{bounds.y - 7 + overlay_padding}px", children: [domify @outer_idoc, text: " #{n.name} "] - @overlay.appendChild ann - @matting.push ann + ann_box = domify @outer_idoc, div: class: 'ann_box', style: "left: #{bounds.x - 1 + overlay_padding}px; top: #{bounds.y - 2 + overlay_padding}px; width: #{bounds.w}px; height: #{bounds.h}px" # outline: 1000px solid rgba(0,153,255,#{alpha}); + @overlay.appendChild ann_box + @matting.push ann_box + ann_tag = domify @outer_idoc, div: class: 'ann_tag', style: "left: #{bounds.x + 1 + overlay_padding}px; top: #{bounds.y - 7 + overlay_padding}px", children: [domify @outer_idoc, text: " #{n.name} "] + @overlay.appendChild ann_tag + @matting.push ann_tag n = n.parent alpha *= 1.5 pretty_html: (tree, indent = '', parent_flags = pre_ish: false, block: true, want_nl: false) ->