stevearc / dressing.nvim

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

Clicking outside telescope select window breaks all vim.ui.select actions #150

Open WizardStark opened 7 months ago

WizardStark commented 7 months ago

Describe the bug Opening a vim.ui.select window using the telescope backend and then clicking outside the popup breaks all subsequent vim.ui.select calls.

See https://github.com/mrjones2014/legendary.nvim/issues/447 for original discovery of this issue and additional context

System information

Run :checkhealth for more info

To Reproduce Steps to reproduce the behavior:

  1. vim.ui.select({ "apple", "banana" }, {}, function(item) vim.print(item) end) - mapped to <space>a for convenience
  2. triple click outside the window
  3. <space>a again, or call vim.ui.select

If possible, provide a minimal file that will trigger the issue (see tests/manual for examples of short ways to call vim.ui.*):

vim.g.mapleader = " "
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "--single-branch",
        "https://github.com/folke/lazy.nvim.git",
        lazypath,
    })
end
vim.opt.runtimepath:prepend(lazypath)

local plugins = {
    "folke/tokyonight.nvim",
    { "nvim-telescope/telescope.nvim", dependencies = { "nvim-lua/plenary.nvim" } },
    { "stevearc/dressing.nvim", opts = {} },
}

require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

vim.keymap.set("n", "<leader>a", function()
    vim.ui.select({ "apple", "banana" }, {}, function(item)
        vim.print(item)
    end)
end)

vim.opt.termguicolors = true
vim.cmd([[colorscheme tokyonight]])

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

emmanueltouzery commented 5 months ago

dressing needs to do something when the telescope picker is closed for any reason. I really tried to find a way to achieve that with telescope, and just couldn't. I have now opened them a PR to add the feature (I guess worst-case they'll say how to achieve that otherwise): https://github.com/nvim-telescope/telescope.nvim/pull/3182

With this in telescope, I confirmed that putting this in the telescope.lua file in dressing at line ~96 fixes the issue:

  vim.api.nvim_create_autocmd("User", {
    pattern = "TelescopePickerClose",
    callback = function(args)
      on_choice(nil, nil)
    end,
    once = true,
  })

I'll followup here when the telescope part of the issue is resolved one way or another.