Keyboard Shortcuts
Relevant source files
The following files were used as context for generating this wiki page:
Keyboard shortcuts in the Writer application are designed to facilitate a distraction-free, efficient markdown editing experience. These shortcuts bridge the gap between simple text entry and complex file management or document export tasks, allowing users to keep their hands on the keyboard during the creative process.
The application leverages SwiftUI's keyboardShortcut modifier and macOS-specific command menus to map physical key presses to internal logic handled by the EditorStore and export utilities.
Command Menu Shortcuts
The primary interface for global keyboard shortcuts is the macOS menu bar, defined within the app's entry point. These shortcuts are available whenever the application is active and often correspond to file-level operations.
File Operations
The "File" menu contains shortcuts for document lifecycle management, including creation and various export formats.
| Shortcut | Action | Context/Requirement |
|---|---|---|
⌘ N | New File | Requires an active directory |
⌘ ⇧ N | New Folder | Requires an active directory |
⌘ ⇧ E | Export to HTML | Active file must be selected |
⌘ ⇧ P | Export to PDF | Active file must be selected |
⌘ ⇧ R | Export to RTF | Active file must be selected |
⌘ ⇧ F | Format Tables | Processes all markdown tables in document |
Sources: Writer/WriterApp.swift:94-135, CLAUDE.md:46-51
View Operations
Shortcuts under the "View" menu allow users to manipulate the editor's layout and interface elements.
| Shortcut | Action | Implementation |
|---|---|---|
⌘ ⌥ P | Toggle Preview | Toggles LayoutStore.showPreview |
Sources: Writer/WriterApp.swift:138-142
Contextual and Internal Shortcuts
Beyond the global menu shortcuts, specific views within the application handle input for modal interactions and editor behaviors.
Modal Navigation
When using the "New File" or "New Folder" sheets, specific keys are mapped to handle the dialogue without mouse interaction.
- Return (
↵): Confirms the creation of the file or folder. Sources: Writer/ContentView.swift:189-197 - Escape (
⎋): Cancels the creation process and closes the sheet. Sources: Writer/ContentView.swift:184-187
Editor Specifics
The MarkdownTextView implements standard macOS text editing behaviors through its inheritance from NSTextView.
⌘ B: Implicitly supported viaNSTextViewfor bolding text (though the app specifically handles markdown styling). Sources: CLAUDE.md:15⌘ R: Used for running the project in Xcode, but also listed as the trigger for RTF export in the app context. Sources: CLAUDE.md:16, Writer/WriterApp.swift:123
Shortcut Implementation Flow
The following diagram illustrates how a keyboard shortcut (e.g., ⌘ ⇧ F) flows from user input through the SwiftUI architecture to the underlying logic.
The application uses the keyboardShortcut(_:modifiers:) modifier to bind specific keys to button actions. For example, the table formatting shortcut is implemented as:
Button("Format Tables") {
editorStore.formatAllTables()
}
.keyboardShortcut("f", modifiers: [.command, .shift])
Sources: Writer/WriterApp.swift:128-132
Logic and Architecture
The shortcuts are tightly integrated with the EditorStore and LayoutStore. When a shortcut like ⌘ ⇧ E (Export to HTML) is pressed, the following sequence occurs:
Conclusion
Keyboard shortcuts in Writer are a primary method for document management and layout control. By utilizing standard macOS modifiers (Command, Shift, Option), the application provides a familiar experience for power users while maintaining the simplicity of the distraction-free interface. Most shortcuts are centralized in WriterApp.swift, ensuring they remain globally accessible throughout the application's lifecycle.