Skip to content

Commit

Permalink
safely adjust selections for scale
Browse files Browse the repository at this point in the history
  • Loading branch information
Zasa-san committed Dec 23, 2024
1 parent 2e8b1cc commit 6fe16ca
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ const adjustSelectionsToScale = (
scalingFactor: number,
normalize?: boolean
): TextSelection => {
if (scalingFactor === 1) {
if (scalingFactor === 1 || scalingFactor === 0) {
return selection;
}

const scaledSelection = { ...selection };

if (scaledSelection.selectionRectangles.length) {
if (scaledSelection.selectionRectangles?.length) {
scaledSelection.selectionRectangles = selection.selectionRectangles.map(rectangle => {
const left = rectangle.left || 0;
const top = rectangle.top || 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,9 @@ describe('PDF selections handlers', () => {
});

describe('adjust selections to pdf scale', () => {
it('should return the original selection if there is no scaling', () => {
it('should return the original selection if there is no valid scaling', () => {
expect(adjustSelectionsToScale(selections[0], 1)).toEqual(selections[0]);
expect(adjustSelectionsToScale(selections[0], 0)).toEqual(selections[0]);
});

it('should return the same selections if the rectangles are empty', () => {
Expand Down

0 comments on commit 6fe16ca

Please sign in to comment.