diff --git a/src/highlight/__tests__/highlightUtil-test.ts b/src/highlight/__tests__/highlightUtil-test.ts index 21acfb5a1..575065514 100644 --- a/src/highlight/__tests__/highlightUtil-test.ts +++ b/src/highlight/__tests__/highlightUtil-test.ts @@ -36,6 +36,20 @@ const shape4: Shape = { y: -4, }; +const noWidthShape: Shape = { + height: 10, + width: 0, + x: 10, + y: 10, +}; + +const noHeightShape: Shape = { + height: 0, + width: 10, + x: 10, + y: 10, +}; + describe('highlightUtil', () => { describe('getBoundingRect()', () => { test('should be the same rect for a single shape', () => { @@ -59,6 +73,15 @@ describe('highlightUtil', () => { y: -4, }); }); + + test('should get the bounding rect for multiple shapes, excluding 0 width and height values', () => { + expect(getBoundingRect([shape3, shape4, noWidthShape, noHeightShape])).toEqual({ + height: 3, + width: 4, + x: -2, + y: -4, + }); + }); }); describe('centerHighlight()', () => { diff --git a/src/highlight/highlightUtil.ts b/src/highlight/highlightUtil.ts index d6f59cb89..11f92aea2 100644 --- a/src/highlight/highlightUtil.ts +++ b/src/highlight/highlightUtil.ts @@ -10,6 +10,11 @@ export const getBoundingRect = (shapes: Shape[]): Shape => { const x2 = x + width; const y2 = y + height; + // Ignore empty rects with a width or height of 0 + if (width === 0 || height === 0) { + return; + } + if (x < minX) { minX = x; }