Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't ignore at_edge for floating windows #218

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 46 additions & 38 deletions lua/smart-splits/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,44 @@ local function split_edge(direction)
end
end

---@param direction SmartSplitsDirection direction to move
---@param will_wrap boolean whether to wrap around edge
---@param at_edge SmartSplitsAtEdgeBehavior behavior at edge
local function handle_at_edge(direction, will_wrap, at_edge)
if type(at_edge) == 'function' then
local ctx = { ---@type SmartSplitsContext
mux = mux.get(),
direction = direction,
split = function()
split_edge(direction)
end,
wrap = function()
next_win_or_wrap(will_wrap, DirectionKeysReverse[direction])
end,
}
at_edge(ctx)
return
elseif at_edge == AtEdgeBehavior.stop then
return
elseif at_edge == AtEdgeBehavior.split then
-- if at_edge = 'split' and we're in an ignored buffer, just stop
if
vim.tbl_contains(config.ignored_buftypes, vim.bo.buftype)
or vim.tbl_contains(config.ignored_filetypes, vim.bo.filetype)
then
return
end

split_edge(direction)
return
else -- at_edge == AtEdgeBehavior.wrap
-- shouldn't wrap if count is > 1
if vim.v.count1 == 1 then
dir_key = DirectionKeysReverse[direction]
end
end
end

---@param direction SmartSplitsDirection
---@param opts table
local function move_cursor(direction, opts)
Expand All @@ -356,12 +394,6 @@ local function move_cursor(direction, opts)
end
end

if handle_floating_window(function()
mux.move_pane(direction, true, at_edge)
end) then
return
end

local offset = vim.fn.winline() + vim.api.nvim_win_get_position(0)[1]
local dir_key = DirectionKeys[direction]

Expand All @@ -372,45 +404,21 @@ local function move_cursor(direction, opts)
-- if it is the same as the one one move closer - move is beyond
local will_wrap = win_to_move_to == win_before

if handle_floating_window(function()
mux.move_pane(direction, true, at_edge)
end) then
handle_at_edge(direction, will_wrap, at_edge)
return
end

if will_wrap then
-- if we can move with mux, then we're good
if mux.move_pane(direction, will_wrap, at_edge) then
return
end

-- otherwise check at_edge behavior
if type(at_edge) == 'function' then
local ctx = { ---@type SmartSplitsContext
mux = mux.get(),
direction = direction,
split = function()
split_edge(direction)
end,
wrap = function()
next_win_or_wrap(will_wrap, DirectionKeysReverse[direction])
end,
}
at_edge(ctx)
return
elseif at_edge == AtEdgeBehavior.stop then
return
elseif at_edge == AtEdgeBehavior.split then
-- if at_edge = 'split' and we're in an ignored buffer, just stop
if
vim.tbl_contains(config.ignored_buftypes, vim.bo.buftype)
or vim.tbl_contains(config.ignored_filetypes, vim.bo.filetype)
then
return
end

split_edge(direction)
return
else -- at_edge == AtEdgeBehavior.wrap
-- shouldn't wrap if count is > 1
if vim.v.count1 == 1 then
dir_key = DirectionKeysReverse[direction]
end
end
handle_at_edge(direction, will_wrap, at_edge)
end

next_win_or_wrap(will_wrap, dir_key)
Expand Down
Loading