Skip to content

Commit

Permalink
fix(highlight): Ignore empty rects when calculating bounding rect (#696)
Browse files Browse the repository at this point in the history
* fix(tooltip): Fix highlight promo tooltip for pdfjs upgrade

* fix(highlight): Ignore empty rects when calculating bounding rect
  • Loading branch information
karelee7 authored Jul 6, 2022
1 parent ef1fcbc commit aa28eb4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/highlight/__tests__/highlightUtil-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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()', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/highlight/highlightUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit aa28eb4

Please sign in to comment.