feat: add support for alternative ordering strategies #424
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.
Addresses #341.
Adds a default hotkey of
ctrl+o
to flip between A-Z sort order and numerical sort-by-size-desc on the right-side pane.The approach to implementing this feature was to find all of the places in code that enforce the order in which file-system nodes in the selected layer are displayed in the buffer window. Three methods were identified:
FileTree.StringBetween
,FileNode.VisitDepthParentFirst
andFileNode.VisitDepthChildFirst
. These locations were taking theFileNode
's propertyChildren map[string]*FileNode
and performingsort.Strings(keys)
in order to implement alphanumeric sorting.These locations have been unified with
OrderStrategy.orderKeys(map[string]*FileNode)
. A factory function,GetSortOrderStrategy
, tees up the corresponding ordering strategy given an enum, which it then propagates down to the three mentioned methods.Additionally, a
Size int64
field has been attached toFileNode
in order to cache information on directory/file size for use in the sort-by-size-desc strategy (with a simple extraction refactor of theFileNode.MetadataString
method.Happy New Year! 🥂