File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 1
- local movement = require (' treewalker.movement' )
1
+ \ local movement = require (' treewalker.movement' )
2
2
local swap = require (' treewalker.swap' )
3
3
local options = require (' treewalker.options' )
4
4
Original file line number Diff line number Diff line change @@ -176,6 +176,22 @@ function M.next_sib(node)
176
176
return node :next_named_sibling ()
177
177
end
178
178
179
+ --- @param node TSNode
180
+ --- @param fn function
181
+ --- @return TSNode | nil
182
+ function M .farthest_sibling (node , fn )
183
+ if not node then return nil end
184
+
185
+ --- @type TSNode | nil
186
+ local iter = fn (node )
187
+
188
+ while iter do
189
+ node = iter
190
+ iter = fn (iter )
191
+ end
192
+ return node
193
+ end
194
+
179
195
-- Convenience for give me back prev sibling of a potentially nil node
180
196
--- @param node TSNode | nil
181
197
function M .prev_sib (node )
Original file line number Diff line number Diff line change @@ -121,7 +121,7 @@ function M.swap_right()
121
121
current = strategies .get_highest_string_node (current ) or current
122
122
current = nodes .get_highest_coincident (current )
123
123
124
- local target = nodes .next_sib (current )
124
+ local target = nodes .next_sib (current ) or nodes . farthest_sibling ( current , nodes . prev_sib )
125
125
126
126
if not current or not target then return end
127
127
@@ -158,7 +158,7 @@ function M.swap_left()
158
158
current = strategies .get_highest_string_node (current ) or current
159
159
current = nodes .get_highest_coincident (current )
160
160
161
- local target = nodes .prev_sib (current )
161
+ local target = nodes .prev_sib (current ) or nodes . farthest_sibling ( current , nodes . next_sib )
162
162
163
163
if not current or not target then return end
164
164
You can’t perform that action at this time.
0 commit comments