Skip to content

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

Open
Nivet2006 wants to merge 2 commits into
erictli:mainfrom
Nivet2006:main
Open

Add Find & Replace functionality with Replace and Replace All actions#180
Nivet2006 wants to merge 2 commits into
erictli:mainfrom
Nivet2006:main

Conversation

@Nivet2006

@Nivet2006 Nivet2006 commented Jun 22, 2026

Copy link
Copy Markdown

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4606e145-fb34-4104-9987-630967b9e2d2

📥 Commits

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

📒 Files selected for processing (2)
  • src/components/editor/Editor.tsx
  • src/components/editor/SearchToolbar.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/components/editor/SearchToolbar.tsx
  • src/components/editor/Editor.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
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

1 participant