Closed iiian closed 1 year ago
Sorry! I didn't mean to close this, I renamed the master branch to main... I should have switched the target here first.
@iiian if you'd like to re-open the PR against main
I'd be happy to take a look
@iiian I recreated the master branch temporarily to get this in (I didn't think of that earlier). Just force pushed to rebase.
Rad!
FYI: This closes #89
Addresses https://github.com/wagoodman/dive/issues/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! 🥂