Skip to content

Commit 1b94b1d

Browse files
committed
refactor: now outline passes through the highlight function as is always present
1 parent 1630242 commit 1b94b1d

1 file changed

Lines changed: 22 additions & 53 deletions

File tree

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ function RemoteFunctions(config = {}) {
266266
this.elements = [];
267267
this.selector = "";
268268
this._divs = [];
269+
this._originalOutlines = new Map();
269270
}
270271

271272
Highlight.prototype = {
@@ -276,6 +277,13 @@ function RemoteFunctions(config = {}) {
276277
if (this.trigger) {
277278
_trigger(element, "highlight", 1);
278279
}
280+
281+
// Save original outline and apply highlight outline
282+
this._originalOutlines.set(element, element.style.outline);
283+
const isEditable = element.hasAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR);
284+
const outlineColor = isEditable ? COLORS.outlineEditable : COLORS.outlineNonEditable;
285+
element.style.outline = `1px solid ${outlineColor}`;
286+
279287
this.elements.push(element);
280288
this._createOverlay(element);
281289
},
@@ -293,6 +301,15 @@ function RemoteFunctions(config = {}) {
293301
_trigger(el, "highlight", 0);
294302
});
295303
}
304+
305+
// Restore original outlines
306+
this.elements.forEach(function (el) {
307+
if (this._originalOutlines.has(el)) {
308+
el.style.outline = this._originalOutlines.get(el);
309+
}
310+
}, this);
311+
this._originalOutlines = new Map();
312+
296313
this.elements = [];
297314
},
298315

@@ -410,14 +427,6 @@ function RemoteFunctions(config = {}) {
410427
return getHighlightMode() !== "click";
411428
}
412429

