feat: Sort nodes sensibly #334
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.