Handle selectionchange event. Fixes #1140

This commit is contained in:
Francisco Hodge
2021-07-18 10:06:34 -07:00
parent f20221eae2
commit 7e256907b8
3 changed files with 19 additions and 2 deletions
+14 -1
View File
@@ -1048,6 +1048,7 @@ class SimpleKeyboard {
document.addEventListener("mouseup", this.handleMouseUp);
document.addEventListener("touchend", this.handleTouchEnd);
document.addEventListener("select", this.handleSelect);
document.addEventListener("selectionchange", this.handleSelectionChange);
}
}
@@ -1094,6 +1095,14 @@ class SimpleKeyboard {
this.caretEventHandler(event);
}
/**
* Event Handler: SelectionChange
*/
/* istanbul ignore next */
handleSelectionChange(event: KeyboardHandlerEvent): void {
this.caretEventHandler(event);
}
/**
* Called by {@link setEventListeners} when an event that warrants a cursor position update is triggered
*/
@@ -1143,7 +1152,10 @@ class SimpleKeyboard {
`(${instance.keyboardDOMClass})`
);
}
} else if (instance.options.disableCaretPositioning || !isKeyboard) {
} else if (
(instance.options.disableCaretPositioning || !isKeyboard) &&
event?.type !== "selectionchange"
) {
/**
* If we toggled off disableCaretPositioning, we must ensure caretPosition doesn't persist once reactivated.
*/
@@ -1192,6 +1204,7 @@ class SimpleKeyboard {
document.removeEventListener("mouseup", this.handleMouseUp);
document.removeEventListener("touchend", this.handleTouchEnd);
document.removeEventListener("select", this.handleSelect);
document.removeEventListener("selectionchange", this.handleSelectionChange);
document.onpointerup = null;
document.ontouchend = null;
document.ontouchcancel = null;