-
Notifications
You must be signed in to change notification settings - Fork 506
Add the ability to sort by date or title #765
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
Open
cameron-michie
wants to merge
8
commits into
charmbracelet:master
Choose a base branch
from
cameron-michie:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
…update minihelp view
Member
andreynering
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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