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: Prevent creation of highlights when a point annotation is pending #41

Merged
merged 1 commit into from
Nov 20, 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
6 changes: 6 additions & 0 deletions src/doc/DocAnnotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,12 @@ class DocAnnotator extends Annotator {

this.isCreatingHighlight = false;

// Prevent the creation of highlights if the user is currently creating a point annotation
const pointController = this.modeControllers[TYPES.point];
if (pointController && pointController.hadPendingThreads) {
return;
}

// 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 Down
10 changes: 10 additions & 0 deletions src/doc/__tests__/DocAnnotator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,16 @@ describe('doc/DocAnnotator', () => {
stubs.click = sandbox.stub(annotator, 'highlightClickHandler');
});

it('should not trigger a highlight or creation if a point annotation is pending', () => {
annotator.modeControllers = {
'point': { hadPendingThreads: true }
};
annotator.highlightMouseupHandler({});
expect(stubs.create).to.not.be.called;
expect(stubs.click).to.not.be.called;
expect(annotator.isCreatingHighlight).to.be.false;
})

it('should call highlightCreateHandler if not on mobile, and the user double clicked', () => {
annotator.highlightMouseupHandler({ type: 'dblclick' });
expect(stubs.create).to.be.called;
Expand Down