Skip to content

Commit

Permalink
feat(qfwin): change to make opening item location consistent and pred…
Browse files Browse the repository at this point in the history
…icable
  • Loading branch information
Iraq Jaber authored and Iraq Jaber committed May 13, 2024
1 parent 7751b6e commit a633312
Showing 1 changed file with 49 additions and 7 deletions.
56 changes: 49 additions & 7 deletions lua/bqf/qfwin/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ function M.signVMToggle(bufnr)
vim.validate({
mode = {
mode, function(m)
-- ^V = 0x16
return m:lower() == 'v' or m == ('%c'):format(0x16)
end, 'visual mode'
-- ^V = 0x16
return m:lower() == 'v' or m == ('%c'):format(0x16)
end, 'visual mode'
}
})
-- ^[ = 0x1b
Expand Down Expand Up @@ -243,6 +243,48 @@ function M.open(close, jumpCmd, qwinid, idx)
end
cmd(('%s %s'):format(jumpCmd, fname))
else
local current_tabnr = vim.api.nvim_win_get_tabpage(vim.api.nvim_get_current_win())
local winnr
local winid
local bufInfos = fn.getbufinfo(bufnr)
for key, buffinfo in pairs(bufInfos) do
local windows = buffinfo.windows
for i = 1, #windows do
local window = windows[i]
local wininfo = vim.fn.getwininfo(window)[1]

-- if wininfo.tabnr ~= current_tabnr then
-- print('break')
-- -- continue
-- do break end
-- end

local winnr_ = wininfo.winnr
local winid_ = wininfo.winid

if not (winnr) then
winnr = winnr_
winid = winid_
else
if winnr_ < winnr then
winnr = winnr_
winid = winid_
end
end

if winnr_ == 1 then
break
end
end
end

if not (winid) then
local buffnr = vim.fn.winbufnr(1)
local winid = vim.fn.bufwinid(buffnr)
vim.api.nvim_set_current_win(winid)
else
vim.api.nvim_set_current_win(winid)
end
api.nvim_set_current_buf(bufnr)
end
end)
Expand All @@ -257,10 +299,10 @@ function M.tabedit(stay, qwinid, idx)
qwinid = qwinid or api.nvim_get_current_win()
local unnameBuf = true
if doEdit(qwinid, idx, false, function(bufnr)
unnameBuf = false
local fname = fn.fnameescape(api.nvim_buf_get_name(bufnr))
cmd(('tabedit %s'):format(fname))
end) then
unnameBuf = false
local fname = fn.fnameescape(api.nvim_buf_get_name(bufnr))
cmd(('tabedit %s'):format(fname))
end) then
local curTabPage = api.nvim_get_current_tabpage()
if not unnameBuf then
api.nvim_set_current_win(qwinid)
Expand Down

0 comments on commit a633312

Please sign in to comment.