diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2021-11-29 15:37:55 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-29 15:37:55 -0700 |
commit | fff8827908494a9c4bd5de10c409189929b3db56 (patch) | |
tree | 2eb6d3da035460f9d6254f5d89dadbd9a23ebad9 /runtime/lua/vim/lsp/util.lua | |
parent | b16b7021efe905a0e69731ffa13e6d187fdddb8d (diff) | |
download | rneovim-fff8827908494a9c4bd5de10c409189929b3db56.tar.gz rneovim-fff8827908494a9c4bd5de10c409189929b3db56.tar.bz2 rneovim-fff8827908494a9c4bd5de10c409189929b3db56.zip |
feat(lsp): add 'focus' option to open_floating_preview (#16465)
When the 'focusable' and 'focus_id' parameters are set,
`open_floating_preview` assumes that it should always move focus to an
existing floating window with the same 'focus_id'. However, there are
cases where we want to make a floating window focusable, but do not want
to focus it upon calling `open_floating_preview`. To distinguish these
cases, add a boolean parameter 'focus' that, when false, prevents
moving focus.
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 2879c4a565..ede7f15007 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -1318,6 +1318,9 @@ end --- - focus_id: (string) if a popup with this id is opened, then focus it --- - close_events: (table) list of events that closes the floating window --- - focusable: (boolean, default true) Make float focusable +--- - focus: (boolean, default true) If `true`, and if {focusable} +--- is also `true`, focus an existing floating window with the same +--- {focus_id} ---@returns bufnr,winnr buffer and window number of the newly created floating ---preview window function M.open_floating_preview(contents, syntax, opts) @@ -1329,12 +1332,13 @@ function M.open_floating_preview(contents, syntax, opts) opts = opts or {} opts.wrap = opts.wrap ~= false -- wrapping by default opts.stylize_markdown = opts.stylize_markdown ~= false + opts.focus = opts.focus ~= false opts.close_events = opts.close_events or {"CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre"} local bufnr = api.nvim_get_current_buf() -- check if this popup is focusable and we need to focus - if opts.focus_id and opts.focusable ~= false then + if opts.focus_id and opts.focusable ~= false and opts.focus then -- Go back to previous window if we are in a focusable one local current_winnr = api.nvim_get_current_win() if npcall(api.nvim_win_get_var, current_winnr, opts.focus_id) then |