fix: nui input cannot paste (#187)

This commit is contained in:
yetone 2024-08-24 16:25:08 +08:00 committed by GitHub
parent dbf2509d44
commit b8b5a3086e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View File

@ -1385,9 +1385,11 @@ function Sidebar:create_input()
width = win_width - 2, -- Subtract the width of the input box borders
},
}, {
disable_cursor_position_patch = true,
prompt = Config.windows.prompt.prefix,
default_value = "",
default_value = " ",
on_submit = function(user_input)
user_input = Utils.trim_spaces(user_input)
if user_input == "" then
self:create_input()
return

View File

@ -30,11 +30,14 @@ function M.trim(str, opts)
if not opts then
return str
end
local res = str
if opts.suffix then
return str:sub(-1) == opts.suffix and str:sub(1, -2) or str
elseif opts.prefix then
return str:sub(1, 1) == opts.prefix and str:sub(2) or str
res = str:sub(#str - #opts.suffix + 1) == opts.suffix and str:sub(1, #str - #opts.suffix) or str
end
if opts.prefix then
res = str:sub(1, #opts.prefix) == opts.prefix and str:sub(#opts.prefix + 1) or str
end
return res
end
function M.in_visual_mode()
@ -316,4 +319,8 @@ function M.is_sidebar_buffer(bufnr)
return v == true
end
function M.trim_spaces(s)
return s:match("^%s*(.-)%s*$")
end
return M