Skip to content

Add text replace functionality to rich markdown editor and keyboard shortcut for text replace in bindings - #6703

Merged
AmethystLiang merged 5 commits into
stablyai:mainfrom
Jingyue-Wu:Jingyue-Wu/find-replace-markdown-editor
Jun 29, 2026
Merged

AmethystLiang merged 5 commits into
stablyai:mainfrom
Jingyue-Wu:Jingyue-Wu/find-replace-markdown-editor

Conversation

@Jingyue-Wu

Copy link
Copy Markdown
Contributor

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.

  • Replace and Replace All
  • Match case (Aa) and Match whole word (ab) toggles
  • Keyboard shortcut to open replace, matching the source editor: ⌘⌥F on
    macOS, Ctrl+H on Linux/Windows (rebindable in Settings -> Shortcuts)
  • Bug fix: the find shortcut stopped working after closing the bar (via X
    or Esc) until the editor was re-clicked. Now focus returns to the editor on
    close, so the shortcut keeps working

Screenshots

image

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test -22,046 passed | 28 skipped
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Added unit tests for the match engine: matchCase, wholeWord, the
combination of both, and Unicode/underscore word boundaries, plus option
pass-through in the rich-editor match finder, and verified the new
editor.replace keybinding has no conflicts. The close-focus fix and UI wiring
are 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:

  • Correctness: Replace All processes matches in reverse so earlier
    positions aren't invalidated; Replace leaves the active index in place so
    the next match shifts into it after recompute. Empty replacement uses
    tr.delete because ProseMirror text nodes can't hold an empty string. Toggle
    buttons preventDefault on mousedown so focus stays in the search input and
    match 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 one
    closeSearch that restores editor focus.
  • Cross-platform (macOS / Linux / Windows): No hardcoded metaKey — the new
    editor.replace binding resolves Mod → Cmd/Ctrl per platform (⌘⌥F /
    Ctrl+H), and the registry's exact-modifier matcher was verified not to
    collide with editor.find. Shortcut is handled via a window-capture listener
    so Ctrl+H can't fall through to a ProseMirror delete. Shortcut label in the
    tooltip is platform-formatted. No file paths, shell, or Electron-specific code
    touched; CSS uses existing design tokens.
  • SSH / remote: Search/replace and focus handling run entirely on the
    in-memory ProseMirror document in the renderer — no assumption of local
    execution, so behavior is identical over SSH/remote worktrees.
  • Performance: Match computation stays debounced (150ms) and size-capped;
    Replace All is a single dispatch/undo step. No hot-path regressions.

Security Audit

  • Input handling: Search and replace strings are user text bounded by the
    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}_]/u class tested against single characters.
  • Injection: Replacement text is inserted via tr.insertText / tr.delete
    as plain text — no HTML/markdown is interpreted, so no markup injection.
  • Other: No command execution, path handling, IPC, auth, secrets, or new
    dependencies. The new editor.replace action is a renderer-scoped keybinding.
    Localization keys were synced into en/es/ja/ko/zh via the repo's catalog
    script.

…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.
@Jingyue-Wu Jingyue-Wu changed the title Add text replace functionality to rich markdown editor Add text replace functionality to rich markdown editor and keyboard shortcut for text replace in bindings Jun 29, 2026
@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bc8afa72-d2b3-485f-b4e9-aa25c6e2d2db

📥 Commits

Reviewing files that changed from the base of the PR and between fa92fe9 and b4643f6.

📒 Files selected for processing (4)
  • src/renderer/src/components/editor/markdown-preview-search.test.ts
  • src/renderer/src/components/editor/markdown-preview-search.ts
  • src/renderer/src/components/editor/useRichMarkdownSearch.ts
  • src/shared/keybindings.test.ts
✅ Files skipped from review due to trivial changes (1)
  • src/shared/keybindings.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/editor/markdown-preview-search.ts
  • src/renderer/src/components/editor/useRichMarkdownSearch.ts

📝 Walkthrough

Walkthrough

The pull request adds find-and-replace functionality to the rich markdown editor. It registers a new editor.replace keybinding, extends text matching with matchCase and wholeWord options, and adds replace-mode state and actions to useRichMarkdownSearch. The editor surface and search bar props are updated to support replace controls, option toggles, and replace actions. CSS and localization files are updated for the new search UI.

🚥 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
Title check ✅ Passed The title clearly summarizes the main change: adding replace functionality and a replace shortcut to the rich markdown editor.
Description check ✅ Passed The description covers the required summary, screenshots, testing, AI review, and security audit sections, with only the optional Notes section missing.
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.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (1)
src/renderer/src/assets/rich-markdown-editor.css (1)

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

Use 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

📥 Commits

Reviewing files that changed from the base of the PR and between 61bb2f9 and fa92fe9.

📒 Files selected for processing (15)
  • src/renderer/src/assets/rich-markdown-editor.css
  • src/renderer/src/components/editor/RichMarkdownEditor.tsx
  • src/renderer/src/components/editor/RichMarkdownEditorSurface.tsx
  • src/renderer/src/components/editor/RichMarkdownSearchBar.tsx
  • src/renderer/src/components/editor/markdown-preview-search.test.ts
  • src/renderer/src/components/editor/markdown-preview-search.ts
  • src/renderer/src/components/editor/rich-markdown-search.test.ts
  • src/renderer/src/components/editor/rich-markdown-search.ts
  • src/renderer/src/components/editor/useRichMarkdownSearch.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/shared/keybindings.ts

Comment thread src/renderer/src/i18n/locales/ja.json Resolved
Comment thread src/renderer/src/i18n/locales/zh.json Resolved
@AmethystLiang
AmethystLiang self-requested a review June 29, 2026 05:38

@AmethystLiang AmethystLiang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@AmethystLiang
AmethystLiang merged commit 5807ba8 into stablyai:main Jun 29, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.
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