feat(picker.preview): add option to opt out of real-buffer preview - #2927
feat(picker.preview): add option to opt out of real-buffer preview#2927fmorroni wants to merge 1 commit into
Conversation
Picker previews can be of two types: scratch buffers or real buffers. Scratch buffers are used when the file isn't already open, while real buffers are used when the file is already loaded. Using a real buffer means the preview inherits the buffer's existing state and keymaps, which can interfere with picker-specific keymaps (see folke#1417). It also updates the buffer's last-used timestamp, which can affect picker sorting (see folke#773). Add a `use_real_buffer` option to allow users to opt out of real-buffer previews and always use scratch buffers instead.
|
You might also want to make the following addition diff --git a/lua/snacks/picker/source/buffers.lua b/lua/snacks/picker/source/buffers.lua
index f7a7ee7a..47e9f349 100644
--- a/lua/snacks/picker/source/buffers.lua
+++ b/lua/snacks/picker/source/buffers.lua
@@ -47,6 +47,9 @@ function M.buffers(opts, ctx)
end
if opts.sort_lastused then
table.sort(items, function(a, b)
+ if a.info.lastused == b.info.lastused then
+ return a.buf < b.buf
+ end
return a.info.lastused > b.info.lastused
end)
endbecause otherwise the order will still be non-deterministic for same |
|
Hmm yeah that makes sense. Although I think that change should be added regardless of whether this PR is accepted or not, so maybe it should go in its own PR? That being said, I have no issues with adding it here if that seems best. |
|
I'm just a simple user myself like you. I just made the suggestion because you mentioned in your OP about how Whether you want to make a different PR or add it here is up to you. Not making any decisions myself. |
Description
Picker previews can be of two types: scratch buffers or real buffers. Scratch buffers are used when the file isn't already open, while real buffers are used when the file is already loaded.
Using a real buffer means the preview inherits the buffer's existing state and keymaps, which can interfere with picker-specific keymaps (see #1417). It also updates the buffer's last-used timestamp, which can affect picker sorting (see #773).
For my use cases, having the real-buffer preview has no benefits. Other users also seem to feel the same way (#773 (comment)).
This PR adds a
use_real_bufferoption to allow users to opt out of real-buffer previews and always use scratch buffers instead. You would opt out by settingpicker.previewers.file.use_real_buffer = false.Related Issue(s)
#1417
#773