mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-02-22 01:29:39 +08:00
Add updateCaretOnSelectionChange. Fixes #2346
This commit is contained in:
parent
1fd1f638c7
commit
536f3f7419
@ -137,6 +137,7 @@ class SimpleKeyboard {
|
|||||||
* @property {boolean} layoutCandidatesCaseSensitiveMatch Determines whether layout candidate match should be case sensitive.
|
* @property {boolean} layoutCandidatesCaseSensitiveMatch Determines whether layout candidate match should be case sensitive.
|
||||||
* @property {boolean} disableCandidateNormalization Disables the automatic normalization for selected layout candidates
|
* @property {boolean} disableCandidateNormalization Disables the automatic normalization for selected layout candidates
|
||||||
* @property {boolean} enableLayoutCandidatesKeyPress Enables onKeyPress triggering for layoutCandidate items
|
* @property {boolean} enableLayoutCandidatesKeyPress Enables onKeyPress triggering for layoutCandidate items
|
||||||
|
* @property {boolean} updateCaretOnSelectionChange Updates caret when selectionchange event is fired
|
||||||
*/
|
*/
|
||||||
this.options = {
|
this.options = {
|
||||||
layoutName: "default",
|
layoutName: "default",
|
||||||
@ -1148,7 +1149,11 @@ class SimpleKeyboard {
|
|||||||
document.addEventListener("keydown", this.handleKeyDown, physicalKeyboardHighlightPreventDefault);
|
document.addEventListener("keydown", this.handleKeyDown, physicalKeyboardHighlightPreventDefault);
|
||||||
document.addEventListener("mouseup", this.handleMouseUp);
|
document.addEventListener("mouseup", this.handleMouseUp);
|
||||||
document.addEventListener("touchend", this.handleTouchEnd);
|
document.addEventListener("touchend", this.handleTouchEnd);
|
||||||
document.addEventListener("selectionchange", this.handleSelectionChange);
|
|
||||||
|
if (this.options.updateCaretOnSelectionChange) {
|
||||||
|
document.addEventListener("selectionchange", this.handleSelectionChange);
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener("select", this.handleSelect);
|
document.addEventListener("select", this.handleSelect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1326,7 +1331,13 @@ 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);
|
|
||||||
|
// selectionchange is causing caret update issues on Chrome
|
||||||
|
// https://github.com/hodgef/simple-keyboard/issues/2346
|
||||||
|
if (this.options.updateCaretOnSelectionChange) {
|
||||||
|
document.removeEventListener("selectionchange", this.handleSelectionChange);
|
||||||
|
}
|
||||||
|
|
||||||
document.onpointerup = null;
|
document.onpointerup = null;
|
||||||
document.ontouchend = null;
|
document.ontouchend = null;
|
||||||
document.ontouchcancel = null;
|
document.ontouchcancel = null;
|
||||||
|
@ -265,6 +265,11 @@ export interface KeyboardOptions {
|
|||||||
*/
|
*/
|
||||||
enableLayoutCandidatesKeyPress?: boolean;
|
enableLayoutCandidatesKeyPress?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates caret when selectionchange event is fired
|
||||||
|
*/
|
||||||
|
updateCaretOnSelectionChange?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).
|
* Executes the callback function every time simple-keyboard is rendered (e.g: when you change layouts).
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user