Skip to content

fix: improve value handling in editor components - #7098

Merged
sid-bruno merged 3 commits into
usebruno:mainfrom
sid-bruno:fix/2646
Feb 10, 2026
Merged

sid-bruno merged 3 commits into
usebruno:mainfrom
sid-bruno:fix/2646

Conversation

@sid-bruno

@sid-bruno sid-bruno commented Feb 10, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Temporary fix for preserving cursor positions lost during editor re-renders. This is not an ideal long-term solution, but it avoids the overhead of storing the entire CodeMirror operation log. It specifically addresses cursor displacement that occurs when auto-save and new-line shortcuts are pressed simultaneously, causing a re-render that resets the cursor position.

A proper solution is to add stable ids to items and collections so a combination can be used for editors and other things to avoid the re-render from happening in the first place.

JIRA

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

  • Bug Fixes
    • Improved editor syncing across single-line, multi-line and query editors: when an editor is focused, incoming external value changes are cached instead of overwriting in-progress edits. Editors now preserve cursor/selection, defer replacements until editing ends, and avoid accidental loss during typing.
    • Added safeguards to reduce collisions with auto-save/newline insertions (temporary mitigation).

Copilot AI review requested due to automatic review settings February 10, 2026 12:44
@coderabbitai

coderabbitai Bot commented Feb 10, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Editors now use focus-aware value synchronization: on incoming prop changes they compare editor content and focus, deferring setValue when the editor is focused and user edits differ, otherwise updating cached value, setting the editor value, and restoring the cursor. (49 words)

Changes

Cohort / File(s) Summary
Editor Value Synchronization
packages/bruno-app/src/components/CodeEditor/index.js, packages/bruno-app/src/components/MultiLineEditor/index.js, packages/bruno-app/src/components/SingleLineEditor/index.js, packages/bruno-app/src/components/RequestPane/QueryEditor/index.js
componentDidUpdate now computes nextValue (prop) and currentValue (editor). If editor has focus and values differ, only update the cached value (defer setValue); otherwise update cache, call setValue, and restore cursor. Minor optional chaining/nullish defaults and a TODO about auto-save/newline collisions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno
  • bijin-bruno

Poem

✨ The editor listens when you type,
Incoming words wait out the hype,
Cursor safe, your edits stay—
Props queue up till focus sways,
Quiet sync, then all is ripe.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 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: improving value handling in editor components across multiple editor implementations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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

No actionable comments were generated in the recent review. 🎉


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

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/MultiLineEditor/index.js (1)

153-155: ⚠️ Potential issue | 🟡 Minor

Duplicate readOnly check.

readOnly prop change is handled twice — lines 153–155 and lines 174–176. The second one also adds || false which differs from the first. Pick one and remove the other.

Proposed fix — remove the duplicate
-    if (this.props.readOnly !== prevProps.readOnly && this.editor) {
-      this.editor.setOption('readOnly', this.props.readOnly || false);
-    }

Also applies to: 174-176

🤖 Fix all issues with AI agents
In `@packages/bruno-app/src/components/RequestPane/QueryEditor/index.js`:
- Around line 159-166: The editor updates the value in the else branch (when
!hasFocus) but fails to preserve the cursor/selection, causing jumps on external
updates; modify the else branch around this.editor.setValue(nextValue) to
capture the current cursor/selection position (using this.editor's
cursor/selection APIs), call setValue(nextValue), then restore the previously
captured cursor/selection so the caret is preserved; this change should be
applied to the component code that uses this.props.value, this.editor, and
this.cachedValue.

Copilot AI 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.

Pull request overview

This PR aims to make CodeMirror-based editor components handle incoming value updates more safely/consistently (notably around null/undefined), while attempting to avoid overwriting the editor content during active user focus.

Changes:

  • Normalize incoming value props to safe string defaults (e.g., value ?? '', String(value ?? '')) before applying to editors.
  • Add focus-aware logic intended to prevent setValue() from running while the editor has focus.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
packages/bruno-app/src/components/SingleLineEditor/index.js Adds focus-aware prop-to-editor value reconciliation and normalizes value to a string.
packages/bruno-app/src/components/RequestPane/QueryEditor/index.js Normalizes value updates and adds focus-aware skip logic for setValue().
packages/bruno-app/src/components/MultiLineEditor/index.js Normalizes value updates and adds focus-aware skip logic for setValue().
packages/bruno-app/src/components/CodeEditor/index.js Normalizes value updates and adds focus-aware skip logic while preserving cursor on updates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

🤖 Fix all issues with AI agents
In `@packages/bruno-app/src/components/CodeEditor/index.js`:
- Around line 236-246: The inline comment uses "//TODO:" which fails the linter;
update the comment in the CodeEditor component to use proper spacing "// TODO:"
and keep the rest of the focus-aware sync block intact (the block around
this.props.value handling and calls to this.editor.getValue(),
this.editor.hasFocus?.(), this.editor.setValue(), this.editor.setCursor(), and
this.cachedValue assignment).

In `@packages/bruno-app/src/components/MultiLineEditor/index.js`:
- Around line 157-167: Update the inline TODO comment above the logic that uses
this.editor, cachedValue, getValue, hasFocus, getCursor, setValue and setCursor
to match the project's comment spacing style (e.g., change "//TODO:" to "//
TODO:" and mirror the spacing/format used in CodeEditor and SingleLineEditor);
leave the surrounding logic intact.

In `@packages/bruno-app/src/components/RequestPane/QueryEditor/index.js`:
- Line 159: Fix the linting error by normalizing the inline comment spacing:
change the comment that currently begins "//TODO: temporary fix for keeping
cursor state when auto save and new line insertion collide PR#7098" to use the
linter-preferred spacing and style (e.g., "// TODO: temporary fix for keeping
cursor state when auto save and new line insertion collide PR `#7098`"). Update
that exact comment text so it includes the required space after "//" and any
spacing around "PR `#7098`" if your linter enforces it.

In `@packages/bruno-app/src/components/SingleLineEditor/index.js`:
- Line 172: The inline comment in SingleLineEditor (the TODO comment "//TODO:
temporary fix for keeping cursor state when auto save and new line insertion
collide PR#7098") violates spacing lint rules; update it to follow project
comment style by inserting a space after the // and after the TODO keyword
(e.g., "// TODO: temporary fix...") and ensure consistent spacing around
"PR#7098" (e.g., "PR `#7098`" or follow repo convention) so it passes the linter.

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.

2 participants