fix(desktop): stop Cmd+F crash and add a find-in-note bar (macOS)#577
fix(desktop): stop Cmd+F crash and add a find-in-note bar (macOS)#577JakubAnderwald wants to merge 2 commits into
Conversation
Cmd+F crashed the macOS app. DraftoMenuManager replaces AppKit's default main menu but dropped the Find item, so Cmd+F leaked past the menu to the focused tentap WKWebView and react-native-macos aborted building an NSArray with a nil element (NSInvalidArgumentException -> SIGABRT). Bind Cmd+F / Cmd+G / Cmd+Shift+G as menu key-equivalents via the onMenuAction bridge so AppKit absorbs them in performKeyEquivalent before keyDown ever reaches the WebView, and wire them to a find-in-note bar. The bar drives the tentap editor by injecting a find engine (window.__draftoFind) that highlights matches with the CSS Custom Highlight API (no DOM mutation, offset-safe regex match) and posts match counts back through a custom onMessage passthrough (exclusivelyUseCustomOnMessage=false so tentap's own bridge keeps working). Adds find-engine + find-bar with unit and jsdom-runtime tests, and ADR-0028. Scope: parity:desktop-only (macOS-native-menu-specific crash). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 46 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR adds a desktop-only "Find in note" feature: an injected WebView engine highlighting matches via the CSS Custom Highlight API, a FindBar UI, native macOS Cmd+F/Find Next/Previous menu bindings, wiring through NoteEditorPanel and MainScreen, plus tests and an ADR. ChangesDesktop Find-in-Note Feature
Estimated code review effort: 3 (Moderate) | ~30 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant MainScreen
participant NoteEditorPanel
participant WebView as Tentap WebView
participant Engine as window.__draftoFind
User->>MainScreen: Cmd+F (findInNote)
MainScreen->>NoteEditorPanel: findSignal { command: "open", nonce }
NoteEditorPanel->>NoteEditorPanel: show FindBar, set findVisible
User->>NoteEditorPanel: type query
NoteEditorPanel->>WebView: inject findSearchJS(query)
WebView->>Engine: search(query, pattern)
Engine->>Engine: highlight matches
Engine->>WebView: postMessage({type, total, current})
WebView->>NoteEditorPanel: onMessage(event)
NoteEditorPanel->>NoteEditorPanel: parseFindResult, update match counts
User->>MainScreen: Cmd+G (findNext)
MainScreen->>NoteEditorPanel: findSignal { command: "next", nonce }
NoteEditorPanel->>WebView: inject findStepJS("next")
WebView->>Engine: next()
Engine->>WebView: postMessage(updated counts)
WebView->>NoteEditorPanel: onMessage(event)
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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/components/editor/find-engine.ts`:
- Around line 84-111: The full-document tree walk in search() is being triggered
on every keystroke, so keep this function unchanged and fix the call site
instead. Update handleFindChange in note-editor-panel.tsx to debounce or
otherwise throttle calls into search() so repeated input does not re-run the
ProseMirror text-node scan on every character. Use the existing search() and
handleFindChange symbols to locate the integration point and apply the debounce
where the query state is forwarded.
In `@apps/desktop/src/components/editor/note-editor.tsx`:
- Around line 5-23: The NoteEditorProps setup should explicitly disable the
default custom message exclusivity so TenTap’s bridge keeps working. In
note-editor.tsx where NoteEditorProps declares the optional onMessage callback
and the RichText integration is configured, set exclusivelyUseCustomOnMessage to
false whenever a custom onMessage is supplied so editor readiness, onChange, and
getJSON messages still flow through TenTap’s internal handler.
In `@apps/desktop/src/components/notes/note-editor-panel.tsx`:
- Around line 433-439: The find-bar change handler in note-editor-panel’s
handleFindChange is triggering a full findSearchJS/injectFind search on every
keystroke, which can cause typing lag. Update this path to debounce the query
handling so setFindQuery can still update immediately while
injectFind(findSearchJS(query)) runs only after a short delay; make sure the
debounce is wired through handleFindChange and cleaned up properly in the
note-editor-panel component.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 779cbb0d-4531-46f0-a4b8-29ec4199116c
📒 Files selected for processing (12)
apps/desktop/__tests__/components/editor/find-bar.test.tsxapps/desktop/__tests__/components/editor/find-engine.runtime.test.tsapps/desktop/__tests__/components/editor/find-engine.test.tsapps/desktop/macos/Drafto-macOS/DraftoMenuManager.mmapps/desktop/src/components/editor/find-bar.tsxapps/desktop/src/components/editor/find-engine.tsapps/desktop/src/components/editor/note-editor.tsxapps/desktop/src/components/notes/note-editor-panel.tsxapps/desktop/src/lib/native/menu-manager.tsapps/desktop/src/screens/main.tsxdocs/adr/0028-desktop-find-in-note.mddocs/adr/README.md
Addresses CodeRabbit review: the injected engine re-scans every ProseMirror text node per search, so debounce injectFind(findSearchJS()) by 150ms in handleFindChange (input stays responsive). Cancel the pending timer on reset (close / note switch) so a late search can't re-highlight, and on unmount. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
What & why
Pressing Cmd+F in the macOS app crashed it instantly. Root cause (from the native crash report):
DraftoMenuManager.setupMenusreplaces AppKit's default main menu but its custom Edit menu has no Find item, so Cmd+F is no longer a menu key-equivalent — it leaks to the focused tentap WKWebView, and react-native-macos aborts building anNSArraywith anilelement (NSInvalidArgumentException→SIGABRT).The fix
onMenuActionbridge (target = the menu manager, so the item is always enabled). AppKit absorbs them inperformKeyEquivalent:beforekeyDown:ever reaches the WebView.window.__draftoFind) which highlights matches with the CSS Custom Highlight API (overlay only — no DOM mutation, so find can't corrupt content or trigger autosave). Match counts come back through a customonMessagepassthrough.Notes
parity:desktop-only— the crash and its fix are macOS-native-menu specific. Find-in-note on mobile (same tentap engine) and web (BlockNote) are follow-ups./code-review(xhigh) caught a critical bug before merge: theonMessagepassthrough needsexclusivelyUseCustomOnMessage={false}— tentap's default istrue, which would have suppressed tentap's own bridge and broken the editor entirely. Also fixed: a localetoLowerCase()offset overflow (IndexSizeError) → offset-safe regex match, a whitespace-query UI mismatch, and a Cmd+F-during-load race.react-native-macos 0.81.6 → 0.81.8bump (stalePodfile.lock+ areact-native-svgFabric incompatibility).mainonly builds because itsnode_modulesis frozen at 0.81.6. This PR's code compiles on that frozen toolchain; the de-fossilization will land as its own PR.Testing
pnpm --filter @drafto/desktop test— 317 pass (incl. new unit tests forparseFindResult/ the engine JS builders /FindBar, plus a jsdom runtime suite that executes the injected engine to cover case-insensitive counting, next/prev wrap, regex-literal matching, and the locale-offset fix).tsc --noEmit,eslint src/,prettier --check— all green.Drafto-macOSbuilds andDraftoMenuManager.mmcompiles with the new Find actions in the binary.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Documentation