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

feat: smart open should prefer alternative window #83

Merged
merged 1 commit into from
Nov 28, 2023
Merged
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
26 changes: 16 additions & 10 deletions lua/flatten/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,24 @@ function M.smart_open(focus)

-- traverse the window tree to find the first available window
local stack = { layout }
local win_alt = vim.fn.win_getid(vim.fn.winnr("#"))
local win

while #stack > 0 do
local node = table.remove(stack)
if node[1] == "leaf" then
if valid_targets[node[2]] then
win = node[2]
break
end
else
for i = #node[2], 1, -1 do
table.insert(stack, node[2][i])
-- prefer the alternative window if it's valid
if valid_targets[win_alt] and win_alt ~= vim.api.nvim_get_current_win() then
win = win_alt
else
while #stack > 0 do
local node = table.remove(stack)
if node[1] == "leaf" then
if valid_targets[node[2]] then
win = node[2]
break
end
else
for i = #node[2], 1, -1 do
table.insert(stack, node[2][i])
end
end
end
end
Expand Down