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: Highlight selection on Surface #326

Merged
merged 6 commits into from
Jan 25, 2019
Merged
Changes from 2 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
20 changes: 10 additions & 10 deletions src/doc/DocAnnotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,15 @@ class DocAnnotator extends Annotator {
this.selectionEndTimeout = null;
}

this.resetHighlightOnOutsideClick(event);
if (!this.isCreatingHighlight) {
pramodsum marked this conversation as resolved.
Show resolved Hide resolved
this.resetHighlightOnOutsideClick(event);
}

// Do nothing if in a text area or mobile dialog or mobile create dialog is already open
const pointController = this.modeControllers[TYPES.point];
const isCreatingPoint = !!(pointController && pointController.pendingThreadID);
const isPopoverActive = !!util.findClosestElWithClass(document.activeElement, CLASS_ANNOTATION_POPOVER);
if (this.isCreatingHighlight || isCreatingPoint || isPopoverActive) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should re-show the create dialog on selection change so that the position updates

if (isCreatingPoint || isPopoverActive) {
return;
}

Expand All @@ -577,7 +579,7 @@ class DocAnnotator extends Annotator {
}

this.selectionEndTimeout = setTimeout(() => {
if (this.createHighlightDialog && !this.createHighlightDialog.isVisible) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensures create dialog is re-positioned on timeout

if (this.createHighlightDialog) {
this.createHighlightDialog.show(this.lastSelection);
}
}, SELECTION_TIMEOUT);
Expand All @@ -594,12 +596,8 @@ class DocAnnotator extends Annotator {
this.modeControllers[TYPES.highlight_comment].applyActionToThreads((thread) => thread.reset(), page);
}

let mouseEvent = event;
// $FlowFixMe
if (this.hasTouch && event.targetTouches) {
mouseEvent = event.targetTouches[0];
}
this.lastHighlightEvent = mouseEvent;
this.lastHighlightEvent = this.hasTouch && event.targetTouches ? event.targetTouches[0] : event;
pramodsum marked this conversation as resolved.
Show resolved Hide resolved
this.lastSelection = selection;
}

Expand Down Expand Up @@ -774,15 +772,17 @@ class DocAnnotator extends Annotator {
* Bail if mid highlight and click is outside highlight/selection
*
* @param {Event} event - Mouse event
* @return {void}
* @return {boolean} - Whether or not event was consumed
*/
resetHighlightOnOutsideClick(event: Event) {
resetHighlightOnOutsideClick(event: Event): boolean {
const selection = window.getSelection();
const isClickOutsideCreateDialog = this.isCreatingHighlight && !util.isInDialog(event);
if (!docUtil.isValidSelection(selection) && isClickOutsideCreateDialog) {
this.lastHighlightEvent = null;
this.resetHighlightSelection(event);
return true;
pramodsum marked this conversation as resolved.
Show resolved Hide resolved
}
return false;
}

/**
Expand Down