Repository navigation
Add text replace functionality to rich markdown editor and keyboard shortcut for text replace in bindings - #6703
Conversation
…ditor The rich markdown editor's find bar was find-only, forcing users into the source editor for any replace. Add Replace / Replace All plus Match Case and Whole Word toggles in a VSCode-style two-row find widget (regex intentionally omitted). Search/replace operates on the rendered ProseMirror text, consistent with the existing find behavior.
Add an editor.replace keybinding that opens the rich editor's find bar with the replace row expanded, matching the source editor's native replace shortcut: Cmd+Alt+F on macOS, Ctrl+H on Linux/Windows. The replace toggle tooltip now shows the effective shortcut.
…he bar Closing the find/replace bar unmounted the focused search input, dropping focus to <body> — outside the editor root — so the shortcut's targetInsideEditor guard ignored the next keypress until the user clicked back into the editor. Return focus to the editor on close so the shortcut keeps working and the caret returns to the document.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe pull request adds find-and-replace functionality to the rich markdown editor. It registers a new 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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: 5
🧹 Nitpick comments (1)
src/renderer/src/assets/rich-markdown-editor.css (1)
381-381: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse existing theme tokens for the widget shadow and option states.
These
rgba(...)/color-mix(...)values introduce new visual tiers directly in the component stylesheet, so this widget can drift from the renderer theme over time. Please swap them to the existing shadow and state tokens from the shared style system instead of minting local values.As per coding guidelines,
src/renderer/src/**/*.{ts,tsx,css}should "Never invent new color values, font sizes, or shadow tiers when a documented one in STYLEGUIDE.md already covers the role."Also applies to: 439-447
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: cc965284-7bc4-4ce2-a43b-4251ac0bf449
📒 Files selected for processing (15)
src/renderer/src/assets/rich-markdown-editor.csssrc/renderer/src/components/editor/RichMarkdownEditor.tsxsrc/renderer/src/components/editor/RichMarkdownEditorSurface.tsxsrc/renderer/src/components/editor/RichMarkdownSearchBar.tsxsrc/renderer/src/components/editor/markdown-preview-search.test.tssrc/renderer/src/components/editor/markdown-preview-search.tssrc/renderer/src/components/editor/rich-markdown-search.test.tssrc/renderer/src/components/editor/rich-markdown-search.tssrc/renderer/src/components/editor/useRichMarkdownSearch.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/shared/keybindings.ts
AmethystLiang
left a comment
There was a problem hiding this comment.
Thanks, this is a solid editor usability improvement. I added a small review follow-up to harden replace against the search debounce and make whole-word matching Unicode-safe around astral code points, plus shortcut/Unicode regression tests.
Validated with typecheck, lint, targeted tests, and Electron rich-markdown replace flows.
Adds replace, replace all, match case, whole word, and the editor replace shortcut to the rich markdown editor. Includes review hardening for live replace matching and Unicode-safe whole-word boundaries.
Summary
The rich markdown editor's find bar was find-only, forcing users into the source editor for any replace. Add Replace / Replace All plus Match Case and Whole Word toggles in a VSCode-style two-row find widget (regex intentionally omitted). Search/replace operates on the rendered ProseMirror text, consistent with the existing find behavior.
Aa) and Match whole word (ab) toggles⌘⌥FonmacOS,
Ctrl+Hon Linux/Windows (rebindable in Settings -> Shortcuts)Xor
Esc) until the editor was re-clicked. Now focus returns to the editor onclose, so the shortcut keeps working
Screenshots
Testing
pnpm lintpnpm typecheckpnpm test-22,046 passed | 28 skippedpnpm buildAdded unit tests for the match engine:
matchCase,wholeWord, thecombination of both, and Unicode/underscore word boundaries, plus option
pass-through in the rich-editor match finder, and verified the new
editor.replacekeybinding has no conflicts. The close-focus fix and UI wiringare not separately unit-tested: this module's tests are pure-function only, and
there is no existing harness that mounts the hook with a live Tiptap editor and
real DOM focus (which is what verifying focus restoration would require).
Verified manually in-app.
AI Review Report
Reviewed the diff for correctness, cross-platform safety, and performance:
Replace Allprocesses matches in reverse so earlierpositions aren't invalidated;
Replaceleaves the active index in place sothe next match shifts into it after recompute. Empty replacement uses
tr.deletebecause ProseMirror text nodes can't hold an empty string. Togglebuttons
preventDefaulton mousedown so focus stays in the search input andmatch navigation keeps working. Decorations recompute via the existing
debounced revision path after each edit. The close-focus fix routes every
close path (
X, Escape in either input, window-level Escape) through onecloseSearchthat restores editor focus.metaKey— the neweditor.replacebinding resolvesMod→ Cmd/Ctrl per platform (⌘⌥F/Ctrl+H), and the registry's exact-modifier matcher was verified not tocollide with
editor.find. Shortcut is handled via a window-capture listenerso
Ctrl+Hcan't fall through to a ProseMirror delete. Shortcut label in thetooltip is platform-formatted. No file paths, shell, or Electron-specific code
touched; CSS uses existing design tokens.
in-memory ProseMirror document in the renderer — no assumption of local
execution, so behavior is identical over SSH/remote worktrees.
Replace Allis a single dispatch/undo step. No hot-path regressions.Security Audit
existing 2KB query cap. Regex was intentionally not added, so no user input is
compiled into a regex — no ReDoS surface. The whole-word check uses a fixed
/[\p{L}\p{N}_]/uclass tested against single characters.tr.insertText/tr.deleteas plain text — no HTML/markdown is interpreted, so no markup injection.
dependencies. The new
editor.replaceaction is a renderer-scoped keybinding.Localization keys were synced into
en/es/ja/ko/zhvia the repo's catalogscript.