Skip to content

Commit

Permalink
refactor: favor same tab win
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-reineke committed Oct 23, 2023
1 parent 8a7b48f commit 072765a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
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

0 comments on commit 072765a

Please sign in to comment.