Skip to content

Add Navigate Back and Navigate Forward commands#4531

Draft
raineorshine with Copilot wants to merge 4 commits into
mainfrom
copilot/add-navigate-back-forward-commands
Draft

Add Navigate Back and Navigate Forward commands#4531
raineorshine with Copilot wants to merge 4 commits into
mainfrom
copilot/add-navigate-back-forward-commands

Conversation

Copilot AI commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Adds two commands that drive the browser Navigation API from within em: Navigate Back (⌘ + [ / ⌘ + ←) and Navigate Forward (⌘ + ] / ⌘ + →), gated on whether history exists in that direction.

Commands

  • New navigateBack / navigateForward commands. exec calls window.navigation.back() / forward(); canExecute reflects window.navigation.canGoBack / canGoForward, so each is disabled (greyed out in the Command Universe) with no history to navigate to or when the API is unavailable.
const navigateBackCommand: Command = {
  id: 'navigateBack',
  label: 'Navigate Back',
  keyboard: [{ key: '[', meta: true }, { key: Key.ArrowLeft, meta: true }],
  multicursor: false,
  svg: ArrowLeftIcon,
  canExecute: () => !!window.navigation?.canGoBack,
  exec: () => window.navigation?.back(),
}

Wiring

  • Registered both in the src/commands/index.ts barrel and the Navigation group in COMMAND_GROUPS (constants.ts) — the latter is a runtime invariant (useCommandList throws otherwise).
  • Reused ArrowLeftIcon / ArrowRightIcon; relaxed their FC<IconType> typing to the plain (props: IconType) => form used by all other command icons so they're assignable to Command.svg.

Types

  • Declared a minimal window.navigation (canGoBack, canGoForward, back, forward) on the global Window interface, as the Navigation API is not yet in the TS DOM lib. Optional, reflecting unsupported browsers (e.g. older Safari).

Shortcut conflict

  • ⌘ + ] was a secondary alias on categorize; removed it (primary ⌘ + Alt + O retained) and updated the categorize puppeteer test to use the primary shortcut.

Reviewer note

  • The ⌘ + ← / ⌘ + → aliases preventDefault the native caret-to-line-start/end while editing. If undesirable, the arrow aliases can be dropped while keeping the bracket bindings.

- Add navigateBack (⌘+[ / ⌘+←) and navigateForward (⌘+] / ⌘+→) commands
  using the Navigation API (window.navigation.back/forward, canGoBack/canGoForward)
- Declare window.navigation in the global Window type
- Remove categorize's conflicting ⌘+] alias (keeps primary ⌘+Alt+O)
- Reuse ArrowLeft/ArrowRight icons; align their typing with icon convention
- Add unit tests for canExecute/exec

Co-authored-by: raineorshine <750276+raineorshine@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Vercel preview: https://em-peepafj56-cybersemics.vercel.app

Copilot AI and others added 3 commits July 6, 2026 16:52
useCommandList requires every command to be in a COMMAND_GROUPS group
or have hideFromHelp: true. Add both to the Navigation group.

Co-authored-by: raineorshine <750276+raineorshine@users.noreply.github.com>
…back-forward-commands

Co-authored-by: raineorshine <750276+raineorshine@users.noreply.github.com>
The categorize puppeteer test triggered categorize via ⌘+], which is now
reassigned to Navigate Forward. Switch it to categorize's retained primary
shortcut ⌘+Alt+O.

Co-authored-by: raineorshine <750276+raineorshine@users.noreply.github.com>
Copilot AI changed the title feat(commands): add Navigate Back and Navigate Forward commands Add Navigate Back and Navigate Forward commands Jul 6, 2026
Copilot AI requested a review from raineorshine July 6, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants