Skip to content

Float view doen't autoclose on opening a file #2624

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

Closed
i-d-lytvynenko opened this issue Jan 12, 2024 · 5 comments · Fixed by #2627
Closed

Float view doen't autoclose on opening a file #2624

i-d-lytvynenko opened this issue Jan 12, 2024 · 5 comments · Fixed by #2627
Labels
awaiting feedback bug Something isn't working reproduced Issue confirmed

Comments

@i-d-lytvynenko
Copy link

Description

When hitting enter with the cursor on a line with some file name, the file opens in a new buffer, but the nvim-tree doesn't autoclose. Upon trying to move cursor in the nvim-tree window, a number of errors pop up. For some reason the problem does not occur with hijack_cursor = false. The last commit without this bug is 96a783f.

Neovim version

NVIM v0.9.2
Build type: RelWithDebInfo
LuaJIT 2.1.1694082368

Operating system and version

Windows 10

Windows variant

No response

nvim-tree version

b8c3a23

Clean room replication

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=F:/nvt-min/site]]
local package_root = "F:/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup {
    {
      "wbthomason/packer.nvim",
      "nvim-tree/nvim-tree.lua",
      "nvim-tree/nvim-web-devicons",
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  }
end
if vim.fn.isdirectory(install_path) == 0 then
  print "Installing nvim-tree 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 setup()]]
vim.opt.termguicolors = true
vim.opt.cursorline = true

_G.setup = function()
  require("nvim-tree").setup {
    hijack_cursor = true,
    view = {
      float = {
        enable = true,
      },
    },
  }
end

Steps to reproduce

  1. nvim -nu F:/nvt-min/nvt-min.lua
  2. :e .
  3. Position cursor on some file
  4. Hit Enter

Expected behavior

No response

Actual behavior

No response

@i-d-lytvynenko i-d-lytvynenko added the bug Something isn't working label Jan 12, 2024
@alex-courtis
Copy link
Member

Confirmed.

:e . is opening the tree in the current window and the issue can be reproduced.

Does not occur when opening the tree as a floating window.

Tree does not open when hijack_directories.enable = false

@alex-courtis alex-courtis added the reproduced Issue confirmed label Jan 13, 2024
@alex-courtis
Copy link
Member

Should :e . open a floating window when hijacking? Documentation is unclear however it intuitively should.

The error on open file should be fixed:

Error detected while processing CursorMoved Autocommands for "NvimTree_*":
Error executing lua callback: ...-dev/site/pack/packer/start/master/lua/nvim-tree/lib.lua:27: Invalid window id: 1000
stack traceback:
        [C]: in function 'nvim_win_get_cursor'
        ...-dev/site/pack/packer/start/master/lua/nvim-tree/lib.lua:27: in function 'get_node_at_cursor'
        .../nvt-dev/site/pack/packer/start/master/lua/nvim-tree.lua:121: in function 'place_cursor_on_node'
        .../nvt-dev/site/pack/packer/start/master/lua/nvim-tree.lua:238: in function <.../nvt-dev/site/pack/packer/start/master/lua/nvim-tree.lua:236>

@alex-courtis
Copy link
Member

alex-courtis commented Jan 13, 2024

view.get_winnr() is incorrect here. The window it returns 1000 no longer exists.

local winnr = view.get_winnr()

  1. view.get_winnr() is called twice however that's not an issue as the nil check is respected. It should be fixed.
  2. View.tabpages is a cache that gets stale

#2600 is not the cause, it simply surfaces the issue. /cc @geril2207

@alex-courtis
Copy link
Member

@i-d-lytvynenko I would be most grateful if you tested a fix #2627

cd /path/to/nvim-tree.lua
git pull
git checkout 2624-float-hijack-dir

When you're finished testing:

git checkout master

@i-d-lytvynenko
Copy link
Author

I confirm that this solves the problem.

emmanueltouzery added a commit to emmanueltouzery/nvim_config that referenced this issue Feb 28, 2024
meant to fix nvim-tree/nvim-tree.lua#2624
which I've been seeing from time to time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting feedback bug Something isn't working reproduced Issue confirmed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants