mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-05 03:08:13 +00:00
fix(picker.input): better handling of stopinsert
with prompt buffers. Closes #723
This commit is contained in:
parent
38649556ee
commit
c2916cb526
2 changed files with 22 additions and 1 deletions
|
@ -24,6 +24,14 @@ function M.new(picker)
|
||||||
text = picker.opts.live and self.filter.search or self.filter.pattern,
|
text = picker.opts.live and self.filter.search or self.filter.pattern,
|
||||||
ft = "regex",
|
ft = "regex",
|
||||||
on_win = function(win)
|
on_win = function(win)
|
||||||
|
-- HACK: set all other picker input prompt buffers to nofile.
|
||||||
|
-- Otherwise when the prompt buffer is closed,
|
||||||
|
-- Neovim always stops insert mode.
|
||||||
|
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
||||||
|
if buf ~= win.buf and vim.bo[buf].filetype == "snacks_picker_input" then
|
||||||
|
vim.bo[buf].buftype = "nofile"
|
||||||
|
end
|
||||||
|
end
|
||||||
vim.fn.prompt_setprompt(win.buf, "")
|
vim.fn.prompt_setprompt(win.buf, "")
|
||||||
win:focus()
|
win:focus()
|
||||||
vim.cmd("startinsert!")
|
vim.cmd("startinsert!")
|
||||||
|
@ -75,6 +83,19 @@ function M:close()
|
||||||
self.picker = nil -- needed for garbage collection of the picker
|
self.picker = nil -- needed for garbage collection of the picker
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M:stopinsert()
|
||||||
|
-- only stop insert mode if needed
|
||||||
|
if not vim.fn.mode():find("^i") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local buf = vim.api.nvim_get_current_buf()
|
||||||
|
-- if the other buffer is a prompt, then don't stop insert mode
|
||||||
|
if buf ~= self.win.buf and vim.bo[buf].buftype == "prompt" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
vim.cmd("stopinsert")
|
||||||
|
end
|
||||||
|
|
||||||
function M:statuscolumn()
|
function M:statuscolumn()
|
||||||
local parts = {} ---@type string[]
|
local parts = {} ---@type string[]
|
||||||
local function add(str, hl)
|
local function add(str, hl)
|
||||||
|
|
|
@ -464,10 +464,10 @@ end
|
||||||
|
|
||||||
--- Close the picker
|
--- Close the picker
|
||||||
function M:close()
|
function M:close()
|
||||||
vim.cmd.stopinsert()
|
|
||||||
if self.closed then
|
if self.closed then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
self.input:stopinsert()
|
||||||
|
|
||||||
self:hist_record(true)
|
self:hist_record(true)
|
||||||
self.closed = true
|
self.closed = true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue