Skip to content

fix: refocus search bar in code editor on Ctrl/Cmd + F - #6980

Merged
sid-bruno merged 4 commits into
usebruno:mainfrom
shubh-bruno:fix/code-search
Feb 2, 2026
Merged

sid-bruno merged 4 commits into
usebruno:mainfrom
shubh-bruno:fix/code-search

Conversation

@shubh-bruno

@shubh-bruno shubh-bruno commented Jan 30, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Fixes : #6930

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

    • Cmd-F/Ctrl-F opens the search bar and automatically focuses the input for immediate typing.
    • Search input now reliably receives focus so keyboard navigation and typing work immediately.
  • Bug Fixes

    • Closing the search bar returns focus to the editor to prevent lost keyboard input.

@coderabbitai

coderabbitai Bot commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

CodeEditor adds a ref to CodeMirrorSearch and changes Cmd/Ctrl‑F handling to show the search bar and call its focus() via the ref. CodeMirrorSearch is converted to forwardRef and exposes a focus() imperative API that focuses/selects its internal input.

Changes

Cohort / File(s) Summary
Code editor integration
packages/bruno-app/src/components/CodeEditor/index.js
Adds createRef import and this.searchBarRef; on Cmd/Ctrl‑F sets searchBarVisible = true and calls this.searchBarRef.current.focus(); passes ref={this.searchBarRef} to CodeMirrorSearch; updates import path for CodeMirrorSearch.
Search component (ref API)
packages/bruno-app/src/components/CodeMirrorSearch/index.js
Wraps component with forwardRef, adds useImperativeHandle to expose focus() that uses an internal inputRef to focus/select the input; retains existing search, highlight, navigation, and close behavior.

Sequence Diagram(s)

sequenceDiagram
participant User
participant CodeEditor as CodeEditor (component)
participant CodeMirrorSearch as CodeMirrorSearch (component)
participant Editor as CodeMirror (editor)

User->>CodeEditor: Press Cmd/Ctrl-F
CodeEditor->>CodeEditor: setState(searchBarVisible = true)
CodeEditor->>CodeMirrorSearch: ref.current.focus()
CodeMirrorSearch->>CodeMirrorSearch: focus() -> inputRef.focus()/select()
CodeMirrorSearch->>Editor: (search input updates) perform search / highlight
Editor-->>CodeMirrorSearch: search results / matches
CodeMirrorSearch-->>User: show matches, navigation controls
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • helloanoop
  • bijin-bruno

Poem

A keypress calls the tiny bell,
A ref directs the search to dwell.
Focus finds the hidden line,
Cursor sings, the matches shine. 🔎✨

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: implementing refocus functionality for the search bar via forwarded refs when Ctrl/Cmd+F is pressed.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@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

🤖 Fix all issues with AI agents
In `@packages/bruno-app/src/components/CodeEditor/index.js`:
- Around line 97-100: Remove the leftover debug log from the 'Cmd-F' key
handler: in the object mapping for keyboard shortcuts (the 'Cmd-F' entry) delete
the console.log('Searching...') call and leave the setState call that toggles
searchBarVisible and sets searchFocusTrigger so behavior matches the 'Ctrl-F'
handler.
🧹 Nitpick comments (2)
packages/bruno-app/src/components/CodeMirrorSearch/index.js (2)

117-119: Consider removing visible and focusTrigger from doSearch dependencies.

These dependencies were added but doSearch doesn't use them directly. The focus concern is already handled by the separate effect above. Including them here may cause unnecessary search re-executions when the search bar opens or when the hotkey is pressed repeatedly.

♻️ Proposed fix
   useEffect(() => {
     doSearch(0, debouncedSearchText);
-  }, [debouncedSearchText, doSearch, visible, focusTrigger]);
+  }, [debouncedSearchText, doSearch]);

178-180: autoFocus is redundant with the new programmatic focus effect.

