🪴 my neovim config:)
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

plugin: use prompt for `vim.ui.input` prompt

robin 8ba4a33a 4032aa8f

+22 -15
+22 -15
config/plugin/input.lua
··· 4 4 5 5 vim.g.loaded_input = true 6 6 7 - local old_input = vim.ui.input 8 - 9 7 ---@type fun(opts?: vim.ui.input.Opts, on_confirm: fun(input?: string)) 10 8 ---@diagnostic disable-next-line: duplicate-set-field 11 9 vim.ui.input = function(opts, on_confirm) 12 - if opts.prompt and #vim.split(opts.prompt, "\n") > 1 then 13 - old_input(opts, on_confirm) 14 - return 15 - end 16 - 17 10 local buf = vim.api.nvim_create_buf(false, true) 18 11 ---@type fun(v: string?) 19 12 local f = function(v) ··· 26 19 vim.bo[buf].bufhidden = "wipe" 27 20 vim.bo[buf].swapfile = false 28 21 29 - vim.fn.prompt_setprompt(buf, "") 22 + local promptset = vim.split(opts.prompt or "", "\n", { trimempty = false }) 23 + local promptlines 24 + local promptstr 25 + if #promptset > 1 then 26 + promptlines = vim.iter(promptset):slice(1, #promptset - 1):totable() 27 + promptstr = promptset[#promptset] 28 + else 29 + promptstr = opts.prompt 30 + end 31 + 32 + vim.fn.prompt_setprompt(buf, promptstr or "") 30 33 vim.fn.prompt_setcallback(buf, f) 31 34 vim.fn.prompt_setinterrupt(buf, f) 32 35 33 - vim.api.nvim_buf_set_lines(buf, 0, -1, false, { opts.default or "" }) 36 + promptlines = promptlines or {} 37 + if opts.default then 38 + table.insert(promptlines, (promptstr or "") .. opts.default) 39 + end 40 + vim.api.nvim_buf_set_lines(buf, 0, -1, false, promptlines) 34 41 local offset = vim.o.winborder == "none" and 0 or -1 35 42 local win = vim.api.nvim_open_win(buf, true, { 36 43 relative = "cursor", 37 - title = opts.prompt, 38 - height = 1, 44 + height = #promptset, 39 45 width = 1, 40 46 row = offset, 41 47 col = offset, ··· 44 50 vim.api.nvim_set_option_value("wrap", true, { win = win, scope = "local" }) 45 51 vim.api.nvim_set_option_value("signcolumn", "no", { win = win, scope = "local" }) 46 52 vim.api.nvim_set_option_value("sidescrolloff", 0, { win = win, scope = "local" }) 47 - local extrawidth = (vim.o.winborder == "none" and 0 or 1) * 2 48 53 vim.api.nvim_create_autocmd({ "CursorMovedI", "InsertEnter" }, { 49 54 buffer = buf, 50 55 callback = function() 51 - local col = vim.api.nvim_win_get_cursor(win)[2] 52 - local text = vim.api.nvim_buf_get_lines(buf, 0, -1, false)[1] 53 - vim.api.nvim_win_set_width(win, math.max(col, #text, opts.prompt and #opts.prompt or 0) + extrawidth) 56 + local maxlinewidth = vim.iter(vim.api.nvim_buf_get_lines(buf, 0, -1, false)):fold(1, function(max, l) 57 + local w = vim.api.nvim_strwidth(l) 58 + return w > max and w or max 59 + end) 60 + vim.api.nvim_win_set_width(win, maxlinewidth + 1) 54 61 end, 55 62 }) 56 63