Skip to content

Commit 0973692

Browse files
committed
fix: make sure info box is within live preview bounds
1 parent 88e960e commit 0973692

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,18 @@ function RemoteFunctions(config) {
991991
}
992992
}
993993

994+
// to make sure that the info box stays under the viewport width
995+
const viewportWidth = window.innerWidth;
996+
const margin = 10;
997+
998+
// horizontal boundary checking
999+
if (leftPos + boxWidth + margin > viewportWidth + scrollLeft) {
1000+
leftPos = viewportWidth + scrollLeft - boxWidth - margin;
1001+
}
1002+
if (leftPos < scrollLeft + margin) {
1003+
leftPos = scrollLeft + margin;
1004+
}
1005+
9941006
const styles = `
9951007
.box {
9961008
background-color: #4285F4;
@@ -1583,6 +1595,20 @@ function RemoteFunctions(config) {
15831595
_clickHighlight.selector = rule;
15841596
}
15851597

1598+
// recreate UI boxes (info box and more options box)
1599+
function redrawUIBoxes() {
1600+
if (_nodeMoreOptionsBox) {
1601+
const element = _nodeMoreOptionsBox.element;
1602+
_nodeMoreOptionsBox.remove();
1603+
_nodeMoreOptionsBox = new NodeMoreOptionsBox(element);
1604+
1605+
if (_nodeInfoBox) {
1606+
_nodeInfoBox.remove();
1607+
_nodeInfoBox = new NodeInfoBox(element, true); // true means it came from a click
1608+
}
1609+
}
1610+
}
1611+
15861612
// redraw active highlights
15871613
function redrawHighlights() {
15881614
if (_remoteHighlight) {
@@ -1594,19 +1620,15 @@ function RemoteFunctions(config) {
15941620
if (_hoverHighlight) {
15951621
_hoverHighlight.redraw();
15961622
}
1597-
if (_nodeMoreOptionsBox) {
1598-
const element = _nodeMoreOptionsBox.element;
1599-
_nodeMoreOptionsBox.remove();
1600-
_nodeMoreOptionsBox = new NodeMoreOptionsBox(element);
1623+
}
16011624

1602-
if (_nodeInfoBox) {
1603-
_nodeInfoBox.remove();
1604-
_nodeInfoBox = new NodeInfoBox(element, true); // true means it came from a click
1605-
}
1606-
}
1625+
// just a wrapper function when we need to redraw highlights as well as UI boxes
1626+
function redrawEverything() {
1627+
redrawHighlights();
1628+
redrawUIBoxes();
16071629
}
16081630

1609-
window.addEventListener("resize", redrawHighlights);
1631+
window.addEventListener("resize", redrawEverything);
16101632
// Add a capture-phase scroll listener to update highlights when
16111633
// any element scrolls.
16121634

@@ -1875,7 +1897,7 @@ function RemoteFunctions(config) {
18751897
this.rememberedNodes = {};
18761898

18771899
// update highlight after applying diffs
1878-
redrawHighlights();
1900+
redrawEverything();
18791901
};
18801902

18811903
function applyDOMEdits(edits) {
@@ -2164,6 +2186,7 @@ function RemoteFunctions(config) {
21642186
"highlight" : highlight,
21652187
"highlightRule" : highlightRule,
21662188
"redrawHighlights" : redrawHighlights,
2189+
"redrawEverything" : redrawEverything,
21672190
"applyDOMEdits" : applyDOMEdits,
21682191
"getSimpleDOM" : getSimpleDOM,
21692192
"updateConfig" : updateConfig,

0 commit comments

Comments
 (0)