Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Don't trigger highlight if a new highlight is being created #265

Merged
merged 1 commit into from
Jul 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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