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
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
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) ->