From 4abd611001a1e77759e347dad67548d81284ccf2 Mon Sep 17 00:00:00 2001 From: Sumedha Pramod Date: Mon, 19 Nov 2018 11:17:26 -0800 Subject: [PATCH] Fix: Reset create highlight UI when mouse hasn't moved on mouseup (#290) --- src/doc/DocAnnotator.js | 2 ++ src/doc/__tests__/DocAnnotator-test.js | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/doc/DocAnnotator.js b/src/doc/DocAnnotator.js index dd485f22a..da408d2af 100644 --- a/src/doc/DocAnnotator.js +++ b/src/doc/DocAnnotator.js @@ -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); } }; diff --git a/src/doc/__tests__/DocAnnotator-test.js b/src/doc/__tests__/DocAnnotator-test.js index 7ec1f2adc..a01aa7bfa 100644 --- a/src/doc/__tests__/DocAnnotator-test.js +++ b/src/doc/__tests__/DocAnnotator-test.js @@ -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', () => {