diff --git a/sloth/editor.scm b/sloth/editor.scm index af19faa..7cccc5a 100644 --- a/sloth/editor.scm +++ b/sloth/editor.scm @@ -120,9 +120,14 @@ state) (define (next-node state) - (define target (ts-node-next-sibling - (sloth-state-point-node state) - #t)) + (define target (or (ts-node-next-sibling + (sloth-state-point-node state) + #t) + (false-if-exception + (ts-node-next-sibling + (ts-node-parent + (sloth-state-point-node state)) + #t)))) (if target (let ((point (ts-node-start-point target))) (move (sloth-state-win state) @@ -131,9 +136,11 @@ state)) (define (prev-node state) - (define target (ts-node-prev-sibling - (sloth-state-point-node state) - #t)) + (define target (or (ts-node-prev-sibling + (sloth-state-point-node state) + #t) + (ts-node-parent + (sloth-state-point-node state)))) (if target (let ((point (ts-node-start-point target))) (move (sloth-state-win state) @@ -142,13 +149,15 @@ state)) (define (down-node state) - (define nodes (ts-node-childs (sloth-state-point-node state) - #t)) - (if (not (null? nodes)) - (let ((point (ts-node-start-point (car nodes)))) + (define target (false-if-exception + (car (ts-node-childs + (sloth-state-point-node state) + #t)))) + (if target + (let ((point (ts-node-start-point target))) (move (sloth-state-win state) (car point) (cdr point)) - (set-sloth-state-point-node state (car nodes))) + (set-sloth-state-point-node state target)) state)) (define (up-node state)