Skip to content

Commit 85abfad

Browse files
devvaannshabose
authored andcommitted
feat: add api for controlling visibility of margin padding in element selection for styles bar
1 parent 95985fe commit 85abfad

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

‎src/LiveDevelopment/BrowserScripts/RemoteFunctions.js‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ function RemoteFunctions(config = {}) {
2626
const SHARED_STATE = {
2727
__description: "Use this to keep shared state for Live Preview Edit instead of window.*",
2828
_suppressDOMEditDismissal: false,
29-
_suppressDOMEditDismissalTimeout: null
29+
_suppressDOMEditDismissalTimeout: null,
30+
_boxModelHighlightHidden: false
3031
};
3132

3233
let _hoverHighlight;
@@ -449,15 +450,17 @@ function RemoteFunctions(config = {}) {
449450
s.backgroundColor = color;
450451
}
451452

452-
// Padding region
453-
const padColor = COLORS.highlightPadding;
453+
// Padding region. Rects stay in place when hidden, only their fill goes away,
454+
// so nothing has to be rebuilt when they come back.
455+
const boxModelHidden = SHARED_STATE._boxModelHighlightHidden;
456+
const padColor = boxModelHidden ? "transparent" : COLORS.highlightPadding;
454457
setRect(refs.padTop, paddingBox.left, paddingBox.top, paddingBox.width, pt, padColor);
455458
setRect(refs.padBottom, paddingBox.left, contentBox.top + contentBox.height, paddingBox.width, pb, padColor);
456459
setRect(refs.padLeft, paddingBox.left, contentBox.top, pl, contentBox.height, padColor);
457460
setRect(refs.padRight, contentBox.left + contentBox.width, contentBox.top, pr, contentBox.height, padColor);
458461

459462
// Margin region
460-
const margColor = COLORS.highlightMargin;
463+
const margColor = boxModelHidden ? "transparent" : COLORS.highlightMargin;
461464
setRect(refs.marTop, marginBox.left, marginBox.top, marginBox.width, mt, margColor);
462465
setRect(refs.marBottom, marginBox.left, borderBox.top + borderBox.height, marginBox.width, mb, margColor);
463466
setRect(refs.marLeft, marginBox.left, borderBox.top, ml, borderBox.height, margColor);
@@ -1506,6 +1509,9 @@ function RemoteFunctions(config = {}) {
15061509
_pendingHoverRAF = null;
15071510
}
15081511

1512+
// the selection is gone, so a popover can no longer turn the fills back on
1513+
SHARED_STATE._boxModelHighlightHidden = false;
1514+
15091515
// Highlight.clear() removes all overlay divs (outline + margin/padding rects)
15101516
hideHighlight();
15111517

@@ -1766,6 +1772,21 @@ function RemoteFunctions(config = {}) {
17661772
}
17671773
}
17681774

1775+
/**
1776+
* Hide just the margin/padding fills of the selected element highlight, keeping
1777+
* the outline and the selection itself. Used while editing paint properties like
1778+
* background color, where the fills sit on top of what the user is changing.
1779+
* @param {Boolean} hidden
1780+
*/
1781+
function setBoxModelHighlightHidden(hidden) {
1782+
hidden = !!hidden;
1783+
if (SHARED_STATE._boxModelHighlightHidden === hidden) {
1784+
return;
1785+
}
1786+
SHARED_STATE._boxModelHighlightHidden = hidden;
1787+
redrawHighlights();
1788+
}
1789+
17691790
let customReturns = {};
17701791
// only apis that needs to be called from phoenix js layer should be customReturns. APis that are shared within
17711792
// the remote function context only should not be in customReturns and should be in
@@ -1789,6 +1810,7 @@ function RemoteFunctions(config = {}) {
17891810
"getHighlightTrackingElement": getHighlightTrackingElement,
17901811
"getHighlightStyle": getHighlightStyle,
17911812
"setHotCornerHidden": setHotCornerHidden,
1813+
"setBoxModelHighlightHidden": setBoxModelHighlightHidden,
17921814
"clearHoverState": _clearHoverState
17931815
};
17941816

‎src/nls/root/strings.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ define({
202202
"LIVE_DEV_STYLER_BACKGROUND": "Background color",
203203
"LIVE_DEV_STYLER_TEXT_COLOR": "Text color",
204204
"LIVE_DEV_STYLER_FONT": "Font family",
205+
"LIVE_DEV_STYLER_FONT_DEFAULT": "Default",
205206
"LIVE_DEV_STYLER_SIZE": "Font size",
206207
"LIVE_DEV_STYLER_WEIGHT": "Font weight",
207208
"LIVE_DEV_STYLER_ALIGN": "Text alignment",

0 commit comments

Comments
 (0)