Skip to content

Cursor does not focus on file created when creating file with nested directory #1716

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
GZLiew opened this issue Nov 2, 2022 · 9 comments · Fixed by #1722
Closed

Cursor does not focus on file created when creating file with nested directory #1716

GZLiew opened this issue Nov 2, 2022 · 9 comments · Fixed by #1722
Labels
bug Something isn't working reproduced Issue confirmed

Comments

@GZLiew
Copy link

GZLiew commented Nov 2, 2022

Description

Cursor does not focus on file created when creating file with nested directory

Neovim version

NVIM v0.7.2
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

Operating system and version

Linux-5.19.12

nvim-tree version

6ca6f99

Minimal config

require("nvim-tree").setup({
  update_focused_file = {
    enable = true
  },
  git = {
    ignore = false
  },
  actions = {
    open_file = {
      quit_on_open = true
    }
  },
  view = {
    width = 200,
    number = true,
    relativenumber = true,
    side = 'left',
    mappings = {
      list = {
        { key = "-", cb = tree_cb("close") },
        { key = { "<BS>", "<C-o>" }, action = "close_node" },
      }
    }
  }
})

Steps to reproduce

  1. nvim
  2. a
  3. somefolder/anotherfolder/a.c
  4. cursor focuses on the top of the tree

Expected behavior

Cursor should focus on the top of the tree

image

Actual behavior

Cursor should focus on the file created

image

@GZLiew GZLiew added the bug Something isn't working label Nov 2, 2022
@alex-courtis
Copy link
Member

Confirmed:

Occurs whenever a file is created in a directory specified via the input.

Open / closed state of the directories has no effect.

@alex-courtis alex-courtis added the reproduced Issue confirmed label Nov 4, 2022
@alex-courtis
Copy link
Member

Problem: the current (focused) node is synchronously refreshed, but not the node in which the file is created.

Solutions:

  1. open the tree to the folder containing the new file and focus it
  2. focus the file only if the folder is already open

1 would be best achieved via a find file action
2 would require refreshing the folder if it is open

@alex-courtis
Copy link
Member

alex-courtis commented Nov 5, 2022

Unrelated bug: FolderCreated event is dispatched with the created file's absolute path.

@alex-courtis
Copy link
Member

alex-courtis commented Nov 5, 2022

@GZLiew I will be grateful if you can test the fix #1722

cd /path/to/nvim-tree.lua
git pull
git checkout 1716-focus-file-dir-on-creation

@GZLiew
Copy link
Author

GZLiew commented Nov 5, 2022

hi @alex-courtis the fix works! Thanks for dropping a pr!

Tested with both single nest and multi nested directory

image

alex-courtis added a commit that referenced this issue Nov 5, 2022
…'t dispatch FolderCreated on file creation (#1722)

* fix(#1716): focus file/directory when created in a sub-directory, don't dispatch FolderCreated on file creation

* fix(#1716): focus file/directory when created in a sub-directory

* fix(#1716): focus file/directory when created in a sub-directory
@alex-courtis
Copy link
Member

Unfortunately I have had to back out this change as it breaks update_focused_file.enabled and renderer.group_empty

Attempting fix again.

@alex-courtis alex-courtis reopened this Nov 6, 2022
alex-courtis added a commit that referenced this issue Nov 6, 2022
…ory, don't dispatch FolderCreated on file creation (#1722)"

This reverts commit bdc4ec6.
@alex-courtis
Copy link
Member

Requires #1723

@alex-courtis
Copy link
Member

Requires #1731

alex-courtis added a commit that referenced this issue Nov 26, 2022
* fix(#1731): watcher refreshes node rather than the first node matching absolute path, profile refresh

* fix(#1731): reload explorer reloads closed folders

* fix(#1731): do not fire folder created event on file create

* fix(#1731): reload profile absolute path, not link to

* fix(#1731): find-file locks/profiles on real path, reloads when watchers disabled

* Revert "fix(#1731): reload explorer reloads closed folders"

This reverts commit 5dfd8bd.

* fix(#1731): tidy watch reload

* fix(#1731): move refresh_node from watch to reload

* fix(#1731): find-file reloads all nodes for the containing directory

* fix(#1731): create-file refreshes synchronously

* fix(#1731): remove unused watch node

* fix(#1731): find-file refreshes root

* fix(#1716): create-file invokes find-file

* fix(#1731): refresh path walks down the tree to the targedt
@alex-courtis
Copy link
Member

Should be resolved by #1757

Please let me know if there are any issues.

emmanueltouzery added a commit to emmanueltouzery/nvim_config that referenced this issue Nov 6, 2023
decided to enable the nvim-tree feature to group folders containing only
a subfolder together, to make handier to work in java projects. That
made me hit nvim-tree/nvim-tree.lua#1716 in my
1-year-old version of nvim-tree. Tried to upgrade to the latest
nvim-tree and put the config changes that enable that, since nvim-tree
changed its setup, but had to revert due to
http://github.com/stevearc/stickybuf.nvim/issues/24

So in the end keep the code to migrate to the latest nvim-tree, but
commented, and do only a slight nvim-tree upgrade to fix the folder
grouping issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproduced Issue confirmed
Projects
None yet
2 participants