From 403a9c5014624dc517b850a360f345340139307c Mon Sep 17 00:00:00 2001 From: takuto Date: Sat, 16 Mar 2024 23:58:19 +0900 Subject: [PATCH] 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. --- doc/neo-tree.txt | 12 ++++++++++-- lua/neo-tree/setup/deprecations.lua | 6 +++--- lua/neo-tree/ui/inputs.lua | 24 ++++++++++-------------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/doc/neo-tree.txt b/doc/neo-tree.txt index 656bad3d..ccccb50b 100644 --- a/doc/neo-tree.txt +++ b/doc/neo-tree.txt @@ -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 to enter normal mode (by default closes prompt) + -- don't forget `opts.buffer` to specify the buffer of the popup. + vim.keymap.set("i", "", vim.cmd.stopinsert, { noremap = true, buffer = args.bufnr }) + end, } < diff --git a/lua/neo-tree/setup/deprecations.lua b/lua/neo-tree/setup/deprecations.lua index a63858d6..527799ab 100644 --- a/lua/neo-tree/setup/deprecations.lua +++ b/lua/neo-tree/setup/deprecations.lua @@ -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", "", vim.cmd.stopinsert, { noremap = true, buffer = args.bufnr }) end, } } diff --git a/lua/neo-tree/ui/inputs.lua b/lua/neo-tree/ui/inputs.lua index dcd618d5..4b82036e 100644 --- a/lua/neo-tree/ui/inputs.lua +++ b/lua/neo-tree/ui/inputs.lua @@ -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", "", 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", "", function() @@ -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)