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

refactor: favor same tab win #749

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions lua/ibl/scope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ M.get = function(bufnr, config)

local win
if bufnr ~= vim.api.nvim_get_current_buf() then
local win_list = vim.fn.win_findbuf(bufnr)
win = win_list and win_list[1]
win = utils.get_win(bufnr)
if not win then
return nil
end
Expand Down
24 changes: 18 additions & 6 deletions lua/ibl/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ M.encode = function(input)
)
end

---@param bufnr number
---@return number?
M.get_win = function(bufnr)
local win_list = vim.fn.win_findbuf(bufnr)
local current_tab = vim.api.nvim_get_current_tabpage()
for _, win in ipairs(win_list or {}) do
if current_tab == vim.api.nvim_win_get_tabpage(win) then
return win
end
end
return win_list and win_list[1]
end

---@class ibl.listchars
---@field tabstop_overwrite boolean
---@field space_char string
Expand All @@ -81,8 +94,7 @@ M.get_listchars = function(bufnr)
end

if bufnr ~= vim.api.nvim_get_current_buf() then
local win_list = vim.fn.win_findbuf(bufnr)
local win = win_list and win_list[1]
local win = M.get_win(bufnr)
if win then
list = vim.api.nvim_get_option_value("list", { win = win })
if list then
Expand Down Expand Up @@ -159,18 +171,18 @@ end

---@param bufnr number
M.get_offset = function(bufnr)
local win = 0
local win
local win_view
local win_end
if bufnr == vim.api.nvim_get_current_buf() then
win = 0
win_view = vim.fn.winsaveview()
win_end = vim.fn.line "w$"
else
local win_list = vim.fn.win_findbuf(bufnr)
if not win_list or not win_list[1] then
win = M.get_win(bufnr)
if not win then
return 0, 0, 0, 0
end
win = win_list[1]
win_view = vim.api.nvim_win_call(win, vim.fn.winsaveview)
end

Expand Down
Loading