Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on_choice is not triggered when closing the window #32

Closed
przepompownia opened this issue Nov 21, 2023 · 6 comments · Fixed by #34
Closed

on_choice is not triggered when closing the window #32

przepompownia opened this issue Nov 21, 2023 · 6 comments · Fixed by #34

Comments

@przepompownia
Copy link

Minimal init.lua:

local thisInitFile = debug.getinfo(1).source:match('@?(.*)')
local configDir = vim.fs.dirname(thisInitFile)

vim.env['XDG_CONFIG_HOME'] = configDir
vim.env['XDG_DATA_HOME'] = vim.fs.joinpath(configDir, '.xdg/data')
vim.env['XDG_STATE_HOME'] = vim.fs.joinpath(configDir, '.xdg/state')
vim.env['XDG_CACHE_HOME'] = vim.fs.joinpath(configDir, '.xdg/cache')
local stdPathConfig = vim.fn.stdpath('config')

vim.opt.runtimepath:prepend(stdPathConfig)
vim.opt.packpath:prepend(stdPathConfig)

local function gitClone(url, installPath, branch)
  if vim.fn.isdirectory(installPath) ~= 0 then
    return
  end

  local command = {'git', 'clone', '--depth=1', '--', url, installPath}
  if branch then
    table.insert(command, 3, '--branch')
    table.insert(command, 4, branch)
  end
  local sysObj = vim.system(command, {}):wait()
  if sysObj.code ~= 0 then
    error(sysObj.stderr)
  end
  vim.notify(sysObj.stdout)
  vim.notify(sysObj.stderr, vim.log.levels.WARN)
end

local pluginsPath = 'plugins'
vim.fn.mkdir(pluginsPath, 'p')
pluginsPath = vim.uv.fs_realpath(pluginsPath)

local plugins = {
  ['plenary'] = {url = 'https://github.com/nvim-lua/plenary.nvim'},
  ['telescope'] = {url = 'https://github.com/nvim-telescope/telescope.nvim'},
  ['telescope-ui-select'] = {url = 'https://github.com/nvim-telescope/telescope-ui-select.nvim'}
}

for name, repo in pairs(plugins) do
  local installPath = vim.fs.joinpath(pluginsPath, name)
  gitClone(repo.url, installPath, repo.branch)
  vim.opt.runtimepath:append(installPath)
end

local function init()
  require('telescope').setup {
    extensions = {
      ['ui-select'] = {
        require('telescope.themes').get_dropdown {
        }
      }
    },
  }

  require('telescope').load_extension('ui-select')
  vim.ui.select({'x'}, {}, function (x, i)
    vim.notify('After select')
    vim.print(x, i)
  end)
end

vim.api.nvim_create_autocmd('UIEnter', {
  once = true,
  callback = init,
})

After close by <Esc> nothing happens in opposite to expected calling on_choice callback with (nil, nil) like in https://github.com/neovim/neovim/blob/488038580934f301c1528a14548ec0cabd16c2cd/runtime/lua/vim/ui.lua#L52.

@Conni2461
Copy link
Member

good catch, #34 should fix your issue. can you confirm? after that i'll merge

@przepompownia
Copy link
Author

With #34 on_choice is called with nil as expected, thanks!

Independently, please notice that to cancel we need to exit Insert mode first and then close the dialog.

Conni2461 added a commit that referenced this issue Nov 24, 2023
@Conni2461
Copy link
Member

Independently, please notice that to cancel we need to exit Insert mode first and then close the dialog.

i dont know what that means?

Conni2461 added a commit that referenced this issue Nov 24, 2023
@przepompownia
Copy link
Author

In short, we need to press double Esc to cancel.

@Conni2461
Copy link
Member

Conni2461 commented Nov 24, 2023

thats a telescope configure thing, isnt it. like the default telescope esc action does not close, it switches modes. you can override this,s ee: https://github.com/nvim-telescope/telescope.nvim/wiki/Configuration-Recipes#mapping-esc-to-quit-in-insert-mode

this is also documented here: https://github.com/nvim-telescope/telescope.nvim?tab=readme-ov-file#default-mappings

does this answer your question?

@przepompownia
Copy link
Author

Ah, ok. I have this mapping for years but my observation came from the minimal repro. I'm sorry for the unnecessary confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants