Skip to content

Commit

Permalink
fix(input)!: pass bufnr and winid to neo_tree_popup_input_ready eve…
Browse files Browse the repository at this point in the history
…nt (#1398)

BREAKING CHANGE:  `config.enable_normal_mode_for_inputs` does absolutely nothing now. Please configure inputs for normal mode with the `neo_tree_popup_input_ready` event.
  • Loading branch information
pysan3 authored Mar 16, 2024
1 parent 00b46a1 commit 403a9c5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
12 changes: 10 additions & 2 deletions doc/neo-tree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1438,11 +1438,19 @@ This is fired inside a vim.schedule.
>lua
{
event = "neo_tree_popup_input_ready",
---@param input NuiInput
handler = function(input)
handler = function()
-- enter input popup with normal mode by default.
vim.cmd("stopinsert")
end,
},
{
event = "neo_tree_popup_input_ready",
---@param args { bufnr: integer, winid: integer }
handler = function(args)
-- map <esc> to enter normal mode (by default closes prompt)
-- don't forget `opts.buffer` to specify the buffer of the popup.
vim.keymap.set("i", "<esc>", vim.cmd.stopinsert, { noremap = true, buffer = args.bufnr })
end,
}
<

Expand Down
6 changes: 3 additions & 3 deletions lua/neo-tree/setup/deprecations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ See instructions in `:h neo-tree-events` for more details.
event_handlers = {
{
event = "neo_tree_popup_input_ready",
---@param input NuiInput
handler = function(input)
-- enter input popup with normal mode by default.
---@param args { bufnr: integer, winid: integer }
handler = function(args)
vim.cmd("stopinsert")
vim.keymap.set("i", "<esc>", vim.cmd.stopinsert, { noremap = true, buffer = args.bufnr })
end,
}
}
Expand Down
24 changes: 10 additions & 14 deletions lua/neo-tree/ui/inputs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,11 @@ local should_use_popup_input = function()
end

M.show_input = function(input, callback)
local config = require("neo-tree").config
input:mount()

if input.prompt_type ~= "confirm" then
vim.schedule(function()
-- deprecate this option in next version
if config.enable_normal_mode_for_inputs then
vim.cmd("stopinsert")
end
events.fire_event(events.NEO_TREE_POPUP_INPUT_READY)
end)
end

input:map("i", "<esc>", function()
vim.cmd("stopinsert")
if not config.enable_normal_mode_for_inputs or input.prompt_type == "confirm" then
input:unmount()
end
input:unmount()
end, { noremap = true })

input:map("n", "<esc>", function()
Expand All @@ -49,6 +36,15 @@ M.show_input = function(input, callback)
callback()
end
end, { once = true })

if input.prompt_type ~= "confirm" then
vim.schedule(function()
events.fire_event(events.NEO_TREE_POPUP_INPUT_READY, {
bufnr = input.bufnr,
winid = input.winid,
})
end)
end
end

M.input = function(message, default_value, callback, options, completion)
Expand Down

0 comments on commit 403a9c5

Please sign in to comment.