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

Retain Tree State on DirChanged #2488

Closed
asmodeus812 opened this issue Oct 21, 2023 · 1 comment · Fixed by #2527
Closed

Retain Tree State on DirChanged #2488

asmodeus812 opened this issue Oct 21, 2023 · 1 comment · Fixed by #2527
Labels
feature request QOL Quality Of Life Improvement

Comments

@asmodeus812
Copy link
Contributor

asmodeus812 commented Oct 21, 2023

Description

So here is an interesting problem, i have. I would usually open a new tree in a separate tab to explore or mutate a given working directory, say in the first vim tab i open a file and a normal side view of nvim tree for the same working directory of the file just opened, on the second tab i would open nvim tree only in the home directory (for example :e ~/). Now in the second tab i will expand the tree view in some folder from the home. I navigate back to the first tab, my configuration would trigger a DirChanged event, and the tree in the first tab would show correctly the view it did initially. However going back to the tab displaying the home folder, DirChanged will trigger again, and will be for the home directory, however the tree would auto-colapse, losing its expanded state it had before i left that home-dir tab, which is quite annoying to be frank, the directory for that tree technically did not change it is still /home, but i do know that nvim tree somehow reuses the same buffer and triggers redraws. Looking at the code i could see that if i disable opts.sync_root_with_cwd, can help, but breaks other things. This function M.change_dir(vim.loop.cwd()) in its implementation redraws the tree. So i assume it does not store the state, or knows that.

Neovim version

NVIM 0.9.4

Operating system and version

Fedora 38

Windows variant

No response

nvim-tree version

master

Clean room replication

on_attach = default_on_attach,
        auto_reload_on_write = false,
        sync_root_with_cwd = true,
        respect_buf_cwd = true,
        hijack_cursor = true,
        disable_netrw = true,
        hijack_netrw = true,
        hijack_unnamed_buffer_when_opening = true,
        hijack_directories = {
            enable = true,
            auto_open = true,
        },
        renderer = {
            full_name = true,
            indent_width = 1,
            root_folder_label = function(path)
                return vim.fn.fnamemodify(path, ":t")
            end,
            highlight_opened_files = "name",
        },
        modified = {
            enable = false,
            show_on_dirs = false,
            show_on_open_dirs = false,
        },
        diagnostics = {
            enable = false,
            show_on_dirs = false,
            show_on_open_dirs = false,
        },
        git = {
            enable = false,
            ignore = true,
        },
        actions = {
            change_dir = {
                enable = false,
                global = false,
            },
            open_file = {
                quit_on_open = true,
                resize_window = true,
            },
        },
        update_focused_file = {
            enable = false,
            update_root = false,
        },

Steps to reproduce

  1. open file in a random working directory
  2. open the tree for that directory using the api.tree.open
  3. open new tab in another directory, open the tree there
  4. start expanding, collapsing, navigating, mutating the tree view
  5. navigate to the first tab, tcd path-to-work-dir
  6. navigate back to the second, tcd path-to-second-dir

Expected behavior

The tree state should be remembered, when going back and forth between directories.

Actual behavior

The tree state is not remembered, rather going back to the same tree, the entire tree only shows the root folders of the directory for which it was opened.

@asmodeus812 asmodeus812 added the bug Something isn't working label Oct 21, 2023
@asmodeus812 asmodeus812 changed the title Tree redraws after DirChanged Tree state is not remembered on DirChanged Oct 21, 2023
@alex-courtis
Copy link
Member

That tabbed behaviour is not surprising. Tree state and (local) cwd state is not handled across tabs. We can follow it at the pinned issue #2255

Ignoring tabs, this is still an issue: the tree state is not remembered when :cd up and down diretories. Watchers are destroyed and recreated however git state cache is retained and used.

Let's change this to a feature request.

@alex-courtis alex-courtis added feature request QOL Quality Of Life Improvement and removed bug Something isn't working labels Oct 21, 2023
@alex-courtis alex-courtis changed the title Tree state is not remembered on DirChanged Retain Tree State on DirChanged Oct 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request QOL Quality Of Life Improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants