Commit 6411be88fd

6411be88fddc41b6ef7a64115dd2338a3faf3eff

parent: 8cc58a48ee

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-22 20:55 UTC

Mac echo area: keep errors, list recent messages, selectable choices

A message stays until the next key or click, as in Emacs, and Messages (View ▸ Messages) lists the last 100. A prompt's choices are no longer cut at twelve: ↑/↓ and C-p/C-n move a highlight that Tab completes and Return answers, and a count shows the highlighted choice and the number of matches. The prompt is its own view, PromptView, for other windows to host.

Ref #222

Layout: unified · split

Changed files (8)
Sources/OrgApp/CommandTitles.swift +1 · view
@@ -166,6 +166,7 @@ enum CommandTitles {
166166 String(localized: "Lower Priority", comment: "Command title"),
167167 String(localized: "Mark Subtree", comment: "Command title"),
168168 String(localized: "Mark as Default Clock Task", comment: "Command title"),
169 String(localized: "Messages", comment: "Command title"),
169170 String(localized: "Move Item Down", comment: "Command title"),
170171 String(localized: "Move Item Up", comment: "Command title"),
171172 String(localized: "Move Subtree Down", comment: "Command title"),
Sources/OrgEditorAppKit/EditorCommands.swift +1 · view
@@ -98,6 +98,7 @@ public enum EditorCommands {
9898 EditorCommand(id: "app.palette", title: "Command Palette…", action: .app),
9999 EditorCommand(id: "app.search", title: "Search Notes", action: .app),
100100 EditorCommand(id: "app.reload-keymap", title: "Reload Keymap", action: .app),
101 EditorCommand(id: "app.messages", title: "Messages", action: .app),
101102 EditorCommand(id: "app.refile", title: "Refile…", action: .app),
102103 EditorCommand(id: "app.refile.copy", title: "Copy to Refile Target…", action: .app),
103104 EditorCommand(id: "app.refile.goto", title: "Go to Refile Target…", action: .app),
Sources/Orgstar/ContentView.swift +2 · view
@@ -422,6 +422,7 @@ struct ContentView: View {
422422 }
423423 }
424424 }
425 .sheet(isPresented: $commands.showingMessages) { MessagesView(messages: commands.messages) }
425426 .onChange(of: commands.showingPalette) { _, showing in if showing { sheetTarget = session.focused } }
426427 .onChange(of: commands.showingQuickOpen) { _, showing in if showing { sheetTarget = session.focused } }
427428 .onChange(of: session.conflict) { _, conflict in
@@ -1327,6 +1328,7 @@ struct ContentView: View {
13271328 case "app.edit-config": commands.jump(path: UserConfig.configFile.path, offset: 0)
13281329 case "app.quick-open": commands.showingQuickOpen = true
13291330 case "app.palette": commands.showingPalette = true
1331 case "app.messages": commands.showingMessages = true
13301332 case "app.search": commands.focusSearch = true
13311333 case "app.reload-keymap":
13321334 loadKeymap()
Sources/Orgstar/Keys.swift +140 −71 · view
@@ -9,15 +9,13 @@ struct KeyHint: Hashable {
99 let title: String
1010}
1111
12/// The minibuffer line: a pending prefix, or the last message for a few seconds. After a
13/// short pause on a prefix, the keys that can follow it.
12/// The minibuffer line: a question, a pending prefix, or the last message until the next key
13/// or click. After a short pause on a prefix, the keys that can follow it.
1414struct EchoArea: View {
1515 let commands: AppCommands
1616 @Environment(\.orgTheme) private var theme
1717 @Environment(\.colorScheme) private var colorScheme
1818 @State private var showingHints = false
19 @State private var answer = ""
20 @FocusState private var answerFocused: Bool
2119
2220 var body: some View {
2321 VStack(alignment: .leading, spacing: 0) {
@@ -34,71 +32,9 @@ struct EchoArea: View {
3432 }
3533 .padding(10)
3634 }
37 if let request = commands.prompt, let fast = request.prompt.fast {
38 Divider()
39 FastSelectionView(selection: fast, message: request.prompt.message) { commands.answer($0) }
35 if let request = commands.prompt {
36 PromptView(commands: commands, request: request)
4037 .id(request.id)
41 } else if let request = commands.prompt {
42 if !request.prompt.choices.isEmpty {
43 Divider()
44 let matches = filteredChoices(request.prompt.choices)
45 ScrollView {
46 VStack(alignment: .leading, spacing: 2) {
47 ForEach(matches.prefix(12), id: \.self) { choice in
48 Button(choice) {
49 if request.prompt.completionSeparator != nil { complete(choice, request.prompt) } else { commands.answer(choice) }
50 }
51 .buttonStyle(.plain)
52 .font(.system(.callout, design: .monospaced))
53 .foregroundStyle(choice == matches.first ? .primary : .secondary)
54 }
55 }
56 .frame(maxWidth: .infinity, alignment: .leading)
57 .padding(10)
58 }
59 .frame(maxHeight: 200)
60 }
61 if let read = request.prompt.date {
62 Divider()
63 DatePickerView(answer: answer, read: read) { commands.answer($0) }
64 }
65 Divider()
66 HStack(spacing: 6) {
67 Text(request.prompt.message).font(.system(.callout, design: .monospaced)).foregroundStyle(.secondary)
68 .lineLimit(1)
69 .truncationMode(.middle)
70 TextField("", text: $answer)
71 .frame(minWidth: 240)
72 .textFieldStyle(.plain)
73 .font(.system(.callout, design: .monospaced))
74 .focused($answerFocused)
75 .onSubmit {
76 if request.prompt.choices.isEmpty || !request.prompt.requireMatch {
77 commands.answer(answer)
78 } else if let first = filteredChoices(request.prompt.choices).first {
79 commands.answer(first)
80 }
81 }
82 .onKeyPress(.tab) {
83 guard let first = filteredChoices(request.prompt.choices).first else { return .ignored }
84 complete(first, request.prompt)
85 return .handled
86 }
87 .onKeyPress(keys: [.leftArrow, .rightArrow, .upArrow, .downArrow]) { press in
88 guard let read = request.prompt.date, press.modifiers == .shift else { return .ignored }
89 let days = [KeyEquivalent.leftArrow: -1, .rightArrow: 1, .upArrow: -7, .downArrow: 7][press.key]!
90 answer = DatePickerView.shifted(answer, read, by: days)
91 return .handled
92 }
93 .onExitCommand { commands.answer(nil) }
94 }
95 .padding(.horizontal, 10)
96 .padding(.vertical, 4)
97 .onAppear {
98 answer = request.prompt.initial
99 answerFocused = true
100 }
101 .id(request.id)
10238 } else if let text = commands.pendingKeys.map({ $0 + "-" }) ?? commands.message {
10339 Text(text)
10440 .font(.system(.callout, design: .monospaced))
@@ -177,7 +113,108 @@ struct StateTag: View {
177113 }
178114}
179115
180extension EchoArea {
116/// A question a command asks: fast selection, or a text field with its choices, filtered as
117/// it is typed, and a calendar for dates. Any window with an echo area can show it.
118struct PromptView: View {
119 let commands: AppCommands
120 let request: PromptRequest
121 @State private var answer = ""
122 @FocusState private var answerFocused: Bool
123 /// The highlighted choice, moved by ↑/↓ or C-p/C-n.
124 @State private var selected = 0
125 /// The highlight was moved, so Return answers with it even where any text is accepted.
126 @State private var moved = false
127
128 private var prompt: Prompt { request.prompt }
129
130 var body: some View {
131 if let fast = prompt.fast {
132 Divider()
133 FastSelectionView(selection: fast, message: prompt.message) { commands.answer($0) }
134 } else {
135 let matches = filteredChoices(prompt.choices)
136 let current = min(selected, matches.count - 1)
137 if !prompt.choices.isEmpty {
138 Divider()
139 ScrollViewReader { proxy in
140 ScrollView {
141 LazyVStack(alignment: .leading, spacing: 2) {
142 ForEach(matches.indices, id: \.self) { index in
143 let choice = matches[index]
144 Button {
145 if prompt.completionSeparator != nil { complete(choice) } else { commands.answer(choice) }
146 } label: {
147 Text(choice)
148 .frame(maxWidth: .infinity, alignment: .leading)
149 .padding(.horizontal, 4)
150 .background(index == current ? Color.accentColor.opacity(0.25) : .clear, in: RoundedRectangle(cornerRadius: 3))
151 .contentShape(Rectangle())
152 }
153 .buttonStyle(.plain)
154 .font(.system(.callout, design: .monospaced))
155 .accessibilityAddTraits(index == current ? .isSelected : [])
156 }
157 }
158 .padding(10)
159 }
160 .frame(maxHeight: 200)
161 .onChange(of: current) { if current >= 0 { proxy.scrollTo(current) } }
162 }
163 }
164 if let read = prompt.date {
165 Divider()
166 DatePickerView(answer: answer, read: read) { commands.answer($0) }
167 }
168 Divider()
169 HStack(spacing: 6) {
170 Text(prompt.message).font(.system(.callout, design: .monospaced)).foregroundStyle(.secondary)
171 .lineLimit(1)
172 .truncationMode(.middle)
173 TextField("", text: $answer)
174 .frame(minWidth: 240)
175 .textFieldStyle(.plain)
176 .font(.system(.callout, design: .monospaced))
177 .focused($answerFocused)
178 .onSubmit {
179 if current >= 0, moved || prompt.requireMatch {
180 commands.answer(matches[current])
181 } else if prompt.choices.isEmpty || !prompt.requireMatch {
182 commands.answer(answer)
183 }
184 }
185 .onKeyPress(.tab) {
186 guard current >= 0 else { return .ignored }
187 complete(matches[current])
188 return .handled
189 }
190 .movesSelection(Binding(get: { selected }, set: { selected = $0; moved = true }), current: current, count: matches.count)
191 .onKeyPress(keys: [.leftArrow, .rightArrow, .upArrow, .downArrow]) { press in
192 guard let read = prompt.date, press.modifiers == .shift else { return .ignored }
193 let days = [KeyEquivalent.leftArrow: -1, .rightArrow: 1, .upArrow: -7, .downArrow: 7][press.key]!
194 answer = DatePickerView.shifted(answer, read, by: days)
195 return .handled
196 }
197 .onExitCommand { commands.answer(nil) }
198 .onChange(of: answer) {
199 selected = 0
200 moved = false
201 }
202 if !prompt.choices.isEmpty {
203 Text(verbatim: "\(max(current + 1, 0))/\(matches.count)")
204 .font(.system(.callout, design: .monospaced))
205 .foregroundStyle(.secondary)
206 .accessibilityLabel("Choice \(max(current + 1, 0)) of \(matches.count)")
207 }
208 }
209 .padding(.horizontal, 10)
210 .padding(.vertical, 4)
211 .onAppear {
212 answer = prompt.initial
213 answerFocused = true
214 }
215 }
216 }
217
181218 /// What completion matches: the text after the last separator, or all of it.
182219 private func completing(_ separator: Character?) -> Substring {
183220 guard let separator, let last = answer.lastIndex(of: separator) else { return answer[...] }
@@ -185,7 +222,7 @@ extension EchoArea {
185222 }
186223
187224 /// Puts `choice` in place of what's being completed; with a separator, adds one after it.
188 func complete(_ choice: String, _ prompt: Prompt) {
225 func complete(_ choice: String) {
189226 guard let separator = prompt.completionSeparator else {
190227 answer = choice
191228 return
@@ -196,7 +233,7 @@ extension EchoArea {
196233
197234 /// Choices matching what's typed, best first.
198235 func filteredChoices(_ choices: [String]) -> [String] {
199 let typed = String(completing(commands.prompt?.prompt.completionSeparator))
236 let typed = String(completing(prompt.completionSeparator))
200237 guard !typed.isEmpty else { return choices }
201238 return choices.compactMap { choice in FuzzyMatch.score(typed, choice).map { (choice, $0) } }
202239 .sorted { $0.1 > $1.1 }
@@ -204,6 +241,38 @@ extension EchoArea {
204241 }
205242}
206243
244/// Messages: the echo area's recent messages, newest last (`view-echo-area-messages`).
245struct MessagesView: View {
246 let messages: [String]
247 @Environment(\.dismiss) private var dismiss
248
249 var body: some View {
250 VStack(alignment: .leading, spacing: 0) {
251 Text("Messages").font(.headline).padding(12)
252 Divider()
253 if messages.isEmpty {
254 ContentUnavailableView("No messages", systemImage: "text.bubble")
255 } else {
256 ScrollView {
257 Text(messages.joined(separator: "\n"))
258 .font(.system(.callout, design: .monospaced))
259 .textSelection(.enabled)
260 .frame(maxWidth: .infinity, alignment: .leading)
261 .padding(12)
262 }
263 .defaultScrollAnchor(.bottom)
264 }
265 Divider()
266 HStack {
267 Spacer()
268 Button("Done") { dismiss() }.keyboardShortcut(.defaultAction)
269 }
270 .padding(12)
271 }
272 .frame(width: 560, height: 360)
273 }
274}
275
207276/// Commands this build leaves out of the palette and menus; their keys say so when pressed.
208277#if APPSTORE
209278let hiddenCommandIDs = AppStoreCommands.hidden
Sources/Orgstar/OrgstarApp.swift +19 −7 · view
@@ -23,6 +23,7 @@ final class AppCommands {
2323 var focusSearch = false
2424 var showingConflict = false
2525 var showingPalette = false
26 var showingMessages = false
2627 /// A location another window asked the main window to show.
2728 private(set) var jumpRequest: (path: String, offset: Int, id: Int)?
2829 private var jumpID = 0
@@ -74,9 +75,12 @@ final class AppCommands {
7475 var keyHints: [KeyHint] = []
7576 /// A question a command asked, answered in the echo area.
7677 private(set) var prompt: PromptRequest?
77 /// The last message from a command or the keymap, cleared after a few seconds.
78 /// The last message from a command or the keymap, kept until the next key or click, as
79 /// Emacs keeps it.
7880 private(set) var message: String?
79 private var messageID = 0
81 /// Recent messages, oldest first, for Messages.
82 private(set) var messages: [String] = []
83 @ObservationIgnored private var inputMonitor: Any?
8084
8185 func ask(_ prompt: Prompt, reply: @escaping (String?) -> Void) {
8286 self.prompt = PromptRequest(prompt: prompt, reply: reply)
@@ -169,13 +173,19 @@ final class AppCommands {
169173 }
170174
171175 func show(_ text: String) {
172 messageID += 1
173 let id = messageID
174176 message = text
177 messages.append(text)
178 if messages.count > 100 { messages.removeFirst(messages.count - 100) }
175179 AccessibilityNotification.Announcement(text).post()
176 Task {
177 try? await Task.sleep(for: .seconds(4))
178 if messageID == id { message = nil }
180 // A local monitor sees an event before it is handled, so a message the key or click
181 // itself shows is set after this clears the last one.
182 if inputMonitor == nil {
183 inputMonitor = NSEvent.addLocalMonitorForEvents(matching: [.keyDown, .leftMouseDown, .rightMouseDown]) { [weak self] event in
184 MainActor.assumeIsolated {
185 if self?.message != nil { self?.message = nil }
186 }
187 return event
188 }
179189 }
180190 }
181191}
@@ -539,6 +549,8 @@ struct OrgstarApp: App {
539549 Button("Turn Auto Fill On or Off") { commands.run("editor.toggle-auto-fill") }
540550 Button("Check Spelling While Typing") { commands.editor?.run("editor.toggle-spell-check") }
541551 .disabled(commands.editor == nil)
552 Divider()
553 Button("Messages") { commands.run("app.messages") }
542554 }
543555 CommandGroup(after: .pasteboard) {
544556 Divider()
docs/manual/guide/02-the-editor.org +2 −2 · view
@@ -212,7 +212,7 @@ The running clock is covered in [[file:06-dates-and-clocking.org][Dates and cloc
212212
213213The line under the modeline is the echo area, as Emacs's minibuffer. It shows:
214214
215- *Messages* from commands, such as =Stored: …= or =Not an org file=. A message stays for 4 seconds.
215- *Messages* from commands, such as =Stored: …= or =Not an org file=. A message stays until the next key or click. View ▸ Messages lists the last 100.
216216- *A pending key prefix*. After =C-c= it shows =C-c-=. If you pause for about 0.6 seconds, a grid of the keys that can follow appears, each with the command it would run at the caret, or =+prefix= for a further prefix, as =which-key= shows them. =C-g= cancels the prefix and shows =Quit=. A sequence that isn't bound shows, for example, =C-c z is undefined=, and does nothing; in the Doom preset this includes sequences after =SPC=.
217217- *Prompts*, when a command asks a question.
218218
@@ -221,7 +221,7 @@ The line under the modeline is the echo area, as Emacs's minibuffer. It shows:
221221A prompt shows its question and a text field, which takes the keyboard.
222222
223223- Type an answer and press =Return=.
224- When the prompt has choices (buffers, refile targets, tags), up to 12 of them list above the field, filtered as you type: characters match in order, and the best match is listed first. =Tab= completes the field to the first match. =Return= accepts the first match when the prompt requires one of its choices, and the typed text otherwise. Clicking a choice accepts it.
224- When the prompt has choices (buffers, refile targets, tags), they list above the field, filtered as you type: characters match in order, and the best match is listed first and highlighted. The count at the right of the field shows the highlighted choice and the number of matches. =↑= and =↓= (or =C-p= and =C-n=) move the highlight, and =Tab= completes the field to the highlighted choice. =Return= accepts the highlighted choice when the prompt requires one of its choices or the highlight was moved, and the typed text otherwise. Clicking a choice accepts it.
225225- Prompts that take several values, such as tags separated by colons, complete only the part after the last separator.
226226- =Escape= cancels the prompt; the command reports =Quit=.
227227
docs/manual/guide/03-keys.org +4 −3 · view
@@ -77,12 +77,12 @@ A key bound by itself cannot also be a prefix. When a keymap binds both =C-c= an
7777
7878The echo area is the line at the bottom of the window, below the modeline. It shows, in order of priority:
7979
80- A question a command is asking, with a text field: a refile target, a date, a property value, a sparse-tree match, a Vim search or ex command. =Return= answers, =Esc= cancels. When the question has choices, they are listed above the field and filtered as you type with fuzzy matching; =Tab= completes the best match. Date questions show a calendar, and =S-<left>=, =S-<right>=, =S-<up>= and =S-<down>= move the date by a day or a week, as in =org-read-date=.
80- A question a command is asking, with a text field: a refile target, a date, a property value, a sparse-tree match, a Vim search or ex command. =Return= answers, =Esc= cancels. When the question has choices, they are listed above the field and filtered as you type with fuzzy matching, best first; the count at the right shows which one is highlighted and how many match (=3/40=). =↑= and =↓= (or =C-p= and =C-n=) move the highlight, =Tab= completes the highlighted choice, and =Return= answers with it, or with the text as typed when the question accepts any text and the highlight has not been moved. Date questions show a calendar, and =S-<left>=, =S-<right>=, =S-<up>= and =S-<down>= move the date by a day or a week, as in =org-read-date=.
8181- Fast selection for TODO keywords and tags when the file defines keys for them (see [[file:05-todos-and-tags.org][TODOs and tags]]).
8282- The pending prefix, such as =C-c C-x-=.
83- The last message from a command or from the keymap, for four seconds.
83- The last message from a command or from the keymap, until the next key or click.
8484
85VoiceOver reads each message as it appears.
85VoiceOver reads each message as it appears. View ▸ Messages (=app.messages=) lists the last 100 messages.
8686
8787In the Doom preset the modeline shows the evil state as a tag: =NORMAL=, =INSERT=, =VISUAL=, =V-LINE= or =V-BLOCK=. See [[file:02-the-editor.org][The editor]] for the rest of the modeline.
8888
@@ -1135,6 +1135,7 @@ No preset binds these. Run them from the palette or a menu, or bind them in =key
11351135| Command | What it does |
11361136|-+-|
11371137| Board (=app.board=) | Opens the Board window. Window ▸ Board, =⇧⌘B=. |
1138| Messages (=app.messages=) | Lists the last 100 messages of the echo area (=view-echo-area-messages=). View ▸ Messages. |
11381139| Show Agenda or Files in Sidebar (=app.sidebar-agenda=) | Switches the sidebar between the files and the agenda, as the button at the right of its bar does. |
11391140| Verbatim, Code, Strike-Through (=org.emphasize.verbatim=, =org.emphasize.code=, =org.emphasize.strike-through=) | =org-emphasize= with ===, =~= or =+=. |
11401141| Cancel Running Task (=app.babel.cancel=) | Stops the src block that is running, or an export or table recalculation running in Emacs. Edit ▸ Cancel Running Task, =⌘.=. |
l10n/Localizable.xcstrings +104 · view
@@ -6309,6 +6309,41 @@
63096309 }
63106310 }
63116311 },
6312 "Choice %lld of %lld": {
6313 "comment": "VoiceOver label for the echo area's count of matching choices",
6314 "localizations": {
6315 "de": {
6316 "stringUnit": {
6317 "state": "translated",
6318 "value": "Auswahl %1$lld von %2$lld"
6319 }
6320 },
6321 "es": {
6322 "stringUnit": {
6323 "state": "translated",
6324 "value": "Opción %1$lld de %2$lld"
6325 }
6326 },
6327 "fr": {
6328 "stringUnit": {
6329 "state": "translated",
6330 "value": "Choix %1$lld sur %2$lld"
6331 }
6332 },
6333 "ja": {
6334 "stringUnit": {
6335 "state": "translated",
6336 "value": "%2$lld件中%1$lld件目"
6337 }
6338 },
6339 "pt-BR": {
6340 "stringUnit": {
6341 "state": "translated",
6342 "value": "Opção %1$lld de %2$lld"
6343 }
6344 }
6345 }
6346 },
63126347 "Choices": {
63136348 "localizations": {
63146349 "de": {
@@ -19036,6 +19071,41 @@
1903619071 }
1903719072 }
1903819073 },
19074 "Messages": {
19075 "comment": "Command title",
19076 "localizations": {
19077 "de": {
19078 "stringUnit": {
19079 "state": "translated",
19080 "value": "Meldungen"
19081 }
19082 },
19083 "es": {
19084 "stringUnit": {
19085 "state": "translated",
19086 "value": "Mensajes"
19087 }
19088 },
19089 "fr": {
19090 "stringUnit": {
19091 "state": "translated",
19092 "value": "Messages"
19093 }
19094 },
19095 "ja": {
19096 "stringUnit": {
19097 "state": "translated",
19098 "value": "メッセージ"
19099 }
19100 },
19101 "pt-BR": {
19102 "stringUnit": {
19103 "state": "translated",
19104 "value": "Mensagens"
19105 }
19106 }
19107 }
19108 },
1903919109 "Midnight": {
1904019110 "localizations": {
1904119111 "de": {
@@ -21863,6 +21933,40 @@
2186321933 }
2186421934 }
2186521935 },
21936 "No messages": {
21937 "localizations": {
21938 "de": {
21939 "stringUnit": {
21940 "state": "translated",
21941 "value": "Keine Meldungen"
21942 }
21943 },
21944 "es": {
21945 "stringUnit": {
21946 "state": "translated",
21947 "value": "No hay mensajes"
21948 }
21949 },
21950 "fr": {
21951 "stringUnit": {
21952 "state": "translated",
21953 "value": "Aucun message"
21954 }
21955 },
21956 "ja": {
21957 "stringUnit": {
21958 "state": "translated",
21959 "value": "メッセージはありません"
21960 }
21961 },
21962 "pt-BR": {
21963 "stringUnit": {
21964 "state": "translated",
21965 "value": "Nenhuma mensagem"
21966 }
21967 }
21968 }
21969 },
2186621970 "No notes match": {
2186721971 "localizations": {
2186821972 "de": {
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form