stevearc / dressing.nvim

Neovim plugin to improve the default vim.ui interfaces
MIT License
1.7k stars 32 forks source link

Using the FZF UIs removes the current visual selection #74

Closed Penaz91 closed 1 year ago

Penaz91 commented 1 year ago

Describe the bug While trying to make a quick menu for nvim's LSP, I ran into the following issue: if you select some text and open vim.ui.* using dressing, the visual selection is lost.

System information

require("dressing").setup{}

To Reproduce Steps to reproduce the behavior:

  1. Open a file containing some text
  2. Select some text in visual mode (I usually use line-selection out of habit)
  3. Trigger vim.ui in any way, the most "minimal code" i can provide is the following command
:'<,'>lua vim.ui.input({}, function(item) print(item) end)  
  1. As soon as the ui pops up, the visual selection is lost.

Additional context I tried disabling the plugin and using the native vim.ui.select and the selection is kept.

I'm using the fzf backend with ibhagwan/fzf-lua.

I'm available for any question!

stevearc commented 1 year ago

Unfortunately, this is just how vim works. When you open fzf, that puts your cursor inside of a terminal window in insert mode (technically, in "terminal" mode). There's no way to also have your cursor be in the original window with a visual mode selection. You could potentially save the current visual selection before calling vim.ui.select, or you could restore the selection after vim.ui.select completes with vim.cmd.normal({args = {"gv"}}), but there's no way to preserve that visual selection while doing anything else with your cursor.

Penaz91 commented 1 year ago

I understand. I thought it was an issue because the normal vim.ui seemed to keep the visual selection "active in background" (although probably only visually) and restore it after the task was completed.

Thank you for the clarification, feel free to close this ticket!

stevearc commented 1 year ago

The built-in vim.ui methods use synchronous input functions that block Neovim. All other rendering is paused while waiting for input() or inputlist(). This can be helpful if you really do need the user to input something before you continue execution, but you'll want to manually use vim.fn.inputlist if that's what you're after, since vim.ui.select is designed to work async.