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

File diff suppressed because one or more lines are too long

View File

@ -198,6 +198,10 @@ declare class SimpleKeyboard {
* Event Handler: Select * Event Handler: Select
*/ */
handleSelect(event: KeyboardHandlerEvent): void; handleSelect(event: KeyboardHandlerEvent): void;
/**
* Event Handler: SelectionChange
*/
handleSelectionChange(event: KeyboardHandlerEvent): void;
/** /**
* Called by {@link setEventListeners} when an event that warrants a cursor position update is triggered * Called by {@link setEventListeners} when an event that warrants a cursor position update is triggered
*/ */

View File

@ -1048,6 +1048,7 @@ class SimpleKeyboard {
document.addEventListener("mouseup", this.handleMouseUp); document.addEventListener("mouseup", this.handleMouseUp);
document.addEventListener("touchend", this.handleTouchEnd); document.addEventListener("touchend", this.handleTouchEnd);
document.addEventListener("select", this.handleSelect); document.addEventListener("select", this.handleSelect);
document.addEventListener("selectionchange", this.handleSelectionChange);
} }
} }
@ -1094,6 +1095,14 @@ class SimpleKeyboard {
this.caretEventHandler(event); 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 * Called by {@link setEventListeners} when an event that warrants a cursor position update is triggered
*/ */
@ -1143,7 +1152,10 @@ class SimpleKeyboard {
`(${instance.keyboardDOMClass})` `(${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. * 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("mouseup", this.handleMouseUp);
document.removeEventListener("touchend", this.handleTouchEnd); document.removeEventListener("touchend", this.handleTouchEnd);
document.removeEventListener("select", this.handleSelect); document.removeEventListener("select", this.handleSelect);
document.removeEventListener("selectionchange", this.handleSelectionChange);
document.onpointerup = null; document.onpointerup = null;
document.ontouchend = null; document.ontouchend = null;
document.ontouchcancel = null; document.ontouchcancel = null;