Skip to content

Add Find & Replace functionality with Replace and Replace All actions - #180

Merged
erictli merged 5 commits into
erictli:mainfrom
Nivet2006:main
Jul 28, 2026
Merged

Add Find & Replace functionality with Replace and Replace All actions#180
erictli merged 5 commits into
erictli:mainfrom
Nivet2006:main

Conversation

@Nivet2006

@Nivet2006 Nivet2006 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds Find & Replace functionality to the editor.

Features Added

  • Find text within the current document
  • Replace the currently selected match
  • Replace all occurrences of the searched text
  • Separate controls for "Replace" and "Replace All"

Benefits

  • Faster text editing workflow
  • Easier bulk text modifications
  • Improved editor usability

Screenshot

image

Closes #173

Summary by CodeRabbit

  • New Features

    • Added replace mode to the editor’s in-note search, including single replace and replace-all actions.
    • Added keyboard shortcuts to open search (Cmd/Ctrl+F) and open the replace panel (Cmd/Ctrl+H).
    • Updated the search toolbar UI with an expandable “Replace” section and improved match status display.
  • Bug Fixes

    • Ensured search/replace state is cleared when switching notes.
  • Chores

    • Updated development server host configuration for local access.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@erictli, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 35 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 50cd614e-6c83-4410-9979-cacde4f658f5

📥 Commits

Reviewing files that changed from the base of the PR and between db19095 and a1746f1.

📒 Files selected for processing (2)
  • src/components/editor/Editor.tsx
  • src/components/icons/index.tsx
📝 Walkthrough

Walkthrough

Adds find-and-replace to the in-note search: new ReplaceIcon/ReplaceAllIcon SVGs, expanded SearchToolbarProps, replaceCurrent and replaceAll ProseMirror callbacks in Editor, a Cmd/Ctrl+H shortcut to open the replace panel, and a conditional replace row in SearchToolbar. Also changes the Vite/Tauri dev server host from localhost to 127.0.0.1.

Changes

Find-and-Replace Feature

Layer / File(s) Summary
New icons and SearchToolbarProps contract
src/components/icons/index.tsx, src/components/editor/SearchToolbar.tsx
ReplaceIcon and ReplaceAllIcon SVG components added; SearchToolbarProps extended with replaceQuery, onReplaceChange, onReplace, onReplaceAll, isReplaceOpen, and onToggleReplace.
Editor replace state, callbacks, and keyboard shortcuts
src/components/editor/Editor.tsx
Adds replaceQuery/isReplaceOpen state, replaceCurrent and replaceAll ProseMirror callbacks, expands the keydown handler for Cmd/Ctrl+H, clears replace state on note switch and toolbar close, and wires all replace props to SearchToolbar.
SearchToolbar replace UI rendering
src/components/editor/SearchToolbar.tsx
Adds handleReplaceKeyDown for modifier-aware Enter/Escape/Tab; reworks first row with a chevron replace-toggle button and updated match counter; conditionally renders a replace input row with Replace and Replace All buttons when isReplaceOpen is true.

Dev Server Host Fix

Layer / File(s) Summary
Vite and Tauri dev server host alignment
vite.config.ts, src-tauri/tauri.conf.json
server.host fallback changed from false to "127.0.0.1"; devUrl updated from http://localhost:1420 to http://127.0.0.1:1420.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Editor
  participant ProseMirror
  participant SearchToolbar

  rect rgba(100, 149, 237, 0.5)
    note over User,SearchToolbar: Open Replace Panel
    User->>Editor: Cmd/Ctrl+H
    Editor->>Editor: setIsSearchOpen(true), setIsReplaceOpen(true)
    Editor->>SearchToolbar: render replace row (isReplaceOpen=true)
  end

  rect rgba(144, 238, 144, 0.5)
    note over User,ProseMirror: Replace Current Match
    User->>SearchToolbar: type replaceQuery, click Replace
    SearchToolbar->>Editor: onReplace()
    Editor->>ProseMirror: dispatch transaction (replace active match)
    ProseMirror-->>Editor: updated doc
    Editor->>Editor: recompute matches, update decorations
  end

  rect rgba(255, 179, 71, 0.5)
    note over User,ProseMirror: Replace All Matches
    User->>SearchToolbar: click Replace All
    SearchToolbar->>Editor: onReplaceAll()
    Editor->>ProseMirror: dispatch transaction (all matches in reverse)
    ProseMirror-->>Editor: updated doc
    Editor->>Editor: recompute matches, reset to first match
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hop hop! No more searching in vain,
A replace row appears — what a gain!
Ctrl+H opens the door,
Swap text, one or more,
And 127.0.0.1? Yes, that's the right lane! 🔍✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

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.
Out of Scope Changes check ❓ Inconclusive Changes to tauri.conf.json and vite.config.ts (localhost to 127.0.0.1) appear to be configuration adjustments potentially supporting the find-replace feature but are not directly related to #173's core requirements. Clarify whether configuration changes to devUrl and server.host are necessary for the find-replace functionality or if they should be in a separate PR for infrastructure updates.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and accurately summarizes the primary change: adding Find & Replace functionality with Replace and Replace All actions.
Linked Issues check ✅ Passed The PR successfully implements the find-and-replace functionality requested in #173, including replace current match and replace all occurrences capabilities.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

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

@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/components/editor/Editor.tsx`:
- Around line 1310-1330: In the replaceCurrent callback function, the nextIndex
calculation uses currentMatchIndex % newMatches.length which does not advance to
the next match when the replacement text contains the search query, causing the
replacement to target the same match repeatedly. Change the nextIndex
calculation from currentMatchIndex % newMatches.length to (currentMatchIndex +
1) % newMatches.length to ensure the function advances to the next match after
each replacement instead of potentially staying on the same location.

In `@src/components/editor/SearchToolbar.tsx`:
- Around line 73-79: The handleReplaceKeyDown function in SearchToolbar.tsx
currently triggers onReplaceAll when the user presses Enter with metaKey,
ctrlKey, or altKey modifiers. However, Alt+Enter should not trigger replace-all,
only Cmd/Ctrl+Enter should. Remove the e.altKey check from the conditional
statement in handleReplaceKeyDown that calls onReplaceAll, keeping only the
e.metaKey and e.ctrlKey checks. Apply the same fix to the similar location
mentioned at lines 165-169 where the same pattern exists.
🪄 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: e2f195ef-7333-4412-8a87-87c5dc8f338c

📥 Commits

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

📒 Files selected for processing (5)
  • src-tauri/tauri.conf.json
  • src/components/editor/Editor.tsx
  • src/components/editor/SearchToolbar.tsx
  • src/components/icons/index.tsx
  • vite.config.ts

Comment thread src/components/editor/Editor.tsx Outdated
Comment thread src/components/editor/SearchToolbar.tsx
Nivet2006 and others added 4 commits June 23, 2026 08:32
Cmd+H is reserved by macOS for Hide (bound in the default app menu), so
the replace shortcut follows platform convention: Option+Cmd+F on macOS,
Ctrl+H on Windows/Linux. Also reuses openEditorSearch instead of
duplicating the open-and-focus logic.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Restores localhost/default host binding; the 127.0.0.1 override was a
local-environment workaround unrelated to find & replace.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The custom icons read as "open in new window"; these are the standard
Lucide glyphs, matching the icon set used across the app.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@erictli erictli left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you!

@erictli
erictli merged commit e026667 into erictli:main Jul 28, 2026
2 checks passed
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.

Feature Request: Adding match and replace

2 participants