Skip to content

Commit 36c692f

Browse files
committed
feat: remove boxes when escape key is pressed or user clicks on a empty area
1 parent 869f79a commit 36c692f

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,12 @@ function RemoteFunctions(config) {
13771377
event.target._originalOutline = event.target.style.outline;
13781378
event.target.style.outline = "1px solid #4285F4";
13791379
previouslyClickedElement = event.target;
1380+
} else if ( // when user clicks on the HTML or the BODY tag, we want to remove the boxes
1381+
isFlagActive &&
1382+
_nodeMoreOptionsBox &&
1383+
(event.target.tagName === "HTML" || event.target.tagName === "BODY")
1384+
) {
1385+
dismissMoreOptionsBox();
13801386
}
13811387
}
13821388

@@ -1394,6 +1400,9 @@ function RemoteFunctions(config) {
13941400
}
13951401

13961402
function onKeyDown(event) {
1403+
if ((event.key === "Escape" || event.key === "Esc")) {
1404+
dismissMoreOptionsBox();
1405+
}
13971406
if (!_setup && _validEvent(event)) {
13981407
window.document.addEventListener("keyup", onKeyUp);
13991408
window.document.addEventListener("mouseover", onMouseOver);
@@ -1838,6 +1847,32 @@ function RemoteFunctions(config) {
18381847
return JSON.stringify(config);
18391848
}
18401849

1850+
/**
1851+
* This function is responsible to remove the more options box
1852+
* we do this either when user presses the Esc key or clicks on the HTML or Body tags
1853+
*/
1854+
function dismissMoreOptionsBox() {
1855+
if (_nodeMoreOptionsBox) {
1856+
_nodeMoreOptionsBox.remove();
1857+
_nodeMoreOptionsBox = null;
1858+
}
1859+
1860+
if (_nodeInfoBox) {
1861+
_nodeInfoBox.remove();
1862+
_nodeInfoBox = null;
1863+
}
1864+
1865+
if (previouslyClickedElement) {
1866+
if (previouslyClickedElement._originalOutline !== undefined) {
1867+
previouslyClickedElement.style.outline = previouslyClickedElement._originalOutline;
1868+
} else {
1869+
previouslyClickedElement.style.outline = "";
1870+
}
1871+
delete previouslyClickedElement._originalOutline;
1872+
previouslyClickedElement = null;
1873+
}
1874+
}
1875+
18411876
// Function to handle direct editing of elements in the live preview
18421877
function startEditing(element) {
18431878
if (!element) {
@@ -1989,10 +2024,7 @@ function RemoteFunctions(config) {
19892024
window.document.addEventListener("click", onClick);
19902025
window.document.addEventListener("dragover", onDragOver);
19912026
window.document.addEventListener("drop", onDrop);
1992-
1993-
if (experimental) {
1994-
window.document.addEventListener("keydown", onKeyDown);
1995-
}
2027+
window.document.addEventListener("keydown", onKeyDown);
19962028

19972029
return {
19982030
"DOMEditHandler" : DOMEditHandler,

0 commit comments

Comments
 (0)