Skip to content

feat: add toggle support for sort boolean flags#3777

Open
alastairsounds wants to merge 1 commit intosxyazi:mainfrom
alastairsounds:feat/sort-toggle-flag
Open

feat: add toggle support for sort boolean flags#3777
alastairsounds wants to merge 1 commit intosxyazi:mainfrom
alastairsounds:feat/sort-toggle-flag

Conversation

@alastairsounds
Copy link

@alastairsounds alastairsounds commented Mar 18, 2026

Resolves #3157

Rationale

sort's boolean flags (--reverse, --dir-first, --translit) had no toggle support. This adds toggle as a valid value for each, mirroring the existing hidden toggle command.

sort --reverse=toggle
sort --dir-first=toggle
sort --translit=toggle

Changes

  • yazi-parser: Adds SortBoolState enum (none / on / off / toggle), replacing bool for the three flags. Modelled on HiddenOptState.
  • yazi-actor: Sort actor now calls .bool(old) so none preserves and toggle inverts current state.

@alastairsounds
Copy link
Author

Also wondering if I should implement this for the sensitive sort? But figure there's a little less utility in toggling case sensitivity 🤷🏻‍♂️

Comment on lines +78 to +80
Data::Boolean(true) => Ok(Self::On),
Data::Boolean(false) => Ok(Self::Off),
Data::String(s) => s.parse().map_err(Into::into),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This treats both boolean and string as SortBoolState, but it isn't clear whether SortBoolState should be serialized as a boolean or a string in Lua, which was in use by https://yazi-rs.github.io/docs/tips#folder-rules

@alastairsounds alastairsounds force-pushed the feat/sort-toggle-flag branch from 97d744c to d67dc26 Compare March 19, 2026 22:28
@alastairsounds
Copy link
Author

I see what you're saying. I think it should be serialized as a boolean and not handle strings. I don't see a scenario in which a user would need to set "toggle" via a Lua script. Since it's not really a "state" per-se, I've updated Sort::hook() to account for that. Now, when any of reverse, dir_first, or translit contains Toggle, it returns None to skip preflight entirely.

https://github.com/sxyazi/yazi/pull/3777/changes#diff-608cad97a235673889398f55a252b08703746ca6bce53ee32ebaabe78294f9cbR62-R70

With this revision, Lua shouldn't be able to see "toggle". Sorts that occur from plugins should work normally since they're only handling booleans and not strings.

Toggle being a CLI feature, not Lua, seems like a clean implementation. Or might there be a better route to follow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature to toggle "sort_dir_first" by shortcut key

2 participants