Skip to content

feat: add browser-like back/forward navigation history#183

Open
dalelane wants to merge 3 commits into
erictli:mainfrom
dalelane:navigation-history
Open

feat: add browser-like back/forward navigation history#183
dalelane wants to merge 3 commits into
erictli:mainfrom
dalelane:navigation-history

Conversation

@dalelane

@dalelane dalelane commented Jun 28, 2026

Copy link
Copy Markdown

Tracks note navigation in a history stack so you can move back and forward between previously visited notes, mimicing standard browser behaviour.

I've chosen Cmd+[ and Cmd+] as keyboard shortcuts for back/forward because that's what Safari uses. I considered using Cmd+left and Cmd+right to match Chrome, but that clashed with editor shortcuts to jump to the start of the line.

I've added toolbar back/forward buttons with arrow icons, next to the sidebar toggle, and enable/disable them if the stack has no pages left.

I've tried to make sure the stack keeps up with any changes (e.g. when notes or folders are renamed or deleted) so the history doesn't point at non-existent pages. Returning to the default "What's on your mind?" page will clear the history entirely as it is essentially a reset. All of that did complicate the commit a lot more than I'd originally hoped/expected, sorry about that!

To copy web browser behaviour, if you click on a link that discards any forward history. I'm ignoring any external URL clicks as that just got confusing to include.

Summary by CodeRabbit

  • New Features

    • Added keyboard shortcuts for note navigation: back (mod+ [) and forward (mod+ ]).
    • Added back/forward buttons to the editor title bar (enabled/disabled based on availability).
    • Note navigation now tracks a history stack and updates it as you create, select, duplicate, rename, move, or delete notes and folders.
  • Bug Fixes

    • Improved back/forward accuracy so navigation continues to work correctly after note or folder changes (rename/move/delete).

Tracks note navigation in a history stack so you can move back and
forward between previously visited notes, mimicing standard browser
behaviour.

I've chosen Cmd+[ and Cmd+] as keyboard shortcuts for back/forward
because that's what Safari uses. I considered using Cmd+left and
Cmd+right to match Chrome, but that clashed with editor shortcuts
to jump to the start of the line.

I've added toolbar back/forward buttons with arrow icons, next to
the sidebar toggle, and enable/disable them if the stack has no
pages left.

I've tried to make sure the stack keeps up with any changes (e.g.
when notes or folders are renamed or deleted) so the history
doesn't point at non-existent pages. Returning to the default
"What's on your mind?" page will clear the history entirely as it
is essentially a reset. All of that did complicate the commit a lot
more than I'd originally hoped/expected, sorry about that!

To copy web browser behaviour, if you click on a link that discards
any forward history. I'm ignoring any external URL clicks as that
just got confusing to include.

Signed-off-by: Dale Lane <dale.lane@gmail.com>
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 570a3ca8-b770-436c-a6da-8876b633f871

📥 Commits

Reviewing files that changed from the base of the PR and between 51b68aa and afe34b2.

📒 Files selected for processing (1)
  • src/context/NotesContext.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/context/NotesContext.tsx

📝 Walkthrough

Walkthrough

Adds browser-style back/forward navigation history to the notes app. NotesContext gains a NavState stack that is pushed on note selection and maintained across create, delete, rename, move, and folder operations. goBack/goForward actions and canGoBack/canGoForward flags are exposed via context, wired into editor toolbar buttons, and bound to Cmd/Ctrl+[ / Cmd/Ctrl+] global shortcuts.

Changes

Note Navigation History

Layer / File(s) Summary
Navigation state, helpers, and selectNote/goBack/goForward in NotesContext
src/context/NotesContext.tsx
Adds canGoBack/canGoForward to the data context interface; extends the actions interface with goBack/goForward; introduces NavState, navPush/navRemove helpers, nav state with a navRef mirror, and an internal loadNoteById. Refactors selectNote to push history and implements goBack/goForward index traversal. Wires all four values into memoized context values and their dependency arrays.
Nav history maintenance across mutations
src/context/NotesContext.tsx
Updates nav history on every mutating operation: pushing on create/duplicate/folder-note-create; replacing IDs on save-rename, note-move, folder-rename, and folder-move; removing IDs on note-delete and folder-delete; resetting history on root folder set/sync.
Back/forward buttons in Editor toolbar
src/components/editor/Editor.tsx
Imports ArrowLeftIcon/ArrowRightIcon; reads canGoBack/canGoForward/goBack/goForward from notesCtx; renders conditional IconButtons in the title bar that are disabled when navigation is unavailable.
Global keyboard shortcuts and registry
src/App.tsx, src/lib/shortcuts.ts
Destructures goBack/goForward from useNotes(); adds Cmd/Ctrl+[ and Cmd/Ctrl+] keydown handlers; updates useEffect deps. Registers mod+[ and mod+] in the Navigation shortcut category.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • erictli

Poem

🐇 I hopped through notes both near and far,
With [and]` I chased each star.
Back and forward, soft and neat,
My bunny trail feels round and sweet.
Icons blink and shortcuts sing —
A tidy hop for everything!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding browser-like back/forward navigation history.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dalelane

Copy link
Copy Markdown
Author

@erictli Thanks so much for sharing scratch - I find it super useful.

I feel a little weird offering an unsolicited feature, so obviously it's entirely fine if you're not interested and prefer to close this without review. I'm happy using this as a feature in my private fork.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/context/NotesContext.tsx`:
- Around line 173-179: The selectNote flow in NotesContext pushes the note ID
into navigation history before verifying the note loads successfully. Update the
selectNote callback to await loadNoteById(id) first and only call setNav with
navPush afterward, matching the goBack/goForward behavior so failed loads do not
leave broken entries in history.

In `@src/lib/shortcuts.ts`:
- Around line 26-28: The shortcuts list currently advertises a “Go to note”
binding for mod+G, but there is no matching handler in the global shortcut
logic. Either remove the `Go to note` entry from `shortcuts.ts` or implement the
`g` branch in `App.tsx`’s shortcut handler so it triggers the intended note
navigation action, keeping the documented shortcut and runtime behavior aligned.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 93d851a8-1395-4bd9-8aa5-ad5e92c1d259

📥 Commits

Reviewing files that changed from the base of the PR and between a638f02 and a570071.

📒 Files selected for processing (4)
  • src/App.tsx
  • src/components/editor/Editor.tsx
  • src/context/NotesContext.tsx
  • src/lib/shortcuts.ts

Comment thread src/context/NotesContext.tsx
Comment thread src/lib/shortcuts.ts Outdated
dalelane and others added 2 commits June 28, 2026 13:42
This was a git commit mixup - I've got a go-to-note feature in
a separate branch, and hadn't spotted that I left the shortcut
in this branch.

Signed-off-by: Dale Lane <dale.lane@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

1 participant