Since lines 110-115 now handle focusing the input programmatically when visible changes, the autoFocus attribute is no longer necessary and can be removed for clarity.

♻️ Proposed fix
         <input
           ref={inputRef}
-          autoFocus
           type="text"

@sid-bruno

Copy link
Copy Markdown
Collaborator

The approach depends on useEffect which isn't needed, allow the CodeEditorSearch to allow forwarding ref and use the ref in the CodeEditor to trigger a .focus on the ref if the search is already active.

@pull-request-size pull-request-size Bot added size/M and removed size/S labels Jan 31, 2026
this.setState({ searchBarVisible: true });
}
this.setState({ searchBarVisible: true }, () => {
this.searchBarRef.current?.focus();

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.searchBarRef.current may or may not exist after the state is flushed, the mounting might happen after the callback comes back.

Instead run the focus in the ref callback itself

@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

🤖 Fix all issues with AI agents
In `@packages/bruno-app/src/components/CodeMirrorSearch/index.js`:
- Around line 118-120: The useEffect is calling doSearch(0, debouncedSearchText)
but doSearch only accepts a single parameter (newIndex); remove the dead second
argument so the effect calls doSearch(0) (or alternatively, if the intention was
to pass the search text, update the doSearch signature where it’s defined).
Update the call in the useEffect that references doSearch and
debouncedSearchText to match the doSearch(newIndex) signature to eliminate the
extra argument.
🧹 Nitpick comments (2)
packages/bruno-app/src/components/CodeMirrorSearch/index.js (2)

110-116: Consider adding a dependency array to useImperativeHandle.

Omitting the dependency array causes the imperative handle to be recreated on every render. Since inputRef is stable and focus captures it by reference at call time, an empty array suffices.

♻️ Proposed fix
  useImperativeHandle(ref, () => ({
    focus: () => {
      if (inputRef.current) {
        inputRef.current.focus();
      }
    }
-  }));
+  }), []);

11-11: Optional: Add displayName for easier debugging.

When using forwardRef, setting a displayName helps identify the component in React DevTools and error stack traces.

♻️ Proposed addition after line 209
CodeMirrorSearch.displayName = 'CodeMirrorSearch';

Also applies to: 209-209

Comment on lines 118 to 120
useEffect(() => {
doSearch(0, debouncedSearchText);
}, [debouncedSearchText, doSearch]);

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.

⚠️ Potential issue | 🟡 Minor

Extra argument passed to doSearch.

doSearch accepts only one parameter (newIndex), but it's being called with debouncedSearchText as a second argument. This is dead code and may cause confusion.

🐛 Proposed fix
  useEffect(() => {
-   doSearch(0, debouncedSearchText);
+   doSearch(0);
  }, [debouncedSearchText, doSearch]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(() => {
doSearch(0, debouncedSearchText);
}, [debouncedSearchText, doSearch]);
useEffect(() => {
doSearch(0);
}, [debouncedSearchText, doSearch]);
🤖 Prompt for AI Agents
In `@packages/bruno-app/src/components/CodeMirrorSearch/index.js` around lines 118
- 120, The useEffect is calling doSearch(0, debouncedSearchText) but doSearch
only accepts a single parameter (newIndex); remove the dead second argument so
the effect calls doSearch(0) (or alternatively, if the intention was to pass the
search text, update the doSearch signature where it’s defined). Update the call
in the useEffect that references doSearch and debouncedSearchText to match the
doSearch(newIndex) signature to eliminate the extra argument.

@sid-bruno sid-bruno changed the title fix: search functionality in code editor fix: refocus search bar in code editor on Ctrl/Cmd + F Feb 2, 2026
@sid-bruno
sid-bruno merged commit 679cb91 into usebruno:main Feb 2, 2026
maxenceleblanc pushed a commit to maxenceleblanc/curly_cats2 that referenced this pull request Jul 20, 2026
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.

Searching fields/data in Response does not work

2 participants