Skip to content

Commit c92057b

Browse files
devvaannshabose
authored andcommitted
fix: element highlighting disappears after element properties changes
1 parent 15f52f0 commit c92057b

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,13 @@ function RemoteFunctions(config = {}) {
497497
}
498498

499499
this.elements = [];
500+
// Reset the cached selector so that redraw() uses the elements
501+
// array instead of re-querying the DOM with a stale selector.
502+
// Without this, a selector like [data-brackets-id='3'] persists
503+
// after the element is replaced (e.g. tag name change assigns a
504+
// new ID), causing redraw() to find zero matches and release
505+
// all overlays — making the highlight vanish.
506+
this.selector = "";
500507
},
501508

502509
redraw: function () {
@@ -643,6 +650,20 @@ function RemoteFunctions(config = {}) {
643650
* UI like control box, spacing handles, or measurements.
644651
*/
645652
function selectElement(element, fromEditor) {
653+
// When a cursor-based highlight re-selects the already-selected element,
654+
// just refresh the highlight overlay without dismissing existing UI panels
655+
// (control box, editor box, element-info). This prevents cursor activity
656+
// after a source edit (e.g., tag name change) from tearing down the
657+
// element properties panel and losing its state.
658+
if (fromEditor && element === previouslySelectedElement) {
659+
if (!_clickHighlight) {
660+
_clickHighlight = new Highlight();
661+
}
662+
_clickHighlight.clear();
663+
_clickHighlight.add(element);
664+
return;
665+
}
666+
646667
dismissUIAndCleanupState();
647668
// this should also be there when users are in highlight mode
648669
scrollElementToViewPort(element);
@@ -1317,6 +1338,19 @@ function RemoteFunctions(config = {}) {
13171338
}
13181339
previouslySelectedElement = freshElement;
13191340
window.__current_ph_lp_selected = freshElement;
1341+
// After element replacement (e.g., tag name change), the old
1342+
// DOM node is gone. Patch the element reference on any
1343+
// existing UI boxes so that position() doesn't bail on a
1344+
// disconnected node and future syncs resolve correctly.
1345+
// We update references directly rather than calling
1346+
// handler.updateContent() to avoid side-effects like
1347+
// re-creating a dismissed control box.
1348+
if (SHARED_STATE._controlBox) {
1349+
SHARED_STATE._controlBox.element = freshElement;
1350+
}
1351+
if (SHARED_STATE._editorBox) {
1352+
SHARED_STATE._editorBox.element = freshElement;
1353+
}
13201354
redrawEverything();
13211355
}
13221356
}

src/nls/root/strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ define({
274274
"LIVE_DEV_FORMAT_MORE": "More formatting",
275275
"LIVE_DEV_ELEMENT_PROPS_TITLE": "Element Properties",
276276
"LIVE_DEV_ELEMENT_PROPS_TAG": "Tag",
277+
"LIVE_DEV_ELEMENT_PROPS_VOID_ERROR": "<{0}> is self-closing and cannot have content",
277278
"LIVE_DEV_ELEMENT_PROPS_SIZE": "Size",
278279
"LIVE_DEV_ELEMENT_PROPS_CLASS": "Class",
279280
"LIVE_DEV_ELEMENT_PROPS_ID": "ID",

0 commit comments

Comments
 (0)