Repository navigation
feat: Stabilize variable info editor transition and popup lifecycle (… - #7818
Conversation
…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]>
WalkthroughEnhances 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 Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
| const onPopupClick = function (e) { | ||
| if (!popup.contains(e.target)) { | ||
| return; | ||
| } | ||
| isPinned = true; | ||
| clearTimeout(popupTimeout); | ||
| }; |
There was a problem hiding this comment.
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.
| const onDocumentClick = function (e) { | ||
| if (!popup.contains(e.target)) { | ||
| isPinned = false; | ||
| hidePopup(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/bruno-app/src/utils/codemirror/brunoVarInfo.js (1)
893-899: Redundantpopup.contains(e.target)guard.
onPopupClickis attached topopup, so any event reaching it is already within the popup's subtree (or onpopupitself — stilltrueforcontains). 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
📒 Files selected for processing (1)
packages/bruno-app/src/utils/codemirror/brunoVarInfo.js
| 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); | ||
| }; |
There was a problem hiding this comment.
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.
| const onDocumentClick = function (e) { | ||
| if (!popup.contains(e.target)) { | ||
| isPinned = false; | ||
| hidePopup(); | ||
| } | ||
| }; |
There was a problem hiding this comment.
🧩 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:
- 1: blur and change events fire for elements removed from DOM whatwg/html#3847
- 2: https://sources.debian.org/src/codemirror-js/5.65.0%2B~cs5.83.9-2/src/display/focus.js/
- 3: https://codemirror.net/5/doc/internals.html
- 4: Navigating away from a focused CodeMirror blocks all inputs on the page uiwjs/react-codemirror#677
🏁 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.jsRepository: 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 5Repository: 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 -20Repository: 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 10Repository: usebruno/bruno
Length of output: 1676
🏁 Script executed:
# Get the complete hidePopup function
sed -n '908,970p' packages/bruno-app/src/utils/codemirror/brunoVarInfo.jsRepository: 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 8Repository: 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 2Repository: 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 5Repository: 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 5Repository: 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.jsRepository: 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 15Repository: 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.jsRepository: 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 -5Repository: 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.jsRepository: 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.jsRepository: 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.
|
Thanks for the PR @avictos ! |
|
Merging it to an internal branch for the team to take over and polish it up. |
0d8735a
into
usebruno:feat/7458-improve-variable-tooltip-internal
…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]>
…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]>
…#7458)
Description
This PR improves the variable tooltip experience in the CodeMirror var info popup by addressing two UX issues:
What changed:
Existing popup is now closed with full cleanup before opening a new one
brunoVarInfo.js:822Added pin and hide guards
brunoVarInfo.js:872Mouse-out no longer auto-hides when pinned
brunoVarInfo.js:886Clicking inside popup pins it
brunoVarInfo.js:893Clicking outside always closes it
brunoVarInfo.js:901Hide function now supports immediate close and full listener cleanup
brunoVarInfo.js:909->950Stored internal hide hook on popup node
brunoVarInfo.js:977Net behavior now:
Additonally:
Implemented a fix for that split-second UI flicker when entering variable edit mode.
brunoVarInfo.js:499, I changed the click-to-edit flow so the editor is prepared off-visual first.brunoVarInfo.js:506, the editor now opens with visibility: hidden (instead of instantly swapping the visible content).brunoVarInfo.js:509, layout/height is computed in requestAnimationFrame, then the UI swaps to editor only after it is ready.brunoVarInfo.js:519, the editor is revealed after sizing is done.brunoVarInfo.js:535, visibility is reset on blur to keep future transitions consistent.Result:
User Impact:
issue-7458-feat-explained.mov
Contribution Checklist:
Closes #7458
Summary by CodeRabbit