Skip to content

feat: find text within notes - #911

Closed
maccman wants to merge 4 commits into
masterfrom
codex/note-find
Closed

maccman wants to merge 4 commits into
masterfrom
codex/note-find

Conversation

@maccman

@maccman maccman commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Problem

Reflect had no note-local text search. Users accustomed to browser Find could not locate a phrase in a long note without leaving the editor, and Tauri/Wry does not provide one stable cross-platform page-find API that preserves Meowdown rendered-text semantics.

This PR adds Find for the active note only. Graph-wide search remains unchanged.

Before → After

Behavior Before After
Find inside a note Unavailable Cmd/Ctrl+F opens a compact Find bar with live counts and highlights
Match navigation Unavailable Enter or Cmd/Ctrl+G moves forward; Shift reverses; navigation wraps
Markdown-aware search Raw/editor behavior undefined Searches visible prose, aliases, attachment labels, and math while excluding hidden destinations and delimiters
Detached note windows No Find target Keyboard shortcuts and native Edit menu actions route to the focused webview
Escape focus No Find behavior Escape within Find returns to the note; Escape after moving elsewhere closes Find without stealing focus

Changes

  1. Added a ProseMirror search extension and NoteFindQuery, which projects rendered Meowdown text back to document positions. Literal matching is case-insensitive, Unicode-safe, and uses cached indexed lookup for high match counts. Active queries reproject when Markdown syntax visibility changes.
  2. Added a per-window Find session and design-system Find bar with keyboard navigation, accessible status updates, IME guards, retained Cmd/Ctrl+G continuation, safe selection collapse, and focus restoration owned by the Find bar rather than the window fallback.
  3. Connected note-scoped commands to the focused daily-stream editor or routed note. Pending editors attach when mounted; virtualized editors close their transient Find session cleanly. Query edits restart forward from the session origin, and query or clear state survives a temporary editor detach/rebind.
  4. Added Find, Find Next, and Find Previous to the native Edit menu. Tauri routes these commands to the focused webview without platform-specific WebKit/WebView branches.

Tests

  • Rendered-text query semantics: prose, hidden Markdown, links, wiki aliases, images, files, math, show mode, Unicode offsets, and 4,096 matches.
  • Controller behavior: caret origin, forward/reverse wrapping, forward query refinement, retained continuation, syntax-mode refresh, temporary editor rebinding, safe clear, document refresh, and independent selection changes.
  • Find bar/provider behavior: focus ownership, repeated shortcuts, Escape from Find and unrelated controls, loading, virtualization, route changes, and secondary windows.
  • Command registry, route targeting, native menu dispatch, daily-stream handle compatibility, and existing editor consumers.

Verification

  • pnpm --filter @reflect/desktop test --run src/components/note-find-bar.test.tsx src/editor/note-find.test.ts src/editor/note-find-query.test.ts — 23 tests passed.
  • All 19 relevant suites — 303 tests passed against current master.
  • pnpm check — passed; only the two existing max-lines warnings remain.
  • pnpm build — passed; expected missing Sentry-token and chunk-size warnings remain.
  • Live browser verification covered query focus, counts, wrapping, reverse navigation, aliases, hidden destinations, math highlighting, Escape focus restoration, and selection safety.

Risk / Rollout

No data migration, settings change, external service, or network call is introduced. Search remains entirely local to the mounted editor, including private notes. Roll out with the normal desktop release.


Note

Medium Risk
Large editor/routing integration with new ProseMirror search and cross-window menu dispatch; behavior is well-tested but touches daily-stream focus targeting and secondary windows.

Overview
Adds Find in note for the active editor: a compact overlay bar, live match counts, highlights, and browser-style navigation (Mod-F, Enter / Mod-G, wrap, resume after close).

Search runs on rendered Meowdown text via prosemirror-search and a custom NoteFindQuery (visible prose and atom labels; hidden link destinations and most syntax unless show mode). The note editor exposes find APIs on NoteEditorHandle; a per-window NoteFindProvider binds to the focused daily-stream day or routed note through focusedNotePathForRoute, waits for lazy-mounted editors, and tears down on route change or virtualization unmount.

Commands and menus: note.find / note.findNext / note.findPrevious on CommandContext; macOS Edit menu entries route Find to the focused Tauri webview (detached note windows listen via event), not always main.