413-
// helper function to clear element hover outline highlighting
414-
function clearElementHoverHighlight(element) {
415-
if (element._originalHoverOutline !== undefined) {
416-
element.style.outline = element._originalHoverOutline;
417-
}
418-
delete element._originalHoverOutline;
419-
}
420-
421430
function onElementHover(event) {
422431
// don't want highlighting and stuff when auto scrolling or when dragging (svgs)
423432
// for dragging normal html elements its already taken care of...so we just add svg drag checking
@@ -440,20 +449,12 @@ function RemoteFunctions(config = {}) {
440449

441450
// this is to check the user's settings, if they want to show the elements highlights on hover or click
442451
if (_hoverHighlight && shouldShowHighlightOnHover()) {
443-
_hoverHighlight.elements.forEach(clearElementHoverHighlight);
444452
_hoverHighlight.clear();
445453

446454
// Skip hover outline and overlay for the currently click-selected element.
447-
// It already has its own outline and overlay from the click/selection flow.
448-
// Adding hover state on top would corrupt _originalHoverOutline (it would capture
449-
// the click outline instead of the true original) and stack duplicate overlays.
455+
// It already has its own outline and overlay from the click/selection flow,
456+
// and adding hover state on top would stack duplicate overlays.
450457
if (element !== previouslySelectedElement) {
451-
// Store original outline to restore on hover out, then apply a border
452-
element._originalHoverOutline = element.style.outline;
453-
const isEditable = element.hasAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR);
454-
const outlineColor = isEditable ? COLORS.outlineEditable : COLORS.outlineNonEditable;
455-
element.style.outline = `1px solid ${outlineColor}`;
456-
457458
_hoverHighlight.add(element);
458459
}
459460

@@ -479,7 +480,6 @@ function RemoteFunctions(config = {}) {
479480
// this is to check the user's settings, if they want to show the elements highlights on hover or click
480481
if (_hoverHighlight && shouldShowHighlightOnHover()) {
481482
_hoverHighlight.clear();
482-
clearElementHoverHighlight(element);
483483
// dismiss the hover box
484484
const hoverBoxHandler = LivePreviewView.getToolHandler("HoverBox");
485485
if (hoverBoxHandler) {
@@ -543,11 +543,6 @@ function RemoteFunctions(config = {}) {
543543
}
544544
}
545545

546-
element._originalOutline = element.style.outline;
547-
const isEditable = element.hasAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR);
548-
const outlineColor = isEditable ? COLORS.outlineEditable : COLORS.outlineNonEditable;
549-
element.style.outline = `1px solid ${outlineColor}`;
550-
551546
if (!_clickHighlight) {
552547
_clickHighlight = new Highlight();
553548
}
@@ -649,13 +644,6 @@ function RemoteFunctions(config = {}) {
649644
_cssSelectorHighlightTimer = null;
650645
}
651646
if (_cssSelectorHighlight) {
652-
// Restore original outlines on highlighted elements
653-
_cssSelectorHighlight.elements.forEach(function (el) {
654-
if (el._originalCssSelectorOutline !== undefined) {
655-
el.style.outline = el._originalCssSelectorOutline;
656-
delete el._originalCssSelectorOutline;
657-
}
658-
});
659647
_cssSelectorHighlight.clear();
660648
_cssSelectorHighlight = null;
661649
}
@@ -674,10 +662,6 @@ function RemoteFunctions(config = {}) {
674662
LivePreviewView.isElementInspectable(nodes[i], true) &&
675663
nodes[i].nodeType === Node.ELEMENT_NODE) {
676664
_cssSelectorHighlight.add(nodes[i]);
677-
nodes[i]._originalCssSelectorOutline = nodes[i].style.outline;
678-
const isEditable = nodes[i].hasAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR);
679-
const outlineColor = isEditable ? COLORS.outlineEditable : COLORS.outlineNonEditable;
680-
nodes[i].style.outline = `1px solid ${outlineColor}`;
681665
}
682666
}
683667
_cssSelectorHighlight.selector = rule;
@@ -690,7 +674,6 @@ function RemoteFunctions(config = {}) {
690674
_clickHighlight = null;
691675
}
692676
if (_hoverHighlight) {
693-
_hoverHighlight.elements.forEach(clearElementHoverHighlight);
694677
_hoverHighlight.clear();
695678
_hoverHighlight = null;
696679
}
@@ -1186,11 +1169,6 @@ function RemoteFunctions(config = {}) {
11861169
}
11871170

11881171
if (freshElement) {
1189-
freshElement._originalOutline = freshElement.style.outline;
1190-
const isEditable = freshElement.hasAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR);
1191-
const outlineColor = isEditable
1192-
? COLORS.outlineEditable : COLORS.outlineNonEditable;
1193-
freshElement.style.outline = `1px solid ${outlineColor}`;
11941172
if (_clickHighlight) {
11951173
_clickHighlight.clear();
11961174
_clickHighlight.add(freshElement);
@@ -1275,23 +1253,14 @@ function RemoteFunctions(config = {}) {
12751253
*/
12761254
function cleanupPreviousElementState() {
12771255
if (previouslySelectedElement) {
1278-
// Safety net: clear any stale hover outline tracking before hideHighlight runs.
1279-
// This prevents clearElementHoverHighlight from re-applying a captured click outline
1280-
// in edge cases where _originalHoverOutline was set on the selected element.
1281-
delete previouslySelectedElement._originalHoverOutline;
1282-
if (previouslySelectedElement._originalOutline !== undefined) {
1283-
previouslySelectedElement.style.outline = previouslySelectedElement._originalOutline;
1284-
} else {
1285-
previouslySelectedElement.style.outline = "";
1286-
}
1287-
delete previouslySelectedElement._originalOutline;
12881256
previouslySelectedElement = null;
12891257
window.__current_ph_lp_selected = null;
12901258
}
12911259

1292-
if (config.mode === 'edit') {
1293-
hideHighlight();
1260+
// Highlight.clear() handles both outline restoration and overlay removal
1261+
hideHighlight();
12941262

1263+
if (config.mode === 'edit') {
12951264
// Notify handlers about cleanup
12961265
getAllToolHandlers().forEach(handler => {
12971266
if (handler.onElementCleanup) {

0 commit comments

Comments
 (0)