mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2026-04-30 00:00:04 +08:00
Address selected input edge case. Fixes #1058
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user