Add the ability to sort by date or title#765
Open
cameron-michie wants to merge 8 commits intocharmbracelet:masterfrom
Open
Add the ability to sort by date or title#765cameron-michie wants to merge 8 commits intocharmbracelet:masterfrom
cameron-michie wants to merge 8 commits intocharmbracelet:masterfrom
Conversation
…update minihelp view
Member
andreynering
left a comment
There was a problem hiding this comment.
Hi @cameron-michie,
I made a small suggestion.
Comment on lines
+16
to
+38
| func sortMarkdowns(mds []*markdown, sortByDate bool, ascending sortOrder) { | ||
| if sortByDate { | ||
| if ascending { | ||
| slices.SortStableFunc(mds, func(a, b *markdown) int { | ||
| return compareTime(a.Modtime, b.Modtime) | ||
| }) | ||
| } else { | ||
| slices.SortStableFunc(mds, func(a, b *markdown) int { | ||
| return -compareTime(a.Modtime, b.Modtime) | ||
| }) | ||
| } | ||
| } else { | ||
| if ascending { | ||
| slices.SortStableFunc(mds, func(a, b *markdown) int { | ||
| return cmp.Compare(a.Note, b.Note) | ||
| }) | ||
| } else { | ||
| slices.SortStableFunc(mds, func(a, b *markdown) int { | ||
| return -cmp.Compare(a.Note, b.Note) | ||
| }) | ||
| } | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
Some suggestions:
- Instead of repeating
slices.SortStableFunc4 times, assigning functions and calling in the end (make it a one-liner). - Change
if/elseinto aswitchcase to reduce block inside block.
Suggested change
| func sortMarkdowns(mds []*markdown, sortByDate bool, ascending sortOrder) { | |
| if sortByDate { | |
| if ascending { | |
| slices.SortStableFunc(mds, func(a, b *markdown) int { | |
| return compareTime(a.Modtime, b.Modtime) | |
| }) | |
| } else { | |
| slices.SortStableFunc(mds, func(a, b *markdown) int { | |
| return -compareTime(a.Modtime, b.Modtime) | |
| }) | |
| } | |
| } else { | |
| if ascending { | |
| slices.SortStableFunc(mds, func(a, b *markdown) int { | |
| return cmp.Compare(a.Note, b.Note) | |
| }) | |
| } else { | |
| slices.SortStableFunc(mds, func(a, b *markdown) int { | |
| return -cmp.Compare(a.Note, b.Note) | |
| }) | |
| } | |
| } | |
| } | |
| func sortMarkdowns(mds []*markdown, sortByDate bool, order sortOrder) { | |
| var fn func(a, b *markdown) int | |
| switch { | |
| case sortByDate && order == ascending: | |
| fn = func(a, b *markdown) int { return compareTime(a.Modtime, b.Modtime) } | |
| case sortByDate && order == descending: | |
| fn = func(a, b *markdown) int { return -compareTime(a.Modtime, b.Modtime) } | |
| case !sortByDate && order == ascending: | |
| fn = func(a, b *markdown) int { return cmp.Compare(a.Note, b.Note) } | |
| case !sortByDate && order == descending: | |
| fn = func(a, b *markdown) int { return -cmp.Compare(a.Note, b.Note) } | |
| } | |
| slices.SortStableFunc(mds, fn) | |
| } |
gustavosbarreto
pushed a commit
to drera-labs/glow
that referenced
this pull request
Jun 9, 2025
…charmbracelet#765) Bumps [github.com/charmbracelet/x/ansi](https://github.com/charmbracelet/x) from 0.5.2 to 0.6.0. - [Release notes](https://github.com/charmbracelet/x/releases) - [Commits](charmbracelet/x@ansi/v0.5.2...ansi/v0.6.0) --- updated-dependencies: - dependency-name: github.com/charmbracelet/x/ansi dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Describe your changes
Adds the ability to press 'y' to toggle the sort by date. Also adds the ability to press 't' to switch back to sorting by title, and can sort reverse alphabetically by pressing repeatedly. These options now appear in the fullView after pressing '?'.
Related issue/discussion: #228