Skip to content

Commit

Permalink
Fix: Reset create highlight UI when mouse hasn't moved on mouseup (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum authored Nov 19, 2018
1 parent a01db9f commit 4abd611
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/doc/DocAnnotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,8 @@ class DocAnnotator extends Annotator {
// we trigger the create handler instead of the click handler
if ((this.createHighlightDialog && hasMouseMoved) || event.type === 'dblclick') {
this.highlightCreateHandler(event);
} else {
this.resetHighlightSelection(event);
}
};

Expand Down
9 changes: 9 additions & 0 deletions src/doc/__tests__/DocAnnotator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -750,17 +750,26 @@ describe('doc/DocAnnotator', () => {
describe('highlightMouseupHandler()', () => {
beforeEach(() => {
annotator.highlightCreateHandler = jest.fn();
annotator.resetHighlightSelection = jest.fn();
annotator.mouseDownEvent = { clientX: 100, clientY: 100 };
});

it('should call highlightCreateHandler if on desktop and the mouse moved', () => {
annotator.highlightMouseupHandler({ x: 0, y: 0 });
expect(annotator.highlightCreateHandler).toBeCalled();
expect(annotator.resetHighlightSelection).not.toBeCalled();
});

it('should call highlightCreateHandler if on desktop and the user double clicked', () => {
annotator.highlightMouseupHandler({ type: 'dblclick' });
expect(annotator.highlightCreateHandler).toBeCalled();
expect(annotator.resetHighlightSelection).not.toBeCalled();
});

it('should reset highlight selection when mouse has not moved', () => {
annotator.highlightMouseupHandler(annotator.mouseDownEvent);
expect(annotator.highlightCreateHandler).not.toBeCalled();
expect(annotator.resetHighlightSelection).toBeCalled();
});

it('should call highlighter.removeAllHighlghts', () => {
Expand Down

0 comments on commit 4abd611

Please sign in to comment.