Address selected input edge case. Fixes #1058

This commit is contained in:
Francisco Hodge
2021-06-08 22:04:10 -07:00
parent f0fbf760b2
commit 3d075a2f57
3 changed files with 63 additions and 0 deletions
+37
View File
@@ -45,6 +45,7 @@ class SimpleKeyboard {
candidateBox!: CandidateBox | null;
keyboardRowsDOM!: KeyboardElement;
defaultName = "default";
activeInputElement: HTMLInputElement | HTMLTextAreaElement | null = null;
/**
* Creates an instance of SimpleKeyboard
@@ -404,6 +405,27 @@ class SimpleKeyboard {
this.caretPositionEnd
);
/**
* EDGE CASE: Check for whole input selection changes that will yield same updatedInput
*/
if(this.utilities.isStandardButton(button) && this.activeInputElement){
const isEntireInputSelection = (
this.input[inputName] &&
this.input[inputName] === updatedInput &&
this.caretPosition === 0 &&
this.caretPositionEnd === updatedInput.length
);
if(isEntireInputSelection){
this.setInput("", this.options.inputName, true);
this.setCaretPosition(0);
this.activeInputElement.value = "";
this.activeInputElement.setSelectionRange(0, 0);
this.handleButtonClicked(button, e);
return;
}
}
/**
* Calling onKeyPress
*/
@@ -1090,6 +1112,11 @@ class SimpleKeyboard {
event.target.selectionEnd
);
/**
* Tracking current input in order to handle caret positioning edge cases
*/
this.activeInputElement = event.target;
if (instance.options.debug) {
console.log(
"Caret at: ",
@@ -1105,6 +1132,11 @@ class SimpleKeyboard {
*/
instance.setCaretPosition(null);
/**
* Resetting activeInputElement
*/
this.activeInputElement = null;
if (instance.options.debug) {
console.log(
`Caret position reset due to "${event?.type}" event`,
@@ -1190,6 +1222,11 @@ class SimpleKeyboard {
this.candidateBox = null;
}
/**
* Clearing activeInputElement
*/
this.activeInputElement = null;
/**
* Clearing keyboardDOM
*/