Skip to content

Commit 403a9c5

Browse files
authored
fix(input)!: pass bufnr and winid to neo_tree_popup_input_ready event (#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.
1 parent 00b46a1 commit 403a9c5

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

doc/neo-tree.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,11 +1438,19 @@ This is fired inside a vim.schedule.
14381438
>lua
14391439
{
14401440
event = "neo_tree_popup_input_ready",
1441-
---@param input NuiInput
1442-
handler = function(input)
1441+
handler = function()
14431442
-- enter input popup with normal mode by default.
14441443
vim.cmd("stopinsert")
14451444
end,
1445+
},
1446+
{
1447+
event = "neo_tree_popup_input_ready",
1448+
---@param args { bufnr: integer, winid: integer }
1449+
handler = function(args)
1450+
-- map <esc> to enter normal mode (by default closes prompt)
1451+
-- don't forget `opts.buffer` to specify the buffer of the popup.
1452+
vim.keymap.set("i", "<esc>", vim.cmd.stopinsert, { noremap = true, buffer = args.bufnr })
1453+
end,
14461454
}
14471455
<
14481456

lua/neo-tree/setup/deprecations.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ See instructions in `:h neo-tree-events` for more details.
118118
event_handlers = {
119119
{
120120
event = "neo_tree_popup_input_ready",
121-
---@param input NuiInput
122-
handler = function(input)
123-
-- enter input popup with normal mode by default.
121+
---@param args { bufnr: integer, winid: integer }
122+
handler = function(args)
124123
vim.cmd("stopinsert")
124+
vim.keymap.set("i", "<esc>", vim.cmd.stopinsert, { noremap = true, buffer = args.bufnr })
125125
end,
126126
}
127127
}

lua/neo-tree/ui/inputs.lua

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,11 @@ local should_use_popup_input = function()
1212
end
1313

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

18-
if input.prompt_type ~= "confirm" then
19-
vim.schedule(function()
20-
-- deprecate this option in next version
21-
if config.enable_normal_mode_for_inputs then
22-
vim.cmd("stopinsert")
23-
end
24-
events.fire_event(events.NEO_TREE_POPUP_INPUT_READY)
25-
end)
26-
end
27-
2817
input:map("i", "<esc>", function()
2918
vim.cmd("stopinsert")
30-
if not config.enable_normal_mode_for_inputs or input.prompt_type == "confirm" then
31-
input:unmount()
32-
end
19+
input:unmount()
3320
end, { noremap = true })
3421

3522
input:map("n", "<esc>", function()
@@ -49,6 +36,15 @@ M.show_input = function(input, callback)
4936
callback()
5037
end
5138
end, { once = true })
39+
40+
if input.prompt_type ~= "confirm" then
41+
vim.schedule(function()
42+
events.fire_event(events.NEO_TREE_POPUP_INPUT_READY, {
43+
bufnr = input.bufnr,
44+
winid = input.winid,
45+
})
46+
end)
47+
end
5248
end
5349

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

0 commit comments

Comments
 (0)