order commands alphabetically and preserve capitalization

This commit is contained in:
Mitchell Hashimoto
2025-04-21 17:13:00 -07:00
parent a732bb272d
commit 28404e946b
2 changed files with 13 additions and 1 deletions

View File

@ -197,7 +197,7 @@ fileprivate struct CommandRow: View {
var body: some View {
Button(action: action) {
HStack {
Text(option.title.lowercased())
Text(option.title)
Spacer()
if let shortcut = option.shortcut {
Text(shortcut)

View File

@ -38,9 +38,19 @@ pub const Command = struct {
.description = self.description,
};
}
/// Implements a comparison function for std.mem.sortUnstable
/// and similar functions. The sorting is defined by Ghostty
/// to be what we prefer. If a caller wants some other sorting,
/// they should do it themselves.
pub fn lessThan(_: void, lhs: Command, rhs: Command) bool {
return std.ascii.orderIgnoreCase(lhs.title, rhs.title) == .lt;
}
};
pub const defaults: []const Command = defaults: {
@setEvalBranchQuota(100_000);
var count: usize = 0;
for (@typeInfo(Action.Key).@"enum".fields) |field| {
const action = @field(Action.Key, field.name);
@ -58,6 +68,8 @@ pub const defaults: []const Command = defaults: {
}
}
std.mem.sortUnstable(Command, &result, {}, Command.lessThan);
assert(i == count);
const final = result;
break :defaults &final;