Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 70901f2

Browse files
authored
Merge pull request #13297 from Worie/worie/13274-lp-highlight-transform
Fix #13274 - make Brackets margin/padding remoteHighlight work like Chrome one
2 parents 12d583f + ad915c7 commit 70901f2

2 files changed

Lines changed: 40 additions & 31 deletions

File tree

src/LiveDevelopment/Agents/RemoteFunctions.js

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ function RemoteFunctions(config, remoteWSPort) {
275275
elementStyling = window.getComputedStyle(element),
276276
transitionDuration = parseFloat(elementStyling.getPropertyValue('transition-duration')),
277277
animationDuration = parseFloat(elementStyling.getPropertyValue('animation-duration'));
278-
278+
279279
if (transitionDuration) {
280280
animateHighlight(transitionDuration);
281281
}
@@ -296,8 +296,21 @@ function RemoteFunctions(config, remoteWSPort) {
296296
bottom: elementStyling.getPropertyValue('border-bottom-width')
297297
};
298298

299-
var innerWidth = elementBounds.width - parseInt(realElBorder.left) - parseInt(realElBorder.right);
300-
var innerHeight = elementBounds.height - parseInt(realElBorder.top) - parseInt(realElBorder.bottom);
299+
var borderBox = elementStyling.boxSizing === 'border-box';
300+
301+
var innerWidth = parseInt(elementStyling.width),
302+
innerHeight = parseInt(elementStyling.height),
303+
outerHeight = innerHeight,
304+
outerWidth = innerWidth;
305+
306+
if (!borderBox) {
307+
innerWidth += parseInt(elementStyling.paddingLeft) + parseInt(elementStyling.paddingRight);
308+
innerHeight += parseInt(elementStyling.paddingTop) + parseInt(elementStyling.paddingBottom);
309+
outerWidth = innerWidth + parseInt(realElBorder.right) +
310+
parseInt(realElBorder.left),
311+
outerHeight = innerHeight + parseInt(realElBorder.bottom) + parseInt(realElBorder.top);
312+
}
313+
301314

302315
var visualisations = {
303316
horizontal: "left, right",
@@ -306,19 +319,27 @@ function RemoteFunctions(config, remoteWSPort) {
306319

307320
var drawPaddingRect = function(side) {
308321
var elStyling = {};
309-
322+
310323
if (visualisations.horizontal.indexOf(side) >= 0) {
311324
elStyling['width'] = elementStyling.getPropertyValue('padding-' + side);
312-
elStyling['height'] = innerHeight + "px";
313-
elStyling['top'] = realElBorder.top;
325+
elStyling['height'] = innerHeight + "px";
326+
elStyling['top'] = 0;
327+
328+
if (borderBox) {
329+
elStyling['height'] = innerHeight - parseInt(realElBorder.top) - parseInt(realElBorder.bottom) + "px";
330+
}
314331

315332
} else {
316333
elStyling['height'] = elementStyling.getPropertyValue('padding-' + side);
317334
elStyling['width'] = innerWidth + "px";
318-
elStyling['left'] = realElBorder.left;
335+
elStyling['left'] = 0;
336+
337+
if (borderBox) {
338+
elStyling['width'] = innerWidth - parseInt(realElBorder.left) - parseInt(realElBorder.right) + "px";
339+
}
319340
}
320-
321-
elStyling[side] = realElBorder[side];
341+
342+
elStyling[side] = 0;
322343
elStyling['position'] = 'absolute';
323344

324345
return elStyling;
@@ -333,19 +354,18 @@ function RemoteFunctions(config, remoteWSPort) {
333354
margin['bottom'] = parseInt(elementStyling.getPropertyValue('margin-bottom'));
334355
margin['left'] = parseInt(elementStyling.getPropertyValue('margin-left'));
335356

336-
337357
if(visualisations['horizontal'].indexOf(side) >= 0) {
338-
elStyling['width'] = elementStyling.getPropertyValue('margin-' + side);
339-
elStyling['height'] = elementBounds.height + margin['top'] + margin['bottom'] + "px";
340-
elStyling['top'] = "-" + margin['top'] + "px";
341358

359+
elStyling['width'] = elementStyling.getPropertyValue('margin-' + side);
360+
elStyling['height'] = outerHeight + margin['top'] + margin['bottom'] + "px";
361+
elStyling['top'] = "-" + (margin['top'] + parseInt(realElBorder.top)) + "px";
342362
} else {
343-
elStyling['height'] = elementStyling.getPropertyValue('margin-' + side);
344-
elStyling['width'] = elementBounds.width + "px";
345-
elStyling['left'] = 0;
363+
elStyling['height'] = elementStyling.getPropertyValue('margin-' + side);
364+
elStyling['width'] = outerWidth + "px";
365+
elStyling['left'] = "-" + realElBorder.left;
346366
}
347367

348-
elStyling[side] = "-" + margin[side] + "px";
368+
elStyling[side] = "-" + (margin[side] + parseInt(realElBorder[side])) + "px";
349369
elStyling['position'] = 'absolute';
350370

351371
return elStyling;
@@ -364,7 +384,6 @@ function RemoteFunctions(config, remoteWSPort) {
364384
};
365385

366386
var mainBoxStyles = config.remoteHighlight.stylesToSet;
367-
mainBoxStyles['border'] = 'none';
368387

369388
var paddingVisualisations = [
370389
drawPaddingRect('top'),
@@ -386,7 +405,6 @@ function RemoteFunctions(config, remoteWSPort) {
386405
setVisibility(arr[i]);
387406

388407
// Applies to every visualisationElement (padding or margin div)
389-
arr[i]["box-sizing"] = "border-box";
390408
arr[i]["transform"] = "none";
391409
var el = window.document.createElement("div"),
392410
styles = Object.assign(
@@ -424,13 +442,6 @@ function RemoteFunctions(config, remoteWSPort) {
424442
"padding": 0,
425443
"position": "absolute",
426444
"pointer-events": "none",
427-
"border-top-left-radius": elementStyling.borderTopLeftRadius,
428-
"border-top-right-radius": elementStyling.borderTopRightRadius,
429-
"border-bottom-left-radius": elementStyling.borderBottomLeftRadius,
430-
"border-bottom-right-radius": elementStyling.borderBottomRightRadius,
431-
"border-style": "solid",
432-
"border-width": "1px",
433-
"border-color": "#00a2ff",
434445
"box-shadow": "0 0 1px #fff",
435446
"box-sizing": "border-box"
436447
};
@@ -1019,10 +1030,10 @@ function RemoteFunctions(config, remoteWSPort) {
10191030
_ws.onopen = function () {
10201031
window.document.addEventListener("click", onDocumentClick);
10211032
};
1022-
1033+
10231034
_ws.onmessage = function (evt) {
10241035
};
1025-
1036+
10261037
_ws.onclose = function () {
10271038
// websocket is closed
10281039
window.document.removeEventListener("click", onDocumentClick);

src/LiveDevelopment/main.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ define(function main(require, exports, module) {
9898
"marginStyling": {
9999
"background-color": "rgba(21, 165, 255, 0.58)"
100100
},
101-
"stylesToSet": {
102-
"border-width": "1px"
103-
},
101+
"borderColor": "rgba(21, 165, 255, 0.85)",
104102
"showPaddingMargin": true
105103
}, {
106104
description: "LivePreview highlight settings"

0 commit comments

Comments
 (0)