nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.59k stars 827 forks source link

Invalid enter mode if triggered from operator-pending mode #2404

Open backdround opened 1 year ago

backdround commented 1 year ago

Description

If telescope triggered from operator-pending mode then it starts in normal mode instead of insert mode.

Precautions: The bug doesn't work when cursor on first line and first column.

Neovim version

NVIM v0.8.3
Build type: Release
LuaJIT 2.1.0-beta3

Operating system and version

Archlinux

Telescope version / branch / rev

telescope master / a3f17d3 / (after 0.1.1)

checkhealth telescope

telescope: require("telescope.health").check()
========================================================================
## Checking for required plugins
  - OK: plenary installed.
  - WARNING: nvim-treesitter not found.

## Checking external dependencies
  - OK: rg: found ripgrep 13.0.0
  - OK: fd: found fd 8.6.0

## ===== Installed extensions =====

## Telescope Extension: `fzf`
  - OK: lib working as expected
  - OK: file_sorter correctly configured
  - OK: generic_sorter correctly configured

Steps to reproduce

Expected behavior

The current mode is insert in just opened telescope window

Actual behavior

The current mode is normal in just opened telescope window

Minimal config

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'
local function load_plugins()
  require('packer').startup {
    {
      'wbthomason/packer.nvim',
      {
        'nvim-telescope/telescope.nvim',
        requires = {
          'nvim-lua/plenary.nvim',
          { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' },
        },
      },
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. '/plugin/packer_compiled.lua',
      display = { non_interactive = true },
    },
  }
end
_G.load_config = function()
  require('telescope').setup()
  require('telescope').load_extension('fzf')
  -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
  local builtin = require("telescope.builtin")
  vim.keymap.set("o", "<M-m>", builtin.keymaps)
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing Telescope and dependencies.")
  vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }
end
load_plugins()
require('packer').sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
backdround commented 1 year ago

As i can say, if i wrap that line in vim.schedule, then all works fine: https://github.com/nvim-telescope/telescope.nvim/blob/a3f17d3baf70df58b9d3544ea30abe52a7a832c2/lua/telescope/pickers.lua#L442

Or If i wrap the mapping in vim.schedule, then all works fine too:

vim.keymap.set("o", "<M-m>", function()
  vim.schedule(builtin.keymaps)
end)

Could anyone give a guess why that is working that way?