Skip to content

Commit

Permalink
Fix: Don't trigger highlight if a new highlight is being created (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum authored Jul 31, 2017
1 parent 4de1259 commit 9ab6db4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/lib/annotations/doc/DocAnnotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ class DocAnnotator extends Annotator {
return null;
}
this.createHighlightDialog.hide();
this.isCreatingHighlight = false;

const location = this.getLocationFromEvent(this.lastHighlightEvent, TYPES.highlight);
if (!location) {
Expand Down Expand Up @@ -576,6 +577,12 @@ class DocAnnotator extends Annotator {
return;
}

// Determine if user is in the middle of creating a highlight
// annotation and ignore hover events of any highlights below
if (this.isCreatingHighlight) {
return;
}

// Determine if mouse is over any highlight dialog
// and ignore hover events of any highlights below
const event = this.mouseMoveEvent;
Expand Down Expand Up @@ -669,6 +676,8 @@ class DocAnnotator extends Annotator {
this.highlighter.removeAllHighlights();
}
this.createHighlightDialog.hide();
this.isCreatingHighlight = false;

// Creating highlights is disabled on mobile for now since the
// event we would listen to, selectionchange, fires continuously and
// is unreliable. If the mouse moved or we double clicked text,
Expand All @@ -678,7 +687,6 @@ class DocAnnotator extends Annotator {
} else {
this.highlightClickHandler(event);
}
this.isCreatingHighlight = false;
}

/**
Expand Down Expand Up @@ -724,6 +732,7 @@ class DocAnnotator extends Annotator {
if (!this.isMobile) {
this.createHighlightDialog.setPosition(right - pageLeft, bottom - pageTop);
}
this.isCreatingHighlight = true;

this.lastHighlightEvent = event;
}
Expand Down
14 changes: 14 additions & 0 deletions src/lib/annotations/doc/__tests__/DocAnnotator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,18 +694,32 @@ describe('lib/annotations/doc/DocAnnotator', () => {
stubs.getPageInfo = stubs.getPageInfo.returns({ pageEl: {}, page: 1 });
stubs.getThreads = sandbox.stub(annotator, 'getHighlightThreadsOnPage');
stubs.clock = sinon.useFakeTimers();
stubs.isDialog = sandbox.stub(docAnnotatorUtil, 'isDialogDataType');

let timer = 0;
window.performance = window.performance || { now: () => {} };
sandbox.stub(window.performance, 'now', () => {
return (timer += 500);
});

annotator.isCreatingHighlight = false;
});

afterEach(() => {
stubs.clock.restore();
});

it('should not do anything if user is creating a highlight', () => {
stubs.threadMock.expects('onMousemove').returns(false).never();
stubs.delayMock.expects('onMousemove').returns(true).never();
stubs.getThreads.returns([stubs.thread, stubs.delayThread]);
annotator.isCreatingHighlight = true;

annotator.mouseMoveEvent = { clientX: 3, clientY: 3 };
annotator.onHighlightCheck();
expect(stubs.isDialog).to.not.be.called;
});

it('should not add any delayThreads if there are no threads on the current page', () => {
stubs.threadMock.expects('onMousemove').returns(false).never();
stubs.delayMock.expects('onMousemove').returns(true).never();
Expand Down

0 comments on commit 9ab6db4

Please sign in to comment.