telescope.nvim icon indicating copy to clipboard operation
telescope.nvim copied to clipboard

Telescope triggering the `BufEnter` event thrice

Open vyfor opened this issue 1 year ago • 1 comments

Description

When switching files using Telescope, three (instead of two) events are being triggered: one for opening the Telescope's buffer, one for the old file and one for the new file. It seems that Telescope's prompt window closes prematurely before moving to the new file, which lets us see a glimpse of the old file's buffer for a short time, thus, triggering the autocommand. Is this intended?

Neovim version

NVIM v0.10.0-dev-2671+gdc110cba3
Build type: RelWithDebInfo
LuaJIT 2.1.1710088188

Operating system and version

Windows 10

Telescope version / branch / rev

master latest

checkhealth telescope

telescope: health#telescope#check

Checking for required plugins
- OK plenary installed.
- OK nvim-treesitter installed.

Checking external dependencies
- OK rg: found ripgrep 14.1.0 (rev e50df40a19)
- OK fd: found fd 9.0.0

===== Installed extensions =====

Steps to reproduce

  1. nvim -nu minimal.lua minimal.lua
  2. Clear logs: :mes clear
  3. :Telescope find_files
  4. Enter any other file from the list of files.
  5. View logs: :mes

Expected behavior

-- TelescopePrompt buffer
{
  buf = 10,
  event = "BufEnter",
  file = "",
  id = 58,
  match = ""
}
-- new file
{
  buf = 1,
  event = "BufEnter",
  file = "test.lua",
  id = 58,
  match = "test.lua"
}

Actual behavior

-- TelescopePrompt buffer
{
  buf = 10,
  event = "BufEnter",
  file = "",
  id = 58,
  match = ""
}
-- old file
{
  buf = 7,
  event = "BufEnter",
  file = "minimal.lua",
  id = 58,
  match = "minimal.lua"
}
-- new file
{
  buf = 1,
  event = "BufEnter",
  file = "test.lua",
  id = 58,
  match = "test.lua"
}

Minimal config

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
  {
    'nvim-telescope/telescope.nvim',
    branch = 'master',
    dependencies = {
      'nvim-lua/plenary.nvim',
    },
  },
}, {})

vim.api.nvim_create_autocmd('BufEnter', {
    callback = function(args)
      print(vim.inspect(args))
    end
})

vyfor avatar Apr 18 '24 16:04 vyfor

When an entry is selected, first telescope closes itself which triggers BufEnter on the "old" buffer and then we do something like :edit <new file>. So this is expected behavior. Not sure if there's a better way to open files that would avoid this. Open to ideas but otherwise I'd probably close this.

jamestrew avatar Apr 19 '24 03:04 jamestrew