Skip to content

Commit

Permalink
[Bugfix] Fix pen tool blocking non-annotation mouse down actions (Sub…
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterOdin authored Sep 5, 2021
1 parent 8ffad71 commit 6ea7550
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 17 deletions.
15 changes: 8 additions & 7 deletions src/UI/pen.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ let lines = [];
function handleDocumentPointerdown(e) {
path = null;
lines = [];
_candraw = true;
/* if (!e.srcElement.classList.contains('annotationLayer')) {
if (!findSVGAtPoint(e.clientX, e.clientY)) {
return;
} */
}
_candraw = true;
e.preventDefault();
}

Expand All @@ -39,6 +39,9 @@ function handleDocumentPointerup(e) {
}

function saveToStorage(x, y) {
if (!_candraw) {
return;
}
_candraw = false;
let svg;
if (lines.length > 1 && (svg = findSVGAtPoint(x, y))) {
Expand All @@ -64,12 +67,10 @@ function saveToStorage(x, y) {
* @param {PointerEvent} e The DOM event to be handled
*/
function handleDocumentPointermove(e) {
if (!e.srcElement.classList.contains('annotationLayer')) {
if (!findSVGAtPoint(e.clientX, e.clientY) || !_candraw) {
return;
}
if (_candraw) {
savePoint(e.clientX, e.clientY);
}
savePoint(e.clientX, e.clientY);
}

/**
Expand Down
55 changes: 45 additions & 10 deletions test/UI/pen.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { equal, deepStrictEqual } from 'assert';
import { deepStrictEqual, strictEqual } from 'assert';
import PDFJSAnnotate from '../../src/PDFJSAnnotate';
import { firePointerEvent } from '../fireEvent';
import mockAddAnnotation from '../mockAddAnnotation';
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('UI::pen', function() {
disablePen();
simulateCreateDrawingAnnotation();
setTimeout(function() {
equal(addAnnotationSpy.called, false);
strictEqual(addAnnotationSpy.called, false);
done();
}, 0);
});
Expand All @@ -79,14 +79,49 @@ describe('UI::pen', function() {
enablePen();
simulateCreateDrawingAnnotation();
setTimeout(function() {
equal(addAnnotationSpy.called, true);
let args = addAnnotationSpy.getCall(0).args;
equal(args[0], 'test-document-id');
equal(args[1], '1');
equal(args[2].type, 'drawing');
equal(args[2].width, 1);
equal(args[2].color, '000000');
equal(args[2].lines.length, 2);
strictEqual(addAnnotationSpy.called, true);
const args = addAnnotationSpy.getCall(0).args;
strictEqual(args[0], 'test-document-id');
strictEqual(args[1], 1);
strictEqual(args[2].type, 'drawing');
strictEqual(args[2].width, 1);
strictEqual(args[2].color, '000000');
strictEqual(args[2].lines.length, 2);
done();
}, 0);
});

it('should not create annotation if started outside annotation layer', (done) => {
disablePen();
enablePen();
setPen();

firePointerEvent(svg, 'pointerdown', {
clientX: 2000,
clientY: 10,
pointerType: 'mouse'
});

firePointerEvent(svg, 'pointermove', {
clientX: 15,
clientY: 15,
pointerType: 'mouse'
});

firePointerEvent(svg, 'pointermove', {
clientX: 30,
clientY: 30,
pointerType: 'mouse'
});

firePointerEvent(svg, 'pointerup', {
clientX: 30,
clientY: 30,
pointerType: 'mouse'
});

setTimeout(() => {
strictEqual(addAnnotationSpy.called, false);
done();
}, 0);
});
Expand Down

0 comments on commit 6ea7550

Please sign in to comment.