Skip to content

Commit d2612d9

Browse files
Merge pull request #327 from preactjs/content-box
2 parents ca4731e + 0fc8477 commit d2612d9

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/adapter/adapter/highlight.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,21 @@ export function createHightlighter(renderer: Renderer) {
7979
}
8080
}
8181

82+
let height = size.height;
83+
let width = size.width;
84+
if (size.boxSizing === "border-box") {
85+
height += size.marginTop + size.marginBottom;
86+
width += size.marginLeft + size.marginRight;
87+
}
88+
8289
render(
8390
h(Highlighter, {
8491
label,
8592
...size,
8693
top: size.top - size.marginTop,
8794
left: size.left - size.marginLeft,
88-
height: size.height + size.marginTop + size.marginBottom,
89-
width: size.width + size.marginLeft + size.marginRight,
95+
height,
96+
width,
9097
}),
9198
highlightRef,
9299
);

src/adapter/dom.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export function px2Int(input: string | null) {
99
}
1010

1111
export interface Measurements {
12+
boxSizing: string;
1213
top: number;
1314
left: number;
1415
width: number;
@@ -58,6 +59,7 @@ export function measureNode(dom: Element): Measurements {
5859
top,
5960
left,
6061
bounds: getBoundsState(r),
62+
boxSizing: s.boxSizing,
6163

6264
// Round to at most 2 decimals. This is not 100% accurate,
6365
// but good enough for our use case
@@ -85,6 +87,7 @@ export function mergeMeasure(a: Measurements, b: Measurements): Measurements {
8587
const height = Math.max(a.top + a.height, b.top + b.height) - top;
8688
const width = Math.max(a.left + a.width, b.left + b.width) - left;
8789
return {
90+
boxSizing: a.boxSizing,
8891
top,
8992
left,
9093
bounds: getBoundsState({

src/view/components/Highlighter.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface Props extends Measurements {
2323
}
2424

2525
export function Highlighter(props: Props) {
26-
const { width, height, top, left, bounds } = props;
26+
const { width, height, boxSizing, top, left, bounds } = props;
2727

2828
const isOutOfBounds =
2929
bounds.bottom || bounds.left || bounds.right || bounds.top;
@@ -59,7 +59,15 @@ export function Highlighter(props: Props) {
5959
props.paddingRight,
6060
props.paddingBottom,
6161
props.paddingLeft,
62-
)}`}
62+
)} ${
63+
boxSizing === "content-box"
64+
? `height: calc(100% - ${
65+
props.paddingTop + props.paddingBottom
66+
}px); width: calc(100% - ${
67+
props.paddingLeft + props.paddingRight
68+
}px);`
69+
: ""
70+
}`}
6371
/>
6472
</div>
6573
</div>

0 commit comments

Comments
 (0)