Skip to content

Commit c7ef54b

Browse files
committed
Fix vertical swapping regression with lua-spec files (and probs more)
Whoops, another case that wasn't tested. Easy fix though. I broke it when I removed the coincident logic from nodes.get_current()
1 parent 066f62d commit c7ef54b

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

lua/treewalker/swap.lua

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function M.swap_down()
3939
end
4040

4141
local current = nodes.get_current()
42+
current = nodes.get_highest_coincident(current)
4243
local current_augments = augment.get_node_augments(current)
4344
local current_all = { current, unpack(current_augments) }
4445
local current_all_rows = nodes.whole_range(current_all)
@@ -72,6 +73,7 @@ function M.swap_up()
7273
end
7374

7475
local current = nodes.get_current()
76+
current = nodes.get_highest_coincident(current)
7577
local current_augments = augment.get_node_augments(current)
7678
local current_all = { current, unpack(current_augments) }
7779
local current_all_rows = nodes.whole_range(current_all)

tests/fixtures/lua-spec.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe("Treewalker", function()
6464
describe("lua spec file", function()
6565
load_buf(fixtures_dir .. "/lua.lua", "lua")
6666

67-
it("moves up and down at the same pace", function()
67+
it("one", function()
6868
vim.fn.cursor(1, 1) -- Reset cursor
6969
treewalker.down()
7070
assert_cursor_at(3, 1)
@@ -84,7 +84,7 @@ describe("Treewalker", function()
8484
assert_cursor_at(1, 1)
8585
end)
8686

87-
it("goes into functions eagerly", function()
87+
it("two", function()
8888
vim.fn.cursor(143, 1) -- In a bigger function
8989
treewalker.right()
9090
assert_cursor_at(144, 3)

tests/treewalker/swap_spec.lua

+23-2
Original file line numberDiff line numberDiff line change
@@ -253,21 +253,42 @@ describe("Swapping in a lua test file:", function()
253253
assert.same(' { "<CMD>Treewalker SwapUp<CR>", "k", { desc = "up" } },', lines.get_line(102))
254254
end)
255255

256-
it("follows lateral swaps across rows (like in these it args)", function()
256+
it("follows right swaps across rows (like in these it args)", function()
257257
vim.fn.cursor(21, 13)
258258
tw.swap_right()
259259
assert.same(' it(function()', lines.get_line(21))
260260
assert.same(' end, "moves up and down at the same pace")', lines.get_line(39))
261261
helpers.assert_cursor_at(39, 10)
262262
end)
263263

264-
it("follows lateral swaps across rows (like in these it args)", function()
264+
it("follows left swaps across rows (like in these it args)", function()
265265
vim.fn.cursor(50, 13) -- go|es
266266
tw.swap_left()
267267
assert.same(' it("goes into functions eagerly", function()', lines.get_line(41))
268268
assert.same(' end)', lines.get_line(50))
269269
helpers.assert_cursor_at(41, 8)
270270
end)
271+
272+
it("swaps it blocks down", function()
273+
assert.same(' it("one", function()', lines.get_line(67))
274+
assert.same(' it("two", function()', lines.get_line(87))
275+
vim.fn.cursor(67, 5) -- |it "one"
276+
tw.swap_down()
277+
assert.same(' it("two", function()', lines.get_line(67))
278+
assert.same(' it("one", function()', lines.get_line(77))
279+
helpers.assert_cursor_at(77, 5)
280+
end)
281+
282+
it("swaps it blocks up", function()
283+
assert.same(' it("one", function()', lines.get_line(67))
284+
assert.same(' it("two", function()', lines.get_line(87))
285+
vim.fn.cursor(87, 5) --|it "two"
286+
tw.swap_up()
287+
assert.same(' it("two", function()', lines.get_line(67))
288+
assert.same(' it("one", function()', lines.get_line(77))
289+
helpers.assert_cursor_at(67, 5)
290+
end)
291+
271292
end)
272293

273294
-- doesn't work at all in md, doesn't need to

0 commit comments

Comments
 (0)