From 28404e946b196f0d6e62ad3e602d2426b8fa0b24 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 21 Apr 2025 17:13:00 -0700 Subject: [PATCH] order commands alphabetically and preserve capitalization --- .../Features/Command Palette/CommandPalette.swift | 2 +- src/input/command.zig | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/macos/Sources/Features/Command Palette/CommandPalette.swift b/macos/Sources/Features/Command Palette/CommandPalette.swift index 09b216a39..943cc7846 100644 --- a/macos/Sources/Features/Command Palette/CommandPalette.swift +++ b/macos/Sources/Features/Command Palette/CommandPalette.swift @@ -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) diff --git a/src/input/command.zig b/src/input/command.zig index a36232d48..dcfcd0b39 100644 --- a/src/input/command.zig +++ b/src/input/command.zig @@ -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;