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(qfwin): change to make opening item location consistent and predicable #140

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
40 changes: 33 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,32 @@ function M.open(close, jumpCmd, qwinid, idx)
end
cmd(('%s %s'):format(jumpCmd, fname))
else
local winid
local lastused

local bufInfos = fn.getbufinfo(bufnr)
for key, buffinfo in pairs(bufInfos) do
for i = 1, #buffinfo.windows do
local wininfo = vim.fn.getwininfo(windows[i])[1]

local lastused_ = wininfo.lastused
local winid_ = wininfo.winid

if not lastused then
lastused = lastused_
winid = winid_
elseif lastused_ > lastused then
lastused = lastused_
winid = winid_
end
end
end

if not (winid) then
local bufnr = vim.fn.winbufnr(1)
winid = vim.fn.bufwinid(bufnr)
end
vim.api.nvim_set_current_win(winid)
api.nvim_set_current_buf(bufnr)
end
end)
Expand All @@ -257,10 +283,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