Skip to content

After a rename, the node loses selection #2969

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
opsidjflksdf opened this issue Oct 26, 2024 · 4 comments · Fixed by #2974
Closed

After a rename, the node loses selection #2969

opsidjflksdf opened this issue Oct 26, 2024 · 4 comments · Fixed by #2974
Labels
bug Something isn't working OS Windows specific to windows PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated

Comments

@opsidjflksdf
Copy link
Contributor

opsidjflksdf commented Oct 26, 2024

Description

After you rename a (selected) node (file or folder) such that it changes its position in the current sorting order, the selection stays with the same number index within the tree (thus a different file/folder ending up being selected), instead of moving together with the node that was renamed.

In rename-file.lua, function fn(), there is code to update the selection:
find_file(utils.path_remove_trailing(new_file_path))
but the new_file_path variable only contains the filename or part of it (depending on the rename option chosen), rather than the entire path, even if relative.
rename() itself is called with
M.rename(node, prepend .. new_file_path .. append)
I tested and doing something like the following instead (calling find_file() with the same destination path that rename() was called with), fixes the issue (selection properly moves with the renamed node):

local new_full_file_path = prepend .. new_file_path .. append
M.rename(node, new_full_file_path )
[...]
find_file(utils.path_remove_trailing(new_full_file_path))

Could this be implemented? I wanted to run it by you rather than create a pull request in case there might be other considerations here. Thanks!

Neovim version

NVIM v0.10.2
Build type: Release
LuaJIT 2.1.1713484068
Run "nvim -V1 -v" for more info

Operating system and version

Windows 10

Windows variant

Native Windows

nvim-tree version

1.7.1 and latest master both have the issue

Clean room replication

nvim-tree with any file hierarchy

Steps to reproduce

In the nvim-tree window, set the selection on a node - file or folder, and then rename it with shortcut e or r. Selection doesn't move with the renamed item.

Expected behavior

Selection should move with the renamed item.

Actual behavior

Selection doesn't move with the renamed item.

@opsidjflksdf opsidjflksdf added the bug Something isn't working label Oct 26, 2024
@alex-courtis
Copy link
Member

alex-courtis commented Oct 26, 2024

Not able to replicate on linux/alacritty.

20241027_093230

20241027_093243

It sounds likely a windows issue, due to the path difficulties in that OS.

nvim-tree team have no access to nor expertise with windows. Please do create the PR.

Please ensure changes are behind the windows feature flags

@alex-courtis alex-courtis added the OS Windows specific to windows label Oct 26, 2024
@opsidjflksdf
Copy link
Contributor Author

opsidjflksdf commented Oct 26, 2024

Thanks for looking at it!
I can definitely create the PR guarded by OS flags.
Could you by any chance test (in Linux) with a file that's deeper in the hierarchy (rather than an immediate child of root), and possibly a file that has an extension, and rename with 'e' (basename). If, as it appears to be the case regardless of the OS, find_file() is called with just the new basename or filename, rather than the full path, even if find_file() somehow manages to find the file, you're bound to have at least some misbehavior where it will select a file under a different directory if you happen to have one similarly named in the hierarchy.

@alex-courtis
Copy link
Member

Great find!

The highlighting issues occur for r and e but not u or <c-R>

20241027_103731

This may not be OS specific.

@alex-courtis alex-courtis added the PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated label Oct 26, 2024
opsidjflksdf pushed a commit to opsidjflksdf/nvim-tree.lua that referenced this issue Oct 27, 2024
@opsidjflksdf
Copy link
Contributor Author

Ok, great, thanks for confirming!
I created the pull request with the code fix across all OS's, feel free to modify as fit.
Pull request:
#2974

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working OS Windows specific to windows PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants