Skip to content

feat(code-mirror-search): add replace and replace-all with search position, debouncing and tests - #8585

Closed
sachin-thakur-bruno wants to merge 7 commits into
usebruno:release/v4.1.0from
sachin-thakur-bruno:feat/code-mirror-replace-all
Closed

sachin-thakur-bruno wants to merge 7 commits into
usebruno:release/v4.1.0from
sachin-thakur-bruno:feat/code-mirror-replace-all

Conversation

@sachin-thakur-bruno

@sachin-thakur-bruno sachin-thakur-bruno commented Jul 13, 2026 •

Copy link
Copy Markdown
Collaborator

Description

JIRA

Curently users can only search a text in codemirror. There is no option to replace the selected text.

Adding replace and replace all feature in code mirror. Users can select a text for search and can replace the selected text by replace one-by-one or replace all. Adding the keyboard shortcuts for opening the serach and replace.

Screen.Recording.2026-06-16.at.3.39.41.PM.mov

CodeMirrorSearch/index.js

Replace functionality

  • Added replaceText state and replaceVisible toggle
  • handleReplace — replaces the current match via editor.replaceRange, invalidates the search cache, and re-runs search at the same index
  • handleReplaceAll — replaces all matches in reverse order (to preserve character positions) inside editor.operation() for a single undo step

Layout

  • Chevron (IconChevronRight) extracted as a full-height left column — spans both rows when expanded, matching VS Code's widget
  • Rows restructured into .toggle-replace-btn + .search-replace-rows (column of .search-row / .replace-row)
  • Replace action buttons use IconReplace and IconArrowsExchange2 with ToolHint tooltips

Keyboard & focus

  • Native keydown listener attached in the capture phase ({ capture: true }) on the container — ensures Escape is intercepted before CodeMirror or the browser can act on it
  • type="button" added to all buttons for correct focusability

Imperative handle — exposes four methods via useImperativeHandle:

Method Purpose
focus() Focus the search input
setSearch(text) Set search text, reset match index, focus and select input
openReplace() Expand replace row and focus replace input
close() Clean up marks, collapse replace, call onClose

CodeMirrorSearch/StyledWrapper.js

  • Container changed to flex-direction: row — chevron column on the left, rows column on the right
  • .toggle-replace-btn uses align-self: stretch for full-height
  • Each input has its own border box, fixed 180px width — both rows visually identical
  • .search-row gets a border-bottom only when replace is expanded
  • Removed .searchbar-text-btn styles (replaced by icon buttons)

CodeEditor/index.js

Cmd/Ctrl+H — replaced 'replace' string command with a handler that opens the search bar and calls searchBarRef.current?.openReplace()

Cmd/Ctrl+F — updated to check cm.getSelection():

  • Selection present → calls setSearch(selectedText) to prefill and re-run search (works whether bar is open or closed)
  • No selection → calls focus() to move cursor to the input without clearing existing search text

Esc extraKey — updated from bare setState to searchBarRef.current?.close() so marks are properly cleaned up when Esc is pressed while the editor has focus

Performance Improvements

1. Only highlight what's visible

The search still finds all matches in the document, but it only creates highlights (markText()) for matches that are currently visible in the editor (plus a small buffer of ±100 lines). The currently selected match is always highlighted, even if it's outside the viewport.

For example, in a 10,000-line file with 500 matches, the editor typically creates only 5–10 highlights instead of 500, significantly reducing DOM work. As you scroll, old highlights are removed and new ones are drawn for the visible area.

Files

  • components/CodeMirrorSearch/markingUtils.js

2. Cache search results

Scanning the entire document with CodeMirror's getSearchCursor() can be expensive on large files.

Search results are cached and reused until something that affects the results changes:

  • Document content
  • Search text
  • Regex mode
  • Case sensitivity
  • Whole-word mode

This means actions like Next, Previous, scrolling, or component re-renders reuse the existing match list instead of rescanning the document every time.

Files

  • components/CodeMirrorSearch/searchUtils.js (createCacheKey)
  • components/CodeMirrorSearch/index.js (searchCacheKey, isCacheHit)

3. Debounce search while typing

Instead of performing a full document scan on every keystroke, the search waits until the user stops typing for 250 ms before running.

Typing stays responsive because intermediate keystrokes only update the input field without triggering an expensive search.

Files

  • components/CodeMirrorSearch/index.js (useDebounce(searchText, 250))

4. Jump directly to visible matches

When drawing highlights, the code uses a binary search to quickly locate the first match inside the current viewport instead of checking every match from the beginning.

This reduces the work from scanning the entire match list to only processing the matches that are actually visible.

Files

  • components/CodeMirrorSearch/markingUtils.js

5. Limit extremely large searches

To avoid freezing the UI on pathological searches (for example, searching for a single character in a very large minified file), the search stops after 99,999 matches.

This provides a reasonable safety limit while still supporting very large result sets.

Files

  • components/CodeMirrorSearch/searchUtils.js (MAX_MATCHES)

6. Scroll only when it makes sense

Searching no longer automatically scrolls the editor every time results are updated.

The editor scrolls only when explicitly requested, such as:

  • Next / Previous
  • Replace
  • Opening search with selected text

It does not scroll during:

  • Debounced searches while typing
  • Automatic re-scans after document changes
  • Reopening the search bar

This prevents the editor from unexpectedly jumping away from the user's current position.

Files

  • components/CodeMirrorSearch/index.js (doSearch(..., shouldScroll = false))

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • New Features
    • Improved editor Search/Replace UX: opens based on current selection/cursor, adds robust match navigation, and enhances Replace/Replace all interactions (with read-only safeguards).
    • Refined Search/Replace layout and controls, including a dedicated replace toggle and clearer keyboard behavior.
  • Bug Fixes
    • Stabilized match counting/highlighting through typing and document edits, with reliable close/dismiss behavior (including Escape).
  • Tests
    • Added unit tests for search/replace utilities and the search component, plus Playwright E2E coverage for large-document behavior, state persistence, and viewport stability.
  • Documentation
    • Added a targeted test identifier for the documentation editor UI.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The CodeMirror search component was refactored into reusable utilities. Search, replace, highlighting, keyboard interactions, editor integration, read-only behavior, styling, and unit and end-to-end coverage were expanded.

Changes

Search and Replace

Layer / File(s) Summary
Search, marking, and replacement utilities
packages/bruno-app/src/components/CodeMirrorSearch/{searchUtils,markingUtils,replaceUtils}.*
Search matching, cache keys, viewport highlighting, single replacement, and replace-all behavior were extracted and tested.
Search component orchestration
packages/bruno-app/src/components/CodeMirrorSearch/{index.js,StyledWrapper.js,CodeMirrorSearch.spec.jsx}
Search state, navigation, document changes, imperative controls, replacement interactions, keyboard handling, and replace-mode styling were updated and tested.
Editor integration and end-to-end validation
packages/bruno-app/src/components/{CodeEditor,FileEditor/CodeEditor,Documentation}/*, tests/{code-editor,utils/page}/*
Editor shortcuts, closing behavior, read-only wiring, test identifiers, reusable Playwright helpers, and full search/replace workflows were covered.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested reviewers: helloanoop, lohit-bruno, bijin-bruno, naman-bruno, sid-bruno

Poem

Search lights bloom where cursors roam,
Matches march and wrap back home.
Replace one, or replace them all,
Escape closes the toolbar’s call.
CodeMirror hums, precise and bright. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.67% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change set: replace/replace-all support plus search positioning, debouncing, and tests.
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.
✨ 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
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/bruno-app/src/components/FileEditor/CodeEditor/index.js (1)

97-110: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Cmd-H/Ctrl-H should match the new replace flow. These bindings still map to CodeMirror’s built-in 'replace' command, while Cmd-Alt-F/Ctrl-Alt-F use openReplace(). Align them with packages/bruno-app/src/components/CodeEditor/index.js.

🤖 Prompt for 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.

In `@packages/bruno-app/src/components/FileEditor/CodeEditor/index.js` around
lines 97 - 110, Update the Cmd-H and Ctrl-H keybindings in the CodeEditor
component to use the same replace flow as Cmd-Alt-F and Ctrl-Alt-F: honor
readOnly, show the search bar, focus searchBarRef, and call openReplace(). Match
the implementation used by the other CodeEditor component instead of mapping
these keys to CodeMirror’s built-in replace command.
🧹 Nitpick comments (2)
tests/code-editor/search-replace.spec.ts (2)

31-31: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Hardcoded waitForTimeout(50) after setting editor content.

Consider waiting on an observable signal (e.g. an updated match count or exposed doc-version testid) instead of a fixed sleep, to avoid flakiness under CI load.

As per path instructions: "Try to reduce usage of page.waitForTimeout(); in code unless absolutely necessary and the locator cannot be found using existing expect() playwright calls."

🤖 Prompt for 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.

In `@tests/code-editor/search-replace.spec.ts` at line 31, Replace the fixed
page.waitForTimeout(50) after setting editor content with an observable
Playwright wait, such as an expect assertion on the updated match count or
exposed document-version testid. Reuse an existing locator and wait for the
editor update to complete before continuing the test.

Source: Path instructions


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

No test.step usage across the suite.

None of the ~20 tests use test.step to break down arrange/act/assert phases, even though most have a clear multi-step shape (e.g. Lines 167-176, 308-321).

As per path instructions: "Promote the use of test.step as much as possible so the generated reports are easier to read."

🤖 Prompt for 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.

In `@tests/code-editor/search-replace.spec.ts` around lines 104 - 361, Organize
the multi-phase tests in the search/replace suite with test.step blocks for
setup, actions, and assertions, prioritizing flows such as “reopening restores
previous search text...” and “match count updates when the document is edited
while search is open.” Apply the same structure across the suite where steps are
clearly separable, using descriptive step names while preserving the existing
test behavior and assertions.

Source: Path instructions

🤖 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 `@packages/bruno-app/src/components/CodeMirrorSearch/index.js`:
- Around line 369-377: Add accessible names to the regex, case-sensitive, and
whole-word toggle buttons in CodeMirrorSearch by adding descriptive aria-label
or title attributes, matching the naming behavior of the neighboring
prev/next/close buttons.

In `@tests/code-editor/search-replace.spec.ts`:
- Around line 18-79: Move the locators and interactions used by
openScriptEditor, setEditorContent, resetSearchOptions, openSearchBar,
openReplaceBar, and closeSearchBar into the appropriate page module under
tests/utils/page/*. Update the spec helpers to call those page-module actions,
keeping expectMatchCount’s assertion in the spec while obtaining its locator
through the page module; ensure actions synchronize with waits and do not call
expect.

---

Outside diff comments:
In `@packages/bruno-app/src/components/FileEditor/CodeEditor/index.js`:
- Around line 97-110: Update the Cmd-H and Ctrl-H keybindings in the CodeEditor
component to use the same replace flow as Cmd-Alt-F and Ctrl-Alt-F: honor
readOnly, show the search bar, focus searchBarRef, and call openReplace(). Match
the implementation used by the other CodeEditor component instead of mapping
these keys to CodeMirror’s built-in replace command.

---

Nitpick comments:
In `@tests/code-editor/search-replace.spec.ts`:
- Line 31: Replace the fixed page.waitForTimeout(50) after setting editor
content with an observable Playwright wait, such as an expect assertion on the
updated match count or exposed document-version testid. Reuse an existing
locator and wait for the editor update to complete before continuing the test.
- Around line 104-361: Organize the multi-phase tests in the search/replace
suite with test.step blocks for setup, actions, and assertions, prioritizing
flows such as “reopening restores previous search text...” and “match count
updates when the document is edited while search is open.” Apply the same
structure across the suite where steps are clearly separable, using descriptive
step names while preserving the existing test behavior and assertions.
🪄 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: CHILL

Plan: Pro

Run ID: 2fe01ac7-53c3-49db-ad44-d325dd347ba1

📥 Commits

Reviewing files that changed from the base of the PR and between b382a65 and bdd553a.

📒 Files selected for processing (12)
  • packages/bruno-app/src/components/CodeEditor/index.js
  • packages/bruno-app/src/components/CodeMirrorSearch/CodeMirrorSearch.spec.jsx
  • packages/bruno-app/src/components/CodeMirrorSearch/StyledWrapper.js
  • packages/bruno-app/src/components/CodeMirrorSearch/index.js
  • packages/bruno-app/src/components/CodeMirrorSearch/markingUtils.js
  • packages/bruno-app/src/components/CodeMirrorSearch/replaceUtils.js
  • packages/bruno-app/src/components/CodeMirrorSearch/replaceUtils.spec.js
  • packages/bruno-app/src/components/CodeMirrorSearch/searchUtils.js
  • packages/bruno-app/src/components/CodeMirrorSearch/searchUtils.spec.js
  • packages/bruno-app/src/components/Documentation/index.js
  • packages/bruno-app/src/components/FileEditor/CodeEditor/index.js
  • tests/code-editor/search-replace.spec.ts

Comment on lines +369 to +377
<ToolHint text="Regex search" toolhintId="searchbar-regex-toolhint" place="top">
<button type="button" className={`searchbar-icon-btn ${regex ? 'active' : ''}`} onClick={handleToggleRegex} data-testid="search-regex-btn"><IconRegex size={16} /></button>
</ToolHint>
<ToolHint text="Case sensitive" toolhintId="searchbar-case-toolhint" place="top">
<button type="button" className={`searchbar-icon-btn ${caseSensitive ? 'active' : ''}`} onClick={handleToggleCase} data-testid="search-case-btn"><IconLetterCase size={14} /></button>
</ToolHint>
<ToolHint text="Whole word" toolhintId="searchbar-wholeword-toolhint" place="top">
<button type="button" className={`searchbar-icon-btn ${wholeWord ? 'active' : ''}`} onClick={handleToggleWholeWord} data-testid="search-wholeword-btn"><IconLetterW size={14} /></button>
</ToolHint>

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add accessible names to the toggle buttons.

prev/next/close carry title, but the regex, case-sensitive, and whole-word buttons have neither title nor aria-label, so screen readers announce them without a name. Add aria-label (or title) to match the sibling buttons.

♿ Proposed fix
-              <button type="button" className={`searchbar-icon-btn ${regex ? 'active' : ''}`} onClick={handleToggleRegex} data-testid="search-regex-btn"><IconRegex size={16} /></button>
+              <button type="button" aria-label="Regex search" className={`searchbar-icon-btn ${regex ? 'active' : ''}`} onClick={handleToggleRegex} data-testid="search-regex-btn"><IconRegex size={16} /></button>

(apply the same for the case-sensitive and whole-word buttons)

🤖 Prompt for 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.

In `@packages/bruno-app/src/components/CodeMirrorSearch/index.js` around lines 369
- 377, Add accessible names to the regex, case-sensitive, and whole-word toggle
buttons in CodeMirrorSearch by adding descriptive aria-label or title
attributes, matching the naming behavior of the neighboring prev/next/close
buttons.

@sachin-thakur-bruno
sachin-thakur-bruno force-pushed the feat/code-mirror-replace-all branch from bdd553a to 384e59c Compare July 13, 2026 12:51
@sachin-thakur-bruno
sachin-thakur-bruno force-pushed the feat/code-mirror-replace-all branch from 384e59c to 5ea98c9 Compare July 13, 2026 13:00

@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: 1

🧹 Nitpick comments (1)
packages/bruno-app/src/components/CodeMirrorSearch/replaceUtils.spec.js (1)

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

Cover a match that spans a newline.

This test uses two single-line matches, leaving the to.line offset path untested.

Proposed test
+  it('replaces a match spanning multiple lines', () => {
+    const editor = makeEditor('foo\nbar');
+    const matches = [
+      { from: { line: 0, ch: 1 }, to: { line: 1, ch: 2 } }
+    ];
+
+    replaceAll(editor, matches, 'X');
+
+    expect(editor.replaceRange.mock.calls[0][0]).toBe('fXr');
+  });

As per coding guidelines, “Cover both the happy path and the realistically problematic paths.”

🤖 Prompt for 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.

In `@packages/bruno-app/src/components/CodeMirrorSearch/replaceUtils.spec.js`
around lines 78 - 86, Extend the replacement test around replaceAll to use a
single match whose from and to positions span different lines, exercising the
to.line offset calculation. Assert that replaceRange receives the expected
multiline replacement while preserving the existing single-line replacement
coverage.

Source: Coding guidelines

🤖 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 `@packages/bruno-app/src/components/CodeMirrorSearch/index.js`:
- Around line 50-57: Reset searchCacheKey.current in the empty-text branch
alongside searchMatches.current and the other search state resets. This ensures
re-entering the same term with the same docVersion performs a fresh search
instead of reusing the cleared cache.

---

Nitpick comments:
In `@packages/bruno-app/src/components/CodeMirrorSearch/replaceUtils.spec.js`:
- Around line 78-86: Extend the replacement test around replaceAll to use a
single match whose from and to positions span different lines, exercising the
to.line offset calculation. Assert that replaceRange receives the expected
multiline replacement while preserving the existing single-line replacement
coverage.
🪄 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: CHILL

Plan: Pro

Run ID: da099788-ab95-4896-8b3f-c359438be1db

📥 Commits

Reviewing files that changed from the base of the PR and between bdd553a and 384e59c.

📒 Files selected for processing (12)
  • packages/bruno-app/src/components/CodeEditor/index.js
  • packages/bruno-app/src/components/CodeMirrorSearch/CodeMirrorSearch.spec.jsx
  • packages/bruno-app/src/components/CodeMirrorSearch/StyledWrapper.js
  • packages/bruno-app/src/components/CodeMirrorSearch/index.js
  • packages/bruno-app/src/components/CodeMirrorSearch/markingUtils.js
  • packages/bruno-app/src/components/CodeMirrorSearch/replaceUtils.js
  • packages/bruno-app/src/components/CodeMirrorSearch/replaceUtils.spec.js
  • packages/bruno-app/src/components/CodeMirrorSearch/searchUtils.js
  • packages/bruno-app/src/components/CodeMirrorSearch/searchUtils.spec.js
  • packages/bruno-app/src/components/Documentation/index.js
  • packages/bruno-app/src/components/FileEditor/CodeEditor/index.js
  • tests/code-editor/search-replace.spec.ts
🚧 Files skipped from review as they are similar to previous changes (8)
  • packages/bruno-app/src/components/Documentation/index.js
  • packages/bruno-app/src/components/CodeMirrorSearch/CodeMirrorSearch.spec.jsx
  • packages/bruno-app/src/components/FileEditor/CodeEditor/index.js
  • packages/bruno-app/src/components/CodeMirrorSearch/StyledWrapper.js
  • packages/bruno-app/src/components/CodeMirrorSearch/markingUtils.js
  • packages/bruno-app/src/components/CodeMirrorSearch/searchUtils.spec.js
  • packages/bruno-app/src/components/CodeEditor/index.js
  • tests/code-editor/search-replace.spec.ts

@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: 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 `@packages/bruno-app/src/components/CodeMirrorSearch/index.js`:
- Around line 283-293: Update handleNext and handlePrev in the CodeMirror search
component so navigation is blocked while the current query differs from
debouncedSearchText, preventing stale searchMatches.current results from being
used. Ensure pressing Enter after editing either searches the current input
immediately or otherwise waits until both query values match before navigating.
- Around line 196-207: Update the useEffect handling initialIndexRef so a
pending initial search that no longer matches debouncedSearchText is cleared,
allowing subsequent searches to enter the normal cursor-based doSearch path.
Preserve the existing indexed search and cleanup when forText matches.

In `@packages/bruno-app/src/components/CodeMirrorSearch/searchUtils.js`:
- Line 1: Update MAX_MATCHES and the match-producing logic used by
handleReplaceAll so replaceAll never receives a truncated list; either scan and
collect all matches for replacement or detect truncation and block Replace all
with the existing appropriate failure behavior. Preserve the cap for ordinary
search results if needed, but ensure handleReplaceAll can distinguish complete
results from capped results.
🪄 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: CHILL

Plan: Pro

Run ID: 0aadb618-8bb6-4b6c-9f17-b1b84cf7fd92

📥 Commits

Reviewing files that changed from the base of the PR and between 384e59c and 5ea98c9.

📒 Files selected for processing (12)
  • packages/bruno-app/src/components/CodeEditor/index.js
  • packages/bruno-app/src/components/CodeMirrorSearch/CodeMirrorSearch.spec.jsx
  • packages/bruno-app/src/components/CodeMirrorSearch/StyledWrapper.js
  • packages/bruno-app/src/components/CodeMirrorSearch/index.js
  • packages/bruno-app/src/components/CodeMirrorSearch/markingUtils.js
  • packages/bruno-app/src/components/CodeMirrorSearch/replaceUtils.js
  • packages/bruno-app/src/components/CodeMirrorSearch/replaceUtils.spec.js
  • packages/bruno-app/src/components/CodeMirrorSearch/searchUtils.js
  • packages/bruno-app/src/components/CodeMirrorSearch/searchUtils.spec.js
  • packages/bruno-app/src/components/Documentation/index.js
  • packages/bruno-app/src/components/FileEditor/CodeEditor/index.js
  • tests/code-editor/search-replace.spec.ts
🚧 Files skipped from review as they are similar to previous changes (10)
  • packages/bruno-app/src/components/CodeMirrorSearch/replaceUtils.js
  • packages/bruno-app/src/components/Documentation/index.js
  • packages/bruno-app/src/components/CodeMirrorSearch/searchUtils.spec.js
  • packages/bruno-app/src/components/CodeMirrorSearch/CodeMirrorSearch.spec.jsx
  • packages/bruno-app/src/components/CodeMirrorSearch/StyledWrapper.js
  • packages/bruno-app/src/components/CodeMirrorSearch/replaceUtils.spec.js
  • tests/code-editor/search-replace.spec.ts
  • packages/bruno-app/src/components/CodeMirrorSearch/markingUtils.js
  • packages/bruno-app/src/components/FileEditor/CodeEditor/index.js
  • packages/bruno-app/src/components/CodeEditor/index.js

@sachin-thakur-bruno sachin-thakur-bruno changed the title Feat/code mirror replace all feat(code-mirror-search): add replace and replace-all with search position, debouncing and tests Jul 13, 2026
@sachin-thakur-bruno
sachin-thakur-bruno changed the base branch from main to release/v4.1.0 July 15, 2026 06:53

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

🧹 Nitpick comments (1)
tests/utils/page/code-editor-search.ts (1)

50-50: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider replacing page.waitForTimeout().

As per path instructions, try to reduce the usage of page.waitForTimeout() unless absolutely necessary. If you are just waiting for the editor DOM to reflect the newly set value, consider waiting for a specific locator state to keep the tests robust and snappy!

🤖 Prompt for 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.

In `@tests/utils/page/code-editor-search.ts` at line 50, Replace the fixed delay
after setting the editor value with an explicit wait for the relevant editor DOM
locator state in the surrounding search test. Use the existing locator and an
assertion or state condition that confirms the newly set value is reflected
before continuing, and remove the page.waitForTimeout call.

Source: Path instructions

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

Nitpick comments:
In `@tests/utils/page/code-editor-search.ts`:
- Line 50: Replace the fixed delay after setting the editor value with an
explicit wait for the relevant editor DOM locator state in the surrounding
search test. Use the existing locator and an assertion or state condition that
confirms the newly set value is reflected before continuing, and remove the
page.waitForTimeout call.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 03f3433f-b37c-414c-9da2-51636f8cd4b3

📥 Commits

Reviewing files that changed from the base of the PR and between 5ea98c9 and 48eeea5.

📒 Files selected for processing (5)
  • packages/bruno-app/src/components/CodeMirrorSearch/index.js
  • packages/bruno-app/src/components/CodeMirrorSearch/searchUtils.js
  • tests/code-editor/search-replace.spec.ts
  • tests/utils/page/code-editor-search.ts
  • tests/utils/page/index.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/bruno-app/src/components/CodeMirrorSearch/searchUtils.js
  • tests/code-editor/search-replace.spec.ts
  • packages/bruno-app/src/components/CodeMirrorSearch/index.js

this.searchBarRef.current?.openReplace();
});
},
'Ctrl-Alt-F': this.props.readOnly ? false : () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The actions for (Cmd+F or Ctrl+F), (Cmd+H or Ctrl+H), and (Cmd+Alt+F) or (Ctrl+Alt+F) have the same function implementation. Can we extract these into methods which takes in the cm instance and runs something. Helps us not drift the implementation across two bindings when some logic changes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes sure good idea. created a util and used it from there

'Esc': () => {
if (this.state.searchBarVisible) {
this.setState({ searchBarVisible: false });
this.searchBarRef.current?.close();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we need the null/undefined check here with ?? Isn't it always available when the searchBarVisible is true?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes it will be there but since we don't have typescript currently here its added for safety. Also ?. costs nothing at runtime and protects against any edge case where the ref hasn't been committed yet

const marks = [];
return {
getSearchCursor: jest.fn(() => {
let i = -1;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a doubt that I have. Maybe I am wrong here. Doesn't invoking getSearchCursor again reset the value of i to -1? Should we have it outside the getSearchCursor method? This is just to ensure that the state remains stable. Let me know if I am wrong here and my assumptions are a little off.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

actually this is the correct behavior, since each getSearchCursor call should represent an independent cursor scan from the top of the document.


it('renders search input when visible', () => {
renderSearch();
expect(screen.getByPlaceholderText('Search...')).toBeInTheDocument();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Placeholders are fine, but is it better to have data-testid? Maybe useful for later E2E tests? Same for every other place we are doing a DOM search via placeholders and text.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

using the test ids now

describe('result count', () => {
it('shows "0 results" when search is empty', () => {
renderSearch();
expect(screen.getByText('0 results')).toBeInTheDocument();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can this test be more precise. For whatever reason, if we have a text saying "0 results" in our editor instance, this will fail. This is not a case in this specific test but can be an issue if the test evolves. Maybe we can target the specific text label which shows the results.

];
renderSearch({ editor: makeMockEditor(matches) });
typeSearch('test');
expect(screen.getByText('1 / 3')).toBeInTheDocument();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here, maybe we can do a more targeted search than to depend on the screen instance. Let me know your thoughts.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

using the test ids now for these assertions.

describe('imperative handle', () => {
it('focus() focuses the search input', () => {
const ref = createRef();
renderSearch({}, ref);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Am I missing something here? renderSearch renders the CodeMirror instance. But onFocus, why is the search bar appearing? Is this because of some property in makeMockEditor?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

When the parent opens the search bar (sets visible={true}), it also needs to move keyboard focus into the search input so the user can start typing immediately. It does that by calling ref.current.focus().
So the test is for: calling focus() on the ref moves focus to the search input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants