def walk_next_selection(obj): if isinstance(obj, mutable.Selection): if mutable.iscont(obj.container) and obj.head < obj.last: return enter_head(obj.container[obj.head]) else: obj = obj.container if isinstance(obj, mutable.Document): return mutable.Selection(obj, len(obj)) index = obj.parent.index(obj) if mutable.isstruct(obj.parent): if index + 1 < len(obj.parent): nxt = obj.parent[index+1] return enter_head(nxt) else: return walk_next_selection(obj.parent) else: return mutable.Selection(obj.parent, index+1)
def walk_prev_selection(obj): if isinstance(obj, mutable.Selection): if mutable.iscont(obj.container) and obj.head > 0: return enter_tail(obj.container[obj.head-1]) else: obj = obj.container if isinstance(obj, mutable.Document): return mutable.Selection(obj, 0) index = obj.parent.index(obj) if mutable.isstruct(obj.parent): if index > 0: nxt = obj.parent[index-1] return enter_tail(nxt) else: return walk_prev_selection(obj.parent) else: return mutable.Selection(obj.parent, index)