Skip to content

feat: Sort nodes sensibly #334

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

Merged
merged 2 commits into from
Apr 22, 2021
Merged

Conversation

sindrets
Copy link
Contributor

Currently nodes don't always appear in conventional order in the file tree, and they are sometimes inserted in the wrong position when multiple nodes are added. This is a limitation of how insertion of new nodes is currently implemented. Further, symlinks are "sorted" as a separate group as opposed to how it is conventionally done: treating symlinks as the type of file/folder it points to. I.e a symlink pointing to a folder should be sorted alongside other folders.

Proposed solution: sort folders when new nodes are added. This is reasonable and does not have much notable impact on performance with my current implementation. Lua's table.sort is backed by an unstable quick sort algorithm, so I opted to instead implement a stable merge sort. Running some tests i measured a ~6.2ms runtime while sorting a folder with 5000 nodes.

Example behavior on current master while toggling dotfiles:

Peek.2021-04-21.23-13.mp4

.editorconfig and .luacheckrc are inserted at the wrong index and symlinks are sorted incorrectly.

Example behavior with this new implementation, while toggling dotfiles:

Peek.2021-04-21.23-11.mp4

All files retain their position in the tree after toggle and symlinks are sorted correctly.

Copy link
Member

@kyazdani42 kyazdani42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh but by default it should be sorted i think. anyway this looks better :)

@kyazdani42 kyazdani42 merged commit 027e523 into nvim-tree:master Apr 22, 2021
@sindrets
Copy link
Contributor Author

It's sorted almost correctly after the first populate. Except for symlinks, because you group directories, links and files and then add them in that order.

Almo7aya pushed a commit to Almo7aya/nvim-tree.lua that referenced this pull request Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants