Skip to content

Commit 141362b

Browse files
authored
Merge pull request #1655 from frankfriberg/use-vim-input-as-input
2 parents 6871885 + afbf66f commit 141362b

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

lua/neogit/lib/input.lua

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
local M = {}
22

3+
local async = require("plenary.async")
4+
local input = async.wrap(function(prompt, default, completion, callback)
5+
vim.ui.input({
6+
prompt = prompt,
7+
default = default,
8+
completion = completion,
9+
}, callback)
10+
end, 4)
11+
312
--- Provides the user with a confirmation
413
---@param msg string Prompt to use for confirmation
514
---@param options table|nil
@@ -57,34 +66,22 @@ end
5766
function M.get_user_input(prompt, opts)
5867
opts = vim.tbl_extend("keep", opts or {}, { strip_spaces = false, separator = ": " })
5968

60-
vim.fn.inputsave()
61-
6269
if opts.prepend then
6370
vim.defer_fn(function()
6471
vim.api.nvim_input(opts.prepend)
6572
end, 10)
6673
end
6774

68-
local status, result = pcall(vim.fn.input, {
69-
prompt = ("%s%s"):format(prompt, opts.separator),
70-
default = opts.default,
71-
completion = opts.completion,
72-
cancelreturn = opts.cancel,
73-
})
75+
local result = input(("%s%s"):format(prompt, opts.separator), opts.default, opts.completion)
7476

75-
vim.fn.inputrestore()
76-
if not status then
77+
if result == "" or result == nil then
7778
return nil
7879
end
7980

8081
if opts.strip_spaces then
8182
result, _ = result:gsub("%s", "-")
8283
end
8384

84-
if result == "" then
85-
return nil
86-
end
87-
8885
return result
8986
end
9087

0 commit comments

Comments
 (0)