Skip to content

feat: Stabilize variable info editor transition and popup lifecycle (… - #7818

Merged
sid-bruno merged 1 commit into
usebruno:feat/7458-improve-variable-tooltip-internalfrom
Avictos-Open-Source-Syndicate-OSS:feat/7458-improve-variable-tooltip
May 5, 2026
Merged

sid-bruno merged 1 commit into
usebruno:feat/7458-improve-variable-tooltip-internalfrom
Avictos-Open-Source-Syndicate-OSS:feat/7458-improve-variable-tooltip

Conversation

@avictos

@avictos avictos commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

…#7458)

  • fix: prevent var-info split second UI flicker.

Description

This PR improves the variable tooltip experience in the CodeMirror var info popup by addressing two UX issues:

  1. Tooltip closes too aggressively during interaction (issue Improve variable tooltip (var info) popup UX: keep open when interacting #7458).
  2. Variable value editor briefly flickers/jumps when entering edit mode.

What changed:

  1. Existing popup is now closed with full cleanup before opening a new one brunoVarInfo.js:822

    • Before: old popup DOM could be removed directly.
    • Now: it calls a stored hide handler first when available, so listeners and editor resources are cleaned safely.
  2. Added pin and hide guards brunoVarInfo.js:872

    • isPinned: tracks whether user clicked inside popup.
    • isHidden: prevents hide logic from running twice.
  3. Mouse-out no longer auto-hides when pinned brunoVarInfo.js:886

    • If pinned, mouse leaving editor/popup does nothing.
  4. Clicking inside popup pins it brunoVarInfo.js:893

    • onPopupClick sets isPinned true and clears any pending hide timeout.
  5. Clicking outside always closes it brunoVarInfo.js:901

    • onDocumentClick checks popup containment.
    • Outside click unpins and closes immediately.
  6. Hide function now supports immediate close and full listener cleanup brunoVarInfo.js:909->950

    • Adds an immediate option for forced teardown.
    • Removes popup click and document click handlers in cleanup too.
  7. Stored internal hide hook on popup node brunoVarInfo.js:977

    • Used to safely replace an active popup

Net behavior now:

  1. Hover variable -> popup appears.
  2. If you do not click popup, old auto-hide behavior remains.
  3. If you click popup, it becomes pinned.
  4. While pinned, mouseout and editor typing do not close it.
  5. Clicking anywhere outside closes it.

Additonally:

Implemented a fix for that split-second UI flicker when entering variable edit mode.

  1. In brunoVarInfo.js:499, I changed the click-to-edit flow so the editor is prepared off-visual first.
  2. At brunoVarInfo.js:506, the editor now opens with visibility: hidden (instead of instantly swapping the visible content).
  3. At brunoVarInfo.js:509, layout/height is computed in requestAnimationFrame, then the UI swaps to editor only after it is ready.
  4. At brunoVarInfo.js:519, the editor is revealed after sizing is done.
  5. At brunoVarInfo.js:535, visibility is reset on blur to keep future transitions consistent.

Result:

  • No more “expand + empty + snap back” flash when clicking into the field.
  • Transition to edit mode should look stable.

User Impact:

  1. Hover still opens tooltip as before.
  2. If user does not interact, tooltip auto-hide behavior remains unchanged.
  3. Once user clicks inside tooltip, it stays open while interacting.
  4. Clicking outside closes tooltip reliably.
  5. Entering variable edit mode no longer shows split-second expansion/empty flash.
issue-7458-feat-explained.mov

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue.
  • 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.

Closes #7458

Summary by CodeRabbit

  • Bug Fixes
    • Improved editor mode transitions with smoother visual updates and reliable layout handling.
    • Enhanced popup behavior with pinning capability and better dismissal controls.
    • Fixed popup lifecycle management with improved listener cleanup and state tracking.

…sebruno#7458)

* fix: prevent var-info split second UI flicker.

Co-authored-by: Khalid Zegani <[email protected]>
Co-authored-by: Mhammed Reda El Jirari <[email protected]>
Co-authored-by: Fred Rukundo <[email protected]>
Co-authored-by: El Mehdi Bennamrouche <[email protected]>
Co-authored-by: Ahmed Bouregba <[email protected]>
Copilot AI review requested due to automatic review settings April 21, 2026 18:52
@coderabbitai

coderabbitai Bot commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Enhances variable tooltip popup UX by adding a pin mechanism. When users click the popup, it becomes pinned and remains open despite mouse movement or editor changes. Clicking outside dismisses it. The implementation also refactors edit mode transitions to use requestAnimationFrame instead of setTimeout for improved rendering.

Changes

Cohort / File(s) Summary
Popup Pinning Mechanism
packages/bruno-app/src/utils/codemirror/brunoVarInfo.js
Introduces isPinned and isHidden state flags to control auto-hide behavior. Adds onPopupClick handler to set isPinned = true when clicking inside the popup. Adds onDocumentClick handler to dismiss popup when clicking outside. Conditionally suppresses auto-hide in onMouseOut and onEditorChange when pinned. Implements _hidePopup hook for immediate cleanup with listener unregistration.
Edit Mode Rendering Refactor
packages/bruno-app/src/utils/codemirror/brunoVarInfo.js
Replaces setTimeout(..., 0) with requestAnimationFrame in renderVarInfo. Stages editor reveal by hiding container before refresh, computes height from CodeMirror sizer element, then reveals after layout computation. On blur, restores visibility and returns to display mode.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

📌 A popup pinned stays in its place,
No fleeting fade without a trace!
Click to hold, click outside to free—
Variable tooltips, wild and carefree! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 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 changes: stabilizing editor transition behavior and popup lifecycle management in the variable info component.
Linked Issues check ✅ Passed All coding requirements from issue #7458 are met: isPinned flag prevents mouseout hide when pinned, onPopupClick pins popup and clears timeouts, onDocumentClick closes when clicking outside, and onEditorChange respects pinned state.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #7458: popup lifecycle (pinning, event handlers) and edit-mode flicker fix via requestAnimationFrame sequencing align with stated objectives.

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

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 improves the CodeMirror “variable info” tooltip (var info popup) UX by stabilizing the inline variable value editor transition and making the tooltip persist while the user interacts with it (pin/unpin behavior), addressing issue #7458.

Changes:

  • Stages the variable value editor layout off-visual and reveals it only after sizing to reduce edit-mode flicker/jump.
  • Adds pinning behavior for the var info popup (click inside pins; mouseout/typing won’t hide while pinned; outside click closes).
  • Ensures existing popups are closed via a stored hide handler so event listeners and editor resources are cleaned up before opening a new popup.

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

Comment on lines +893 to +899
const onPopupClick = function (e) {
if (!popup.contains(e.target)) {
return;
}
isPinned = true;
clearTimeout(popupTimeout);
};

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

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

onPopupClick relies on a bubbling click handler on the popup to set isPinned, but several interactive elements inside the popup call e.stopPropagation() (e.g. copy button + secret toggle). Clicking those elements won’t bubble to the popup, so the popup won’t pin and any already-scheduled auto-hide timeout may still close it mid-interaction. Consider pinning via a capture-phase handler (or pinning in the document handler when the target is inside the popup), or explicitly pinning in the inner button handlers as well.

Copilot uses AI. Check for mistakes.
Comment on lines +901 to +904
const onDocumentClick = function (e) {
if (!popup.contains(e.target)) {
isPinned = false;
hidePopup();

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

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

Pinned/unpinned popup behavior (skipping auto-hide while pinned + outside-click closes) is user-visible and there’s already Playwright coverage for variable tooltips, but this PR doesn’t add a test for pinning. Please add/extend an E2E test to assert: click inside pins (mouseout + editor typing doesn’t close), and outside click closes.

Copilot uses AI. Check for mistakes.

@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

🧹 Nitpick comments (1)
packages/bruno-app/src/utils/codemirror/brunoVarInfo.js (1)

893-899: Redundant popup.contains(e.target) guard.

onPopupClick is attached to popup, so any event reaching it is already within the popup's subtree (or on popup itself — still true for contains). The early return is dead code and can be dropped.

🧹 Suggested cleanup
-    const onPopupClick = function (e) {
-      if (!popup.contains(e.target)) {
-        return;
-      }
-      isPinned = true;
-      clearTimeout(popupTimeout);
-    };
+    const onPopupClick = function () {
+      isPinned = true;
+      clearTimeout(popupTimeout);
+    };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-app/src/utils/codemirror/brunoVarInfo.js` around lines 893 -
899, The onPopupClick handler contains a redundant guard checking
popup.contains(e.target) because the listener is attached to popup; remove the
if-check and early return so onPopupClick simply sets isPinned = true and clears
popupTimeout. Update the function definition for onPopupClick (referenced as
onPopupClick, popup, isPinned, popupTimeout) to directly perform those two
actions and leave the event listener attachment as-is.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/bruno-app/src/utils/codemirror/brunoVarInfo.js`:
- Around line 881-899: The popup isn't being pinned when inner buttons call
e.stopPropagation(); update the pinning logic so any interaction inside the
popup sets isPinned: either add a capturing click listener on popup that calls
the existing onPopupClick (use capture:true) so it runs before stopPropagation,
or explicitly set isPinned = true (and clear popupTimeout) inside the button
handlers that call stopPropagation (e.g., the copy and eye-toggle handlers);
touch the existing symbols onPopupClick, popup, isPinned, popupTimeout and
hidePopup to ensure consistent behavior.
- Around line 901-906: In onDocumentClick, clicking outside currently calls
hidePopup() which removes the CodeMirror wrapper and causes a blur that
dispatches updateVariableInScope; change onDocumentClick to check the editing
state (isEditing) before hiding and if isEditing is true either reset the editor
to originalValue (e.g., restore via the CodeMirror instance setValue) or flip a
flag that prevents updateVariableInScope from sending the commit, then clear
isEditing/isPinned and call hidePopup(); ensure you reference onDocumentClick,
popup, isPinned, hidePopup, isEditing, originalValue and updateVariableInScope
when implementing the revert-or-skip behavior so outside clicks cancel in-flight
edits instead of silently saving them.

---

Nitpick comments:
In `@packages/bruno-app/src/utils/codemirror/brunoVarInfo.js`:
- Around line 893-899: The onPopupClick handler contains a redundant guard
checking popup.contains(e.target) because the listener is attached to popup;
remove the if-check and early return so onPopupClick simply sets isPinned = true
and clears popupTimeout. Update the function definition for onPopupClick
(referenced as onPopupClick, popup, isPinned, popupTimeout) to directly perform
those two actions and leave the event listener attachment as-is.
🪄 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: 13addf64-fa27-49a7-a2f4-3278131437eb

📥 Commits

Reviewing files that changed from the base of the PR and between c4dc0bc and 995cbc9.

📒 Files selected for processing (1)
  • packages/bruno-app/src/utils/codemirror/brunoVarInfo.js

Comment on lines 881 to +899
const onMouseOverPopup = function () {
clearTimeout(popupTimeout);
};

const onMouseOut = function () {
if (isPinned) {
return;
}
clearTimeout(popupTimeout);
popupTimeout = setTimeout(hidePopup, 500);
};

const hidePopup = function () {
const onPopupClick = function (e) {
if (!popup.contains(e.target)) {
return;
}
isPinned = true;
clearTimeout(popupTimeout);
};

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

Clicks on popup buttons with stopPropagation won't pin the popup.

The copy button (line 145) and eye-toggle button (line 457/599) both call e.stopPropagation(), so their clicks never bubble up to popup — onPopupClick doesn't fire, and isPinned stays false. Consequence: user hovers → clicks copy → moves focus to the main editor → types → onEditorChange fires → popup vanishes mid-interaction. Same for toggling secret visibility.

Consider pinning on any interaction inside the popup (e.g., attach onPopupClick with useCapture: true so it fires before stopPropagation takes effect), or explicitly pin from within those button handlers.

🔧 One possible tweak
-    CodeMirror.on(popup, 'click', onPopupClick);
+    // Use capture so pinning happens before child handlers call stopPropagation
+    popup.addEventListener('click', onPopupClick, true);
...
-    CodeMirror.off(popup, 'click', onPopupClick);
+    popup.removeEventListener('click', onPopupClick, true);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-app/src/utils/codemirror/brunoVarInfo.js` around lines 881 -
899, The popup isn't being pinned when inner buttons call e.stopPropagation();
update the pinning logic so any interaction inside the popup sets isPinned:
either add a capturing click listener on popup that calls the existing
onPopupClick (use capture:true) so it runs before stopPropagation, or explicitly
set isPinned = true (and clear popupTimeout) inside the button handlers that
call stopPropagation (e.g., the copy and eye-toggle handlers); touch the
existing symbols onPopupClick, popup, isPinned, popupTimeout and hidePopup to
ensure consistent behavior.

Comment on lines +901 to +906
const onDocumentClick = function (e) {
if (!popup.contains(e.target)) {
isPinned = false;
hidePopup();
}
};

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

🧩 Analysis chain

🌐 Web query:

CodeMirror 5 blur event firing order when wrapper element removed from DOM

💡 Result:

In CodeMirror 5, the blur event fires when the hidden textarea (cm.display.input.getField) loses focus, which occurs when the wrapper element containing it is removed from the DOM. According to HTML specs and browser behavior (especially Chrome), removing a focused element from the DOM triggers its blur event synchronously as part of the focus fixup rule, which then designates the viewport/body as the new focused area. CodeMirror's onBlur function is explicitly called in response to this, emitting the "blur" event via signal(cm, "blur", cm, e) if the editor was previously focused. There is no other event (like focus) that fires automatically in this sequence solely due to DOM removal—the sequence is: textarea blur event -> CodeMirror "blur" event. This behavior aligns with standard DOM focus management and CodeMirror's focus handling in display/focus.js, where onBlur clears the focused state and emits the event. Delays or suppressions (delayingBlurEvent) only apply during specific interactions like mouse events, not DOM removal.

Citations:


🏁 Script executed:

# First, let's look at the file to understand the context around the click handler
sed -n '890,920p' packages/bruno-app/src/utils/codemirror/brunoVarInfo.js

Repository: usebruno/bruno

Length of output: 917


🏁 Script executed:

# Let's find the hidePopup function definition
rg -n "hidePopup\s*=" packages/bruno-app/src/utils/codemirror/brunoVarInfo.js -A 5

Repository: usebruno/bruno

Length of output: 776


🏁 Script executed:

# Let's find where the cmEditor blur event is handled
rg -n "cm\.on\(" packages/bruno-app/src/utils/codemirror/brunoVarInfo.js | head -20

Repository: usebruno/bruno

Length of output: 40


🏁 Script executed:

# Search for updateVariableInScope to see what it does
rg -n "updateVariableInScope" packages/bruno-app/src/utils/codemirror/brunoVarInfo.js -B 2 -A 10

Repository: usebruno/bruno

Length of output: 1676


🏁 Script executed:

# Get the complete hidePopup function
sed -n '908,970p' packages/bruno-app/src/utils/codemirror/brunoVarInfo.js

Repository: usebruno/bruno

Length of output: 1989


🏁 Script executed:

# Search for blur event handler on cmEditor
rg -n "cm\.on.*blur|blur.*function" packages/bruno-app/src/utils/codemirror/brunoVarInfo.js -B 2 -A 8

Repository: usebruno/bruno

Length of output: 40


🏁 Script executed:

# Search for where cmEditor wrapper is removed from DOM
rg -n "removeChild|remove\(\)|parentNode" packages/bruno-app/src/utils/codemirror/brunoVarInfo.js -B 2 -A 2

Repository: usebruno/bruno

Length of output: 1031


🏁 Script executed:

# Look for the blur handler more broadly
rg -n "blur" packages/bruno-app/src/utils/codemirror/brunoVarInfo.js -B 2 -A 5

Repository: usebruno/bruno

Length of output: 660


🏁 Script executed:

# Look for cm.on handler setup to understand event binding
rg -n "cm\.on\(" packages/bruno-app/src/utils/codemirror/brunoVarInfo.js -A 5

Repository: usebruno/bruno

Length of output: 40


🏁 Script executed:

# Look for the lines around 559-563 mentioned in the review (post-save UI updates)
sed -n '540,570p' packages/bruno-app/src/utils/codemirror/brunoVarInfo.js

Repository: usebruno/bruno

Length of output: 1704


🏁 Script executed:

# Find the updateValueDisplay function to understand what it does
rg -n "function updateValueDisplay|const updateValueDisplay" packages/bruno-app/src/utils/codemirror/brunoVarInfo.js -A 15

Repository: usebruno/bruno

Length of output: 572


🏁 Script executed:

# Get context around where valueDisplay is created to understand its relationship with popup
sed -n '400,450p' packages/bruno-app/src/utils/codemirror/brunoVarInfo.js

Repository: usebruno/bruno

Length of output: 1826


🏁 Script executed:

# Find where valueDisplay is created to confirm it's inside popup
rg -n "valueDisplay\s*=" packages/bruno-app/src/utils/codemirror/brunoVarInfo.js | head -5

Repository: usebruno/bruno

Length of output: 177


🏁 Script executed:

# Look for the popup/container structure to understand DOM hierarchy
sed -n '350,390p' packages/bruno-app/src/utils/codemirror/brunoVarInfo.js

Repository: usebruno/bruno

Length of output: 1979


🏁 Script executed:

# Verify the exact timing - check if there's any other removal happening before blur completes
sed -n '520,575p' packages/bruno-app/src/utils/codemirror/brunoVarInfo.js

Repository: usebruno/bruno

Length of output: 2485


Outside click silently commits the edit with no way to cancel.

When the user clicks outside the popup while editing, hidePopup() immediately removes the CodeMirror wrapper, triggering a blur event that dispatches updateVariableInScope. This means there's no way for the user to bail out of an in-flight edit by clicking away—the change is automatically saved. If "click outside = cancel" is the preferred behavior, consider resetting the editor to originalValue before hiding when isEditing is true. Otherwise, confirm that silent save-on-outside-click is intentional.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-app/src/utils/codemirror/brunoVarInfo.js` around lines 901 -
906, In onDocumentClick, clicking outside currently calls hidePopup() which
removes the CodeMirror wrapper and causes a blur that dispatches
updateVariableInScope; change onDocumentClick to check the editing state
(isEditing) before hiding and if isEditing is true either reset the editor to
originalValue (e.g., restore via the CodeMirror instance setValue) or flip a
flag that prevents updateVariableInScope from sending the commit, then clear
isEditing/isPinned and call hidePopup(); ensure you reference onDocumentClick,
popup, isPinned, hidePopup, isEditing, originalValue and updateVariableInScope
when implementing the revert-or-skip behavior so outside clicks cancel in-flight
edits instead of silently saving them.

@helloanoop

Copy link
Copy Markdown
Contributor

Thanks for the PR @avictos !
We did a quick test and found it to solve the issue. We have shared it with our product team for prioritisation among other issues.

@sid-bruno
sid-bruno changed the base branch from main to feat/7458-improve-variable-tooltip-internal May 4, 2026 05:42
@sid-bruno

Copy link
Copy Markdown
Collaborator

Merging it to an internal branch for the team to take over and polish it up.

@sid-bruno sid-bruno added the adopted-by-maintainers PR needs additional work and is now being worked on by the maintainers label May 4, 2026
@sid-bruno
sid-bruno merged commit 0d8735a into usebruno:feat/7458-improve-variable-tooltip-internal May 5, 2026
12 of 14 checks passed
bijin-bruno pushed a commit that referenced this pull request May 13, 2026
…7912)

* feat: Stabilize variable info editor transition and popup lifecycle (#7458) (#7818)

* fix: prevent var-info split second UI flicker.

Co-authored-by: Mhammed Reda El Jirari <[email protected]>
Co-authored-by: Fred Rukundo <[email protected]>
Co-authored-by: El Mehdi Bennamrouche <[email protected]>
Co-authored-by: Ahmed Bouregba <[email protected]>

* fix: variable-tooltip hover issues (#7907)

---------

Co-authored-by: Avictos <[email protected]>
Co-authored-by: Mhammed Reda El Jirari <[email protected]>
Co-authored-by: Fred Rukundo <[email protected]>
Co-authored-by: El Mehdi Bennamrouche <[email protected]>
Co-authored-by: Ahmed Bouregba <[email protected]>
Co-authored-by: shubh-bruno <[email protected]>
@coderabbitai coderabbitai Bot mentioned this pull request May 22, 2026
6 tasks
sharan-bruno pushed a commit to sharan-bruno/bruno that referenced this pull request Jun 4, 2026
…sebruno#7912)

* feat: Stabilize variable info editor transition and popup lifecycle (usebruno#7458) (usebruno#7818)

* fix: prevent var-info split second UI flicker.

Co-authored-by: Mhammed Reda El Jirari <[email protected]>
Co-authored-by: Fred Rukundo <[email protected]>
Co-authored-by: El Mehdi Bennamrouche <[email protected]>
Co-authored-by: Ahmed Bouregba <[email protected]>

* fix: variable-tooltip hover issues (usebruno#7907)

---------

Co-authored-by: Avictos <[email protected]>
Co-authored-by: Mhammed Reda El Jirari <[email protected]>
Co-authored-by: Fred Rukundo <[email protected]>
Co-authored-by: El Mehdi Bennamrouche <[email protected]>
Co-authored-by: Ahmed Bouregba <[email protected]>
Co-authored-by: shubh-bruno <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adopted-by-maintainers PR needs additional work and is now being worked on by the maintainers size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve variable tooltip (var info) popup UX: keep open when interacting

4 participants