Skip to content

Commit

Permalink
Iteration. Not working, but code structure is there
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronik committed Dec 18, 2024
1 parent 7d98675 commit 25492c2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lua/treewalker/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local util = require('treewalker.util')
local util = require('treewalker.util')
local movement = require('treewalker.movement')
local swapping = require('treewalker.swapping')

Expand Down
6 changes: 6 additions & 0 deletions lua/treewalker/nodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,10 @@ function M.get_at_row(row)
return vim.treesitter.get_node({ pos = { row - 1, col } })
end

-----Getting the size of the node is no trivial thing. Different nodes behave differently.
-----@param row integer
-----@return TSNode|nil
--function M.get_real_range(row)
--end

return M
13 changes: 11 additions & 2 deletions lua/treewalker/swapping.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@ end

---@return nil
function M.swap_down()
local current = nodes.get_current()
local target, row, line = targets.down()

if target and row and line then
if not target or not row or not line then
--util.log("no down candidate")
ops.jump(row, target)
return
end

local current_range = nodes.range(current)
local target_range = nodes.range(target)

ops.swap(
{ current_range[1], current_range[3] },
{ target_range[1], target_range[3] }
)
end

return M
25 changes: 14 additions & 11 deletions plugin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@ local subcommands = {
tw().move_in()
end,

---@param subcommand "right" | "left" | "up" | "down"
Swap = function(subcommand)
if subcommand == "right" then
tw().swap_right()
elseif subcommand == "left" then
tw().swap_left()
elseif subcommand == "up" then
tw().swap_up()
elseif subcommand == "down" then
tw().swap_down()
end
SwapUp = function()
tw().swap_up()
end,

SwapDown = function()
tw().swap_down()
end,

SwapRight = function()
tw().swap_in()
end,

SwapLeft = function()
tw().swap_out()
end
}

Expand Down

0 comments on commit 25492c2

Please sign in to comment.