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

Telescope triggering the BufEnter event thrice #3057

Closed
vyfor opened this issue Apr 18, 2024 · 1 comment
Closed

Telescope triggering the BufEnter event thrice #3057

vyfor opened this issue Apr 18, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@vyfor
Copy link

vyfor commented Apr 18, 2024

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 vyfor added the bug Something isn't working label Apr 18, 2024
@vyfor vyfor changed the title Telescope triggering the BufEnter event twice Telescope triggering the BufEnter event thrice Apr 18, 2024
@jamestrew
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants