mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 10:49:08 +00:00
fix(input): change buftype to prompt. Fixes #350
This commit is contained in:
parent
d1ccbde786
commit
2990bf0c7a
1 changed files with 17 additions and 3 deletions
|
@ -53,14 +53,17 @@ Snacks.config.style("input", {
|
|||
winhighlight = "NormalFloat:SnacksInputNormal,FloatBorder:SnacksInputBorder,FloatTitle:SnacksInputTitle",
|
||||
cursorline = false,
|
||||
},
|
||||
bo = { filetype = "snacks_input" },
|
||||
bo = {
|
||||
filetype = "snacks_input",
|
||||
buftype = "prompt",
|
||||
},
|
||||
--- buffer local variables
|
||||
b = {
|
||||
completion = false, -- disable blink completions in input
|
||||
},
|
||||
keys = {
|
||||
i_esc = { "<esc>", { "cmp_close", "cancel" }, mode = "i" },
|
||||
-- i_esc = { "<esc>", "stopinsert", mode = "i" },
|
||||
n_esc = { "<esc>", { "cmp_close", "cancel" }, mode = "n" },
|
||||
i_esc = { "<esc>", { "cmp_close", "stopinsert" }, mode = "i" },
|
||||
i_cr = { "<cr>", { "cmp_accept", "confirm" }, mode = "i" },
|
||||
i_tab = { "<tab>", { "cmp_select_next", "cmp" }, mode = "i" },
|
||||
q = "cancel",
|
||||
|
@ -181,16 +184,27 @@ function M.input(opts, on_confirm)
|
|||
|
||||
local win = Snacks.win(opts.win)
|
||||
ctx = { opts = opts, win = win }
|
||||
vim.fn.prompt_setprompt(win.buf, "")
|
||||
vim.cmd.startinsert()
|
||||
if opts.default then
|
||||
vim.api.nvim_buf_set_lines(win.buf, 0, -1, false, { opts.default })
|
||||
vim.bo[win.buf].modified = false
|
||||
vim.api.nvim_win_set_cursor(win.win, { 1, #opts.default + 1 })
|
||||
end
|
||||
vim.fn.prompt_setcallback(win.buf, function(text)
|
||||
confirm(text)
|
||||
win:close()
|
||||
end)
|
||||
vim.fn.prompt_setinterrupt(win.buf, function()
|
||||
confirm()
|
||||
win:close()
|
||||
end)
|
||||
|
||||
if opts.expand then
|
||||
vim.api.nvim_create_autocmd("TextChangedI", {
|
||||
buffer = win.buf,
|
||||
callback = function()
|
||||
vim.bo[win.buf].modified = false
|
||||
if vim.api.nvim_win_is_valid(parent_win) then
|
||||
vim.api.nvim_win_call(parent_win, function()
|
||||
win:update()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue