mirror of
https://github.com/neovim/neovim.git
synced 2026-10-25 23:20:23 -05:00
backport: opts.scope in vim.ui.input (#39906)
feat(ui): vim.ui.input(opts.scope) #39570 Problem: There is no way for a `vim.ui.input` caller to indicate for which scope the input is. As in "This input is for something at cursor scope". This information can be useful for `vim.ui.input` implementation to tweak its behavior and presentation: - Show different floating window depending on the scope. For example: - Near cursor for "cursor" scope. - At line start for "line" scope. - In window corner for "buffer" and "window" scopes. - In whole editor corner for "tabpage", "editor", "project" scopes. - Navigate through history only for inputs with the same scope. Solution: Document new `opts.scope` for `vim.ui.input`. Use it in the codebase.
This commit is contained in:
1 parent
b0bfce290f
commit
b05675bccc
5 files changed
+22
-3
No files matched your search
+10
-1
@@ -5109,7 +5109,8 @@ vim.ui.input({opts}, {on_confirm}) *vim.ui.input()*
|
|||||||
work until `on_confirm`.
|
work until `on_confirm`.
|
||||||
|
|
||||||
Example: >lua
|
Example: >lua
|
||||||
vim.ui.input({ prompt = 'Enter value for shiftwidth: ' }, function(input)
|
local opts = { prompt = 'Enter value for shiftwidth: ', scope = 'buffer' }
|
||||||
|
vim.ui.input(opts, function(input)
|
||||||
vim.o.shiftwidth = tonumber(input)
|
vim.o.shiftwidth = tonumber(input)
|
||||||
end)
|
end)
|
||||||
<
|
<
|
||||||
@@ -5124,6 +5125,14 @@ vim.ui.input({opts}, {on_confirm}) *vim.ui.input()*
|
|||||||
• {highlight}? (`function`) Function that will be used
|
• {highlight}? (`function`) Function that will be used
|
||||||
for highlighting user inputs.
|
for highlighting user inputs.
|
||||||
• {prompt}? (`string`) Text of the prompt
|
• {prompt}? (`string`) Text of the prompt
|
||||||
|
• {scope}?
|
||||||
|
(`'cursor'|'line'|'buffer'|'window'|'tabpage'|'editor'|'project'`)
|
||||||
|
Input scope, as in "This input is for something at
|
||||||
|
cursor/line/etc scope". Can be used by `vim.ui.input`
|
||||||
|
implementations to tweak behavior and presentation.
|
||||||
|
For example, the input may adjust the floating window
|
||||||
|
position: near the cursor if `cursor`, in window
|
||||||
|
corner if `buffer` or `window`, etc.
|
||||||
• {on_confirm} (`fun(input?: string)`) Called once the user confirms or
|
• {on_confirm} (`fun(input?: string)`) Called once the user confirms or
|
||||||
abort the input. `input` is what the user typed (it
|
abort the input. `input` is what the user typed (it
|
||||||
might be an empty string if nothing was entered), or
|
might be an empty string if nothing was entered), or
|
||||||
|
|||||||
@@ -313,6 +313,7 @@ LUA
|
|||||||
• Added `__eq` metamethod to |vim.VersionRange|. 2 distinct but representing
|
• Added `__eq` metamethod to |vim.VersionRange|. 2 distinct but representing
|
||||||
the same range instances now compare equal.
|
the same range instances now compare equal.
|
||||||
• |vim.pos| can now convert between positions and buffer offsets.
|
• |vim.pos| can now convert between positions and buffer offsets.
|
||||||
|
• |vim.ui.input()| now allows setting input scope.
|
||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
|
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ function M.get(lang)
|
|||||||
info.lang,
|
info.lang,
|
||||||
info.encoding
|
info.encoding
|
||||||
)
|
)
|
||||||
vim.ui.input({ prompt = prompt }, function(input)
|
vim.ui.input({ prompt = prompt, scope = 'editor' }, function(input)
|
||||||
-- properly clear the message window
|
-- properly clear the message window
|
||||||
vim.api.nvim_echo({ { ' ' } }, false, { kind = 'empty' })
|
vim.api.nvim_echo({ { ' ' } }, false, { kind = 'empty' })
|
||||||
if not input or input:lower() ~= 'y' then
|
if not input or input:lower() ~= 'y' then
|
||||||
|
|||||||
@@ -815,6 +815,7 @@ function M.rename(new_name, opts)
|
|||||||
|
|
||||||
local prompt_opts = {
|
local prompt_opts = {
|
||||||
prompt = 'New Name: ',
|
prompt = 'New Name: ',
|
||||||
|
scope = 'cursor',
|
||||||
}
|
}
|
||||||
if result.placeholder then
|
if result.placeholder then
|
||||||
prompt_opts.default = result.placeholder
|
prompt_opts.default = result.placeholder
|
||||||
@@ -845,6 +846,7 @@ function M.rename(new_name, opts)
|
|||||||
local prompt_opts = {
|
local prompt_opts = {
|
||||||
prompt = 'New Name: ',
|
prompt = 'New Name: ',
|
||||||
default = cword,
|
default = cword,
|
||||||
|
scope = 'cursor',
|
||||||
}
|
}
|
||||||
vim.ui.input(prompt_opts, function(input)
|
vim.ui.input(prompt_opts, function(input)
|
||||||
if not input or #input == 0 then
|
if not input or #input == 0 then
|
||||||
|
|||||||
@@ -96,6 +96,12 @@ end
|
|||||||
---Function that will be used for highlighting
|
---Function that will be used for highlighting
|
||||||
---user inputs.
|
---user inputs.
|
||||||
---@field highlight? function
|
---@field highlight? function
|
||||||
|
---
|
||||||
|
---Input scope, as in "This input is for something at cursor/line/etc scope".
|
||||||
|
---Can be used by `vim.ui.input` implementations to tweak behavior and presentation.
|
||||||
|
---For example, the input may adjust the floating window position: near the cursor if
|
||||||
|
---`cursor`, in window corner if `buffer` or `window`, etc.
|
||||||
|
---@field scope? 'cursor'|'line'|'buffer'|'window'|'tabpage'|'editor'|'project'
|
||||||
|
|
||||||
--- Prompts the user for input, allowing arbitrary (potentially asynchronous) work until
|
--- Prompts the user for input, allowing arbitrary (potentially asynchronous) work until
|
||||||
--- `on_confirm`.
|
--- `on_confirm`.
|
||||||
@@ -103,7 +109,8 @@ end
|
|||||||
--- Example:
|
--- Example:
|
||||||
---
|
---
|
||||||
--- ```lua
|
--- ```lua
|
||||||
--- vim.ui.input({ prompt = 'Enter value for shiftwidth: ' }, function(input)
|
--- local opts = { prompt = 'Enter value for shiftwidth: ', scope = 'buffer' }
|
||||||
|
--- vim.ui.input(opts, function(input)
|
||||||
--- vim.o.shiftwidth = tonumber(input)
|
--- vim.o.shiftwidth = tonumber(input)
|
||||||
--- end)
|
--- end)
|
||||||
--- ```
|
--- ```
|
||||||
|
|||||||
Reference in new issue
Block a user