-
Notifications
You must be signed in to change notification settings - Fork 6
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: enhance height handling, add view argument to open()/toggle() #38
Conversation
Warning There is also a bug to fix:
require('quicker').toggle { open_cmd_mods = { vertical = true } } |
The issue occurs if: - cursor position is not at the top - focus=true - opened quickfix win is large enough to change the scroll position
b75c31c
to
acc93f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kind of config and feature is likely to grow out of control in the future. It starts here, but then someone will ask for a way to restore the height for only certain quickfixes, or they want to clear the stored height/view when the quickfix changes, or they don't want to clear the height/view when the quickfix changes. I would much rather look at how the user can customize this in their own config, and then see if there are any primitives we can expose to make that simpler/easier.
Right now I think most of this should be easy to do in end-user config. Just set up a WinClosed
autocmd, check if the buffer is quickfix, and store the height/view. The toggle
and open
commands already let you specify a height and min/max height, so that's pretty easy. The only thing that we could maybe do is make it slightly easier to restore the saved win view, and honestly maybe just returning the winid from open
and toggle
would be enough. What do you think?
What you’re suggesting does make sense, but there are a lot of configurations required to implement saving the state for each window (give me a few more days). For now, I’d like to point out a few things. 1. Rework
|
Preserve the height and cursor position when toggling the quickfix or location list window:
|
Ok, in addition to the #38 (comment) option, I would also add a require('quicker').open {
---@type vim.fn.winrestview.dict
view = {
lnum = 20,
},
} Warning You can also reset the |
I will also rework how the height property is set. It's better to set it via command arguments.
vim.cmd.copen { count = <height>, ... } |
You're right; the Here is a list of small changes I will apply instead in this PR:
Not related to the PR:
|
fd2137c
to
5b800a4
Compare
Caution Function The same applies to the I don't want to change this logic in this PR. Can be patched with---Utility that checks if an event(s) is already defined
---@param aug nil|integer|string
---@param bufnr nil|integer|integer[]
---@param ... string
M.event_defined = function(aug, bufnr, ...)
return #vim.api.nvim_get_autocmds({
group = aug,
buffer = bufnr,
event = { ... },
}) > 0
end
local util = require("quicker.util")
---@param bufnr number
function M.constrain_cursor(bufnr)
-- HACK: we have to defer this call because sometimes the autocmds don't take effect.
vim.schedule(function()
if not vim.api.nvim_buf_is_valid(bufnr) then
return
end
local aug = vim.api.nvim_create_augroup("quicker", { clear = false })
if util.event_defined(aug, bufnr, "InsertEnter", "CursorMoved", "ModeChanged") then
return
end
vim.api.nvim_create_autocmd("InsertEnter", {
desc = "Constrain quickfix cursor position",
group = aug,
nested = true,
buffer = bufnr,
-- For some reason the cursor bounces back to its original position,
-- so we have to defer the call
callback = vim.schedule_wrap(constrain_cursor),
})
vim.api.nvim_create_autocmd({ "CursorMoved", "ModeChanged" }, {
desc = "Constrain quickfix cursor position",
nested = true,
group = aug,
buffer = bufnr,
callback = constrain_cursor,
})
end)
end
|
The scheduling in And it also should be named like |
5b800a4
to
335c535
Compare
The issues #38 (comment) and #38 (comment) are not related to the current PR. I’m done working on this PR (see #38 (comment)). Apologies for the lengthy or unrelated comments. |
4a4d399
to
7643139
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current approach LGTM. Just fix the merge conflicts and we're good to go
I am a little bit confused because resolving conflicts (merging |
991040c
to
dd9bf7c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there may be an issue with how you resolve merges, because if all you saw was an empty commit then that's quite wrong. The merge deleted some logic that I added to master to handle the case when opening the quickfix as a vsplit
dd9bf7c
to
60c24ef
Compare
I changed the merge process. Instead of "resolving" conflicts in the merge commit, I added parts of the code during the merge and then removed them with separate commits (the same result in a different form). TL;DR Sorry for wasting so much time on such a trivial PR. |
48329b1
to
502507f
Compare
Great, looks good now. Thanks for the PR! |
Add new optionsPrevent the scroll position from jumping when the quickfix opensrecording-1.mp4