From abde91ecaf338da4a0b88e383583624b5cab7b30 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 30 Jan 2022 13:32:55 +0100 Subject: docs: add example to vim.ui.select (#17241) Closes https://github.com/neovim/neovim/issues/17137 --- runtime/lua/vim/ui.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'runtime/lua/vim/ui.lua') diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index 9568b60fd0..0f2de6ce5c 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -18,6 +18,24 @@ local M = {} --- Called once the user made a choice. --- `idx` is the 1-based index of `item` within `item`. --- `nil` if the user aborted the dialog. +--- +--- +--- Example: +---
+--- vim.ui.select({ 'tabs', 'spaces' }, {
+---     prompt = 'Select tabs or spaces:',
+---     format_item = function(item)
+---         return "I'd like to choose " .. item
+---     end,
+--- }, function(choice)
+---     if choice == 'spaces' then
+---         vim.o.expandtab = true
+---     else
+---         vim.o.expandtab = false
+---     end
+--- end)
+--- 
+ function M.select(items, opts, on_choice) vim.validate { items = { items, 'table', false }, @@ -57,6 +75,13 @@ end --- Called once the user confirms or abort the input. --- `input` is what the user typed. --- `nil` if the user aborted the dialog. +--- +--- Example: +---
+--- vim.ui.input({ prompt = 'Select value for shiftwidth: ' }, function(input)
+---     vim.o.shiftwidth = tonumber(input)
+--- end)
+--- 
function M.input(opts, on_confirm) vim.validate { on_confirm = { on_confirm, 'function', false }, -- cgit From 64116d78502e0ca611e13adf9323ef2d3fe708c2 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 8 Feb 2022 01:19:06 +0100 Subject: chore: fix typos (#17250) Co-authored-by: zeertzjq Co-authored-by: Dani Dickstein Co-authored-by: Axel Dahlberg --- runtime/lua/vim/ui.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/ui.lua') diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index 0f2de6ce5c..9d4b38f08a 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -78,7 +78,7 @@ end --- --- Example: ---
---- vim.ui.input({ prompt = 'Select value for shiftwidth: ' }, function(input)
+--- vim.ui.input({ prompt = 'Enter value for shiftwidth: ' }, function(input)
 ---     vim.o.shiftwidth = tonumber(input)
 --- end)
 --- 
-- cgit From e63e5d1dbd3dd4711efa0ecf9e844ff308b370a6 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 15 Apr 2022 12:35:06 +0200 Subject: docs: typo fixes (#17859) Co-authored-by: Elias Alves Moura Co-authored-by: venkatesh Co-authored-by: zeertzjq Co-authored-by: Vikas Raj <24727447+numToStr@users.noreply.github.com> Co-authored-by: Steve Vermeulen Co-authored-by: Evgeni Chasnovski Co-authored-by: rwxd Co-authored-by: casswedson <58050969+casswedson@users.noreply.github.com> --- runtime/lua/vim/ui.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/ui.lua') diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index 9d4b38f08a..165dada1b8 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -16,7 +16,7 @@ local M = {} --- `items`, or the context in which select() was called. ---@param on_choice function ((item|nil, idx|nil) -> ()) --- Called once the user made a choice. ---- `idx` is the 1-based index of `item` within `item`. +--- `idx` is the 1-based index of `item` within `items`. --- `nil` if the user aborted the dialog. --- --- -- cgit From aefdc6783cb77f09786542c90901a9e7120bea42 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Mon, 9 May 2022 11:23:51 +0200 Subject: chore: format runtime with stylua --- runtime/lua/vim/ui.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'runtime/lua/vim/ui.lua') diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index 165dada1b8..77bca7f6c4 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -37,12 +37,12 @@ local M = {} --- function M.select(items, opts, on_choice) - vim.validate { + vim.validate({ items = { items, 'table', false }, on_choice = { on_choice, 'function', false }, - } + }) opts = opts or {} - local choices = {opts.prompt or 'Select one of:'} + local choices = { opts.prompt or 'Select one of:' } local format_item = opts.format_item or tostring for i, item in pairs(items) do table.insert(choices, string.format('%d: %s', i, format_item(item))) @@ -83,9 +83,9 @@ end --- end) --- function M.input(opts, on_confirm) - vim.validate { + vim.validate({ on_confirm = { on_confirm, 'function', false }, - } + }) opts = opts or {} local input = vim.fn.input(opts) -- cgit From ee6b21e8430ea810ba2e3e9163b941386a2e1d65 Mon Sep 17 00:00:00 2001 From: 0x74696d6d79 <34635512+tzx@users.noreply.github.com> Date: Tue, 28 Jun 2022 05:53:15 -0400 Subject: fix(vim.ui.input): accept nil or empty "opts" #19109 Fix #18143 --- runtime/lua/vim/ui.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim/ui.lua') diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index 77bca7f6c4..6f1ce3089d 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -59,7 +59,7 @@ end --- ---@param opts table Additional options. See |input()| --- - prompt (string|nil) ---- Text of the prompt. Defaults to `Input: `. +--- Text of the prompt --- - default (string|nil) --- Default reply to the input --- - completion (string|nil) @@ -87,7 +87,7 @@ function M.input(opts, on_confirm) on_confirm = { on_confirm, 'function', false }, }) - opts = opts or {} + opts = (opts and not vim.tbl_isempty(opts)) and opts or vim.empty_dict() local input = vim.fn.input(opts) if #input > 0 then on_confirm(input) -- cgit