@@ -24,6 +24,24 @@ local function add_jumplist_for_move(command)
2424 end
2525end
2626
27+ --- @param current_node TSNode
28+ --- @param candidate TSNode
29+ --- @return boolean
30+ local function should_confine_vertical_move (current_node , candidate )
31+ local opts = require (' treewalker' ).opts
32+ if opts .scope_confined ~= true then
33+ return false
34+ end
35+
36+ local current_parent = nodes .scope_parent (current_node )
37+ if not current_parent then
38+ return false
39+ end
40+
41+ local candidate_anchor = nodes .get_highest_row_coincident (candidate )
42+ return not nodes .is_descendant_of (current_parent , candidate_anchor )
43+ end
44+
2745--- @return nil
2846function M .move_out ()
2947 -- Add to jumplist at original cursor position before normalizing
@@ -55,6 +73,10 @@ function M.move_up()
5573 local target , row = targets .up (current_node , current_row )
5674 if not target or not row then return end
5775
76+ if should_confine_vertical_move (current_node , target ) then
77+ return
78+ end
79+
5880 local is_neighbor = nodes .have_neighbor_srow (current_node , target )
5981
6082 if not is_neighbor then
@@ -70,6 +92,10 @@ function M.move_down()
7092 local target , row = targets .down (current_node , current_row )
7193 if not target or not row then return end
7294
95+ if should_confine_vertical_move (current_node , target ) then
96+ return
97+ end
98+
7399 local is_neighbor = nodes .have_neighbor_srow (current_node , target )
74100
75101 if not is_neighbor then
0 commit comments