X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=editor.coffee;h=07bf2c760f7ae919a96c067abf9410a76ba608d9;hb=0644f17def6ee0e7b5cc3b6972bfdf279f6d5f15;hp=45e5f364ddd629b391711d540491769f4a5cbc25;hpb=01d1661cb1c3d11720ddbf1337b0b51d83152fdc;p=peach-html5-editor.git diff --git a/editor.coffee b/editor.coffee index 45e5f36..07bf2c7 100644 --- a/editor.coffee +++ b/editor.coffee @@ -326,8 +326,7 @@ traverse_tree = (tree, state, cb) -> traverse_tree c.children, state, cb break if state.done? return state -# find the next element in tree (and decendants) that is after n and can contain text -# TODO make it so cursor can go places that don't have text but could + find_next_cursor_position = (tree, n, i) -> if n? and n.type is TYPE_TEXT and n.text.length > i orig_xyh = cursor_to_xyh n, i @@ -341,15 +340,15 @@ find_next_cursor_position = (tree, n, i) -> return [n, next_i] found = traverse_tree tree, before: n?, (node, state) -> if node.type is TYPE_TEXT and state.before is false - state.node = node - state.done = true + if cursor_to_xyh(node, 0)? + state.node = node + state.done = true if node is n state.before = false if found.node? return [found.node, 0] return null -# TODO make it so cursor can go places that don't have text but could find_prev_cursor_position = (tree, n, i) -> if n? and n.type is TYPE_TEXT and i > 0 orig_xyh = cursor_to_xyh n, i @@ -374,7 +373,12 @@ find_prev_cursor_position = (tree, n, i) -> if node state.prev = node if found.node? - return [found.node, found.node.text.length] + ret = [found.node, found.node.text.length] + # check for unusual case: text not visible + loc = cursor_to_xyh ret[0], ret[1] + if loc? + return ret + return find_prev_cursor_position tree, ret[0], 0 return null find_loc_cursor_position = (tree, loc) ->