Skip to content

Commit

Permalink
Continue refactor of swap.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronik committed Jan 16, 2025
1 parent dc2eb65 commit f1c0f6b
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lua/treewalker/swap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ local function is_supported_ft()
return not unsupported_filetypes[ft]
end

-- pipes follow a specific pattern of taking a node and always returning a
-- node: either the hopeful that it found, or the passed in original
---@param node TSNode
---@return TSNode
local function get_highest_coincident_pipe(node)
local candidate = nodes.get_highest_coincident(node)
return candidate or node
end

-- pipes follow a specific pattern of taking a node and always returning a
-- node: either the hopeful that it found, or the passed in original
---@param node TSNode
---@return TSNode
local function get_highest_string_node_pipe(node)
Expand All @@ -46,11 +50,8 @@ function M.swap_down()
if not is_on_target_node() then return end
if not is_supported_ft() then return end

local target, row, line = targets.down()

if not target or not row or not line then
return
end
local target = targets.down()
if not target then return end

local current = nodes.get_current()
current = get_highest_coincident_pipe(current)
Expand Down Expand Up @@ -80,11 +81,8 @@ function M.swap_up()
if not is_on_target_node() then return end
if not is_supported_ft() then return end

local target, row, line = targets.up()

if not target or not row or not line then
return
end
local target = targets.up()
if not target then return end

local current = nodes.get_current()
current = get_highest_coincident_pipe(current)
Expand Down

0 comments on commit f1c0f6b

Please sign in to comment.