Skip to content

Commit 3e212c3

Browse files
committed
feat: don’t show the interactive controls when user selects an element via editor
1 parent f67ce55 commit 3e212c3

1 file changed

Lines changed: 25 additions & 18 deletions

File tree

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,11 @@ function RemoteFunctions(config = {}) {
507507
/**
508508
* this function is responsible to select an element in the live preview
509509
* @param {Element} element - The DOM element to select
510+
* @param {boolean} [fromEditor] - If true, this is an editor-cursor-driven selection;
511+
* only lightweight highlights (outline + margin/padding) are shown, not interactive
512+
* UI like control box, spacing handles, or measurements.
510513
*/
511-
function selectElement(element) {
514+
function selectElement(element, fromEditor) {
512515
dismissUIAndCleanupState();
513516
// this should also be there when users are in highlight mode
514517
scrollElementToViewPort(element);
@@ -517,23 +520,27 @@ function RemoteFunctions(config = {}) {
517520
return false;
518521
}
519522

520-
// when user clicks on a non-editable element
521-
if (!element.hasAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR)) {
522-
getAllToolHandlers().forEach(handler => {
523-
if (handler.onNonEditableElementClick) {
524-
handler.onNonEditableElementClick(element);
525-
}
526-
});
527-
}
523+
// Only invoke tool handlers for user-initiated clicks in the live preview,
524+
// not for editor cursor movements which should only show lightweight highlights
525+
if (!fromEditor) {
526+
// when user clicks on a non-editable element
527+
if (!element.hasAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR)) {
528+
getAllToolHandlers().forEach(handler => {
529+
if (handler.onNonEditableElementClick) {
530+
handler.onNonEditableElementClick(element);
531+
}
532+
});
533+
}
528534

529-
// make sure that the element is actually visible to the user
530-
if (isElementVisible(element)) {
531-
// Notify handlers about element selection
532-
getAllToolHandlers().forEach(handler => {
533-
if (handler.onElementSelected) {
534-
handler.onElementSelected(element);
535-
}
536-
});
535+
// make sure that the element is actually visible to the user
536+
if (isElementVisible(element)) {
537+
// Notify handlers about element selection
538+
getAllToolHandlers().forEach(handler => {
539+
if (handler.onElementSelected) {
540+
handler.onElementSelected(element);
541+
}
542+
});
543+
}
537544
}
538545

539546
element._originalOutline = element.style.outline;
@@ -764,7 +771,7 @@ function RemoteFunctions(config = {}) {
764771

765772
if (!skipSelection) {
766773
if (element) {
767-
selectElement(element);
774+
selectElement(element, true);
768775
} else {
769776
// No valid element found, dismiss UI
770777
dismissUIAndCleanupState();

0 commit comments

Comments
 (0)