From eec361d1d3c9433106bd070594b4f7883201d66e Mon Sep 17 00:00:00 2001 From: Konrad Malik Date: Sun, 19 Jan 2025 10:18:11 +0100 Subject: [PATCH] fix: floating-input potential close-bug fixed --- config/nvim/lua/pde/floating-input.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/config/nvim/lua/pde/floating-input.lua b/config/nvim/lua/pde/floating-input.lua index 1357e6c5..cc49a3aa 100644 --- a/config/nvim/lua/pde/floating-input.lua +++ b/config/nvim/lua/pde/floating-input.lua @@ -1,4 +1,4 @@ -local M = {} +-- https://github.com/liangxianzhe/floating-input.nvim ---@param winid integer ---@param input_width integer @@ -17,12 +17,14 @@ local under_cursor = { col = 0, } +local M = {} + function M.input(opts, on_confirm, win_config) local prompt = opts.prompt or "Input: " local default = opts.default or "" on_confirm = on_confirm or function() end - -- Calculate a minimal width with a bit padding + -- Calculate a minimal width with a padding local default_length = vim.str_utfindex(default, "utf-8") local default_width = default_length + 10 local prompt_width = vim.str_utfindex(prompt, "utf-8") + 10 @@ -56,26 +58,24 @@ function M.input(opts, on_confirm, win_config) vim.cmd("startinsert") vim.api.nvim_win_set_cursor(window, { 1, default_length + 1 }) - local function close() - vim.cmd("stopinsert") - vim.api.nvim_win_close(window, true) - end - -- Enter to confirm vim.keymap.set({ "n", "i", "v" }, "", function() local lines = vim.api.nvim_buf_get_lines(buffer, 0, 1, false) - close() + vim.cmd("stopinsert") on_confirm(lines[1]) + vim.api.nvim_win_close(window, true) end, { buffer = buffer }) -- Esc or q to close vim.keymap.set("n", "", function() - close() on_confirm(nil) + vim.cmd("stopinsert") + vim.api.nvim_win_close(window, true) end, { buffer = buffer }) vim.keymap.set("n", "q", function() - close() on_confirm(nil) + vim.cmd("stopinsert") + vim.api.nvim_win_close(window, true) end, { buffer = buffer }) end