Reviewed by Cursor Bugbot for commit 9ea6153. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • New Features
    • Added “Find in Note” with match highlighting, live match count, and next/previous navigation (including in secondary note windows).
    • Added note find keyboard shortcuts: open (Mod+F), next match (Mod+G), previous match (Mod+Shift+G).
    • Added Find controls to the Edit menu and routed them to the currently focused note window.
    • Search operates on displayed note content (visible labels/aliases).
  • Bug Fixes
    • Improved Find state synchronization across editor loading, unmount/remount, and focus/visibility changes, including reliable close/clear behavior.

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5e1cc21. Configure here.

Comment thread apps/desktop/src/lib/native-menu/dispatch.ts
Comment thread apps/desktop/src/providers/note-find-provider.tsx
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Adds note-local Find support backed by ProseMirror search, including visible-text matching, editor APIs, provider-managed sessions, UI controls, keyboard and native-menu commands, focused-note routing, highlighting, and associated tests.

Changes

Note-local Find

Layer / File(s) Summary
Find query and editor engine
apps/desktop/src/editor/note-find-query.ts, apps/desktop/src/editor/note-find.tsx, apps/desktop/src/editor/note-editor.tsx, apps/desktop/package.json, apps/desktop/src/editor/*test*
Searches projected visible note content, maps matches to ProseMirror ranges, caches results, tracks match state, and exposes Find operations through NoteEditorHandle.
Find session provider and surfaces
apps/desktop/src/providers/note-find-provider.tsx, apps/desktop/src/components/note-find-bar.tsx, apps/desktop/src/components/*workspace*.tsx, apps/desktop/src/components/note-window-content.tsx, apps/desktop/src/editor/editor-handle-registry.ts, apps/desktop/src/styles/index.css, apps/desktop/src/components/note-find-bar.test.tsx
Manages per-note Find sessions and editor attachment, renders Find controls in main and secondary windows, and styles active and inactive search matches.
Commands and focused-note routing
apps/desktop/src/lib/commands/*, apps/desktop/src/routing/*, apps/desktop/src/lib/native-menu/*, apps/desktop/src/components/command-palette/command-palette.test.tsx, apps/desktop/src/components/sidebar/sidebar.test.tsx
Adds Find commands and shortcuts, resolves the focused note path, adds native Edit-menu entries, and routes Find commands to focused secondary webviews.
Find contract test compatibility
apps/desktop/src/components/daily-stream.focus.test.tsx, apps/desktop/src/components/route-content.test.tsx, apps/desktop/src/editor/use-*.test.*, apps/desktop/src/lib/attach-files.test.ts, apps/desktop/src/mobile/*test.tsx
Extends editor and command test doubles with Find methods, snapshots, and unsubscribe callbacks.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant NoteFindBar
  participant NoteFindProvider
  participant NoteEditor
  User->>NoteFindBar: Enter query
  NoteFindBar->>NoteFindProvider: updateQuery
  NoteFindProvider->>NoteEditor: updateFindQuery
  NoteEditor->>NoteFindProvider: publish match snapshot
  NoteFindProvider->>NoteFindBar: render match status
Loading
sequenceDiagram
  participant User
  participant NativeMenu
  participant FocusedWebview
  participant NoteFindProvider
  User->>NativeMenu: Select Find command
  NativeMenu->>FocusedWebview: emit focused-note command
  FocusedWebview->>NoteFindProvider: deliver validated command
  NoteFindProvider->>FocusedWebview: open or navigate Find
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.09% 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
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding note-local text search inside notes.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/note-find

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

@maccman

maccman commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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: 1

🤖 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 `@apps/desktop/src/lib/native-menu/dispatch.ts`:
- Around line 40-52: Update dispatchToFocusedWindow so failures from an
individual window.isFocused() check are isolated rather than rejecting the
shared Promise.all result. Preserve successfully detected focused windows and
continue selecting the first focused window, while retaining the existing outer
lookup error handling for failures from getAllWebviewWindows or the overall
detection flow.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d122b94b-3078-4319-93de-b8d9b1b3dff6

📥 Commits

Reviewing files that changed from the base of the PR and between 60ff49c and 0f032d3.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (36)
  • apps/desktop/package.json
  • apps/desktop/src/components/command-palette/command-palette.test.tsx
  • apps/desktop/src/components/daily-stream.focus.test.tsx
  • apps/desktop/src/components/graph-workspace.tsx
  • apps/desktop/src/components/note-find-bar.test.tsx
  • apps/desktop/src/components/note-find-bar.tsx
  • apps/desktop/src/components/note-window-content.tsx
  • apps/desktop/src/components/route-content.test.tsx
  • apps/desktop/src/components/sidebar/sidebar.test.tsx
  • apps/desktop/src/components/workspace-content.test.tsx
  • apps/desktop/src/components/workspace-content.tsx
  • apps/desktop/src/editor/editor-handle-registry.ts
  • apps/desktop/src/editor/note-editor.test.tsx
  • apps/desktop/src/editor/note-editor.tsx
  • apps/desktop/src/editor/note-find-query.test.ts
  • apps/desktop/src/editor/note-find-query.ts
  • apps/desktop/src/editor/note-find.test.ts
  • apps/desktop/src/editor/note-find.tsx
  • apps/desktop/src/editor/use-note-document.test.tsx
  • apps/desktop/src/editor/use-template-slash-items.test.ts
  • apps/desktop/src/lib/attach-files.test.ts
  • apps/desktop/src/lib/commands/app-commands.test.ts
  • apps/desktop/src/lib/commands/app-commands.ts
  • apps/desktop/src/lib/commands/registry.test.ts
  • apps/desktop/src/lib/commands/types.ts
  • apps/desktop/src/lib/native-menu/dispatch.ts
  • apps/desktop/src/lib/native-menu/menu.test.ts
  • apps/desktop/src/lib/native-menu/menu.ts
  • apps/desktop/src/mobile/mobile-screen.test.tsx
  • apps/desktop/src/mobile/screens/tasks.test.tsx
  • apps/desktop/src/providers/note-find-provider.tsx
  • apps/desktop/src/routing/app-shortcuts.test.tsx
  • apps/desktop/src/routing/app-shortcuts.ts
  • apps/desktop/src/routing/route.test.ts
  • apps/desktop/src/routing/route.ts
  • apps/desktop/src/styles/index.css

Comment thread apps/desktop/src/lib/native-menu/dispatch.ts

@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.

🧹 Nitpick comments (1)
apps/desktop/src/lib/native-menu/dispatch.ts (1)

89-114: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the exported focused-note routing APIs.

listenForFocusedNoteMenuCommands is a new public API with important lifecycle and validation behavior, but it has no JSDoc. Document its validated payload contract and returned unlisten handle; also document dispatchMenuCommand while its focused-window routing semantics are being exposed.

As per coding guidelines, public APIs must always be documented.

🤖 Prompt for 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.

In `@apps/desktop/src/lib/native-menu/dispatch.ts` around lines 89 - 114, Add
JSDoc to the exported APIs dispatchMenuCommand and
listenForFocusedNoteMenuCommands. Document that dispatchMenuCommand routes valid
focused-note commands to the focused window and otherwise uses the current
handler; document that listenForFocusedNoteMenuCommands validates incoming event
payloads against FocusedNoteMenuCommandSchema, dispatches only valid commands,
and returns an UnlistenFn for removing the listener.

Source: Coding guidelines

🤖 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.

Nitpick comments:
In `@apps/desktop/src/lib/native-menu/dispatch.ts`:
- Around line 89-114: Add JSDoc to the exported APIs dispatchMenuCommand and
listenForFocusedNoteMenuCommands. Document that dispatchMenuCommand routes valid
focused-note commands to the focused window and otherwise uses the current
handler; document that listenForFocusedNoteMenuCommands validates incoming event
payloads against FocusedNoteMenuCommandSchema, dispatches only valid commands,
and returns an UnlistenFn for removing the listener.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 487c287a-40fa-4f45-be0b-e8af68407bc5

📥 Commits

Reviewing files that changed from the base of the PR and between 0f032d3 and 9ea6153.

📒 Files selected for processing (2)
  • apps/desktop/src/lib/native-menu/dispatch.ts
  • apps/desktop/src/lib/native-menu/menu.test.ts

@ocavue

ocavue commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

implemented in #955

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