Skip to content

Opening a tree in a new tab messes up local statusline settings #2768

Closed
@mkalinski

Description

@mkalinski

Description

According to this comment, I'm using nvim-tree's event system to set local statusline for the tree's window.

This works fine, except for a weird case when nvim-tree is opened in a new tab, and then opening a file from the tree causes the local statusline to be removed from nvim-tree window and set in the newly opened file window.

It's a bit hard to explain, so please see the attached screenshots below.

Neovim version

NVIM v0.9.5
Build type: RelWithDebInfo
LuaJIT 2.1.1707061634

Operating system and version

Fedora 39

Windows variant

No response

nvim-tree version

64f61e4

Clean room replication

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

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvt-min/site]]
local package_root = "/tmp/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",
      -- 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
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

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
  require("nvim-tree").setup {}

  vim.opt.statusline = 'global'

  local events = require'nvim-tree.api'.events

  events.subscribe(events.Event.TreeOpen, function()
    vim.opt_local.statusline = 'tree'
  end)
end

-- UNCOMMENT this block for diagnostics issues, substituting pattern and cmd as appropriate.
-- Requires diagnostics.enable = true in setup.
--[[
vim.api.nvim_create_autocmd("FileType", {
  pattern = "lua",
  callback = function()
    vim.lsp.start { cmd = { "lua-language-server" } }
  end,
})
]]

Steps to reproduce

  1. nvim -nu /tmp/nvt-min.lua
  2. :NvimTreeOpen
  3. :tabedit .
  4. <Enter> to open any file visible in the tree opened in the new tab

Expected behavior

The same behaviour as in the first tab: statusline is set locally for the tree is in the tree's window, and global statusline is set for file opened from the tree.

image

Actual behavior

In the second tab, after the file is opened from the tree, the local statusline from tree is set for the opened file, and global statusline gets reset for the tree.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions