Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(input): pass bufnr and winid to event instead #1398

Merged
merged 4 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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")
cseickel marked this conversation as resolved.
Show resolved Hide resolved
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)
pysan3 marked this conversation as resolved.
Show resolved Hide resolved
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