Keyboard Shortcuts - samyanez94/GoalTracker GitHub Wiki

Keyboard Shortcuts

Moku supports the following shortcuts when using an external keyboard. They work in both compact and regular layouts on supported iPhones and iPads.

This page describes the implementation added in development commit 045174f. Availability in the published App Store version depends on its release.

Supported shortcuts

Shortcut Action Availability
⌘N Create a goal Main app, when no form sheet is open.
⌘F Search goals Main app, when no form sheet is open. Reveals the goal list and focuses its search field.
⌘S Save Goal create/edit forms, progress updates, and custom-unit forms, when the input is valid.
Escape Cancel or dismiss Goal create/edit and progress-update sheets. Goal forms retain the existing discard-changes confirmation when there are unsaved edits.

⌘ means Command.

New and Search work even when the sidebar is hidden. In compact layouts, Search returns from goal detail or progress history to the goal list. In regular layouts, it reveals the sidebar while retaining the current detail screen. Search also exits bulk selection mode.

An open form sheet disables New and Search until it closes. Save uses the same validation and persistence behavior as the on-screen Save button. Return is not assigned an app shortcut, leaving it available for normal text entry.

Implementation overview

Keyboard support lives in GoalTracker/App/Keyboard. Navigation state lives in GoalTracker/App/Navigation, and their tests mirror these folders under GoalTrackerTests/App.

The main pieces are:

  • GoalKeyboardCommands registers New and Search as SwiftUI scene commands. GoalKeyboardActions and the focused scene values route them to the active scene's goal list, even when its sidebar is collapsed.
  • GoalNavigationView reveals the sidebar for Search. GoalListView uses searchFocused to focus the search field and shares the create-goal action between the toolbar and keyboard command.
  • Each navigation scene owns a GoalKeyboardState. GoalFormKeyboardScope tracks the lifetime of each sheet's navigation container, keeping New and Search disabled while a form is presented, including when navigating to a screen within that form.
  • Save and Cancel shortcuts attach directly to the existing form buttons using keyboardShortcut("s", modifiers: .command) and keyboardShortcut(.cancelAction). This preserves validation, error handling, and cancellation confirmation.

Verification

The keyboard presentation-state and navigation regression suites passed all 10 focused tests. Simulator checks covered compact and regular layouts, hidden-sidebar commands, search focus, valid and invalid saves, modal command blocking, and cancellation confirmation. The shortcuts were also manually confirmed by the app's maintainer.