mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-02-01 02:53:07 +08:00
Cursor position support
This commit is contained in:
parent
d923c5d920
commit
2ad0ba8506
@ -167,6 +167,8 @@ class SimpleKeyboard {
|
|||||||
clear = () => {
|
clear = () => {
|
||||||
this.keyboardDOM.innerHTML = '';
|
this.keyboardDOM.innerHTML = '';
|
||||||
this.keyboardDOM.className = this.keyboardDOMClass;
|
this.keyboardDOM.className = this.keyboardDOMClass;
|
||||||
|
this.buttonElements = {};
|
||||||
|
this.caretPosition = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch = (callback) => {
|
dispatch = (callback) => {
|
||||||
@ -196,6 +198,31 @@ class SimpleKeyboard {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleCaret = () => {
|
||||||
|
if(this.options.debug){
|
||||||
|
console.log("Caret handling started");
|
||||||
|
}
|
||||||
|
|
||||||
|
let handler = (event) => {
|
||||||
|
let targetTagName = event.target.tagName.toLowerCase();
|
||||||
|
|
||||||
|
if(
|
||||||
|
targetTagName === "textarea" ||
|
||||||
|
targetTagName === "input"
|
||||||
|
){
|
||||||
|
this.caretPosition = event.target.selectionStart;
|
||||||
|
|
||||||
|
if(this.options.debug){
|
||||||
|
console.log('Caret at: ', event.target.selectionStart, event.target.tagName.toLowerCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener("keyup", handler);
|
||||||
|
document.addEventListener("mouseup", handler);
|
||||||
|
document.addEventListener("touchend", handler);
|
||||||
|
}
|
||||||
|
|
||||||
render = () => {
|
render = () => {
|
||||||
/**
|
/**
|
||||||
* Clear keyboard
|
* Clear keyboard
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
class Utilities {
|
class Utilities {
|
||||||
static normalizeString(string){
|
constructor(simpleKeyboardInstance){
|
||||||
|
this.simpleKeyboardInstance = simpleKeyboardInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
normalizeString(string){
|
||||||
let output;
|
let output;
|
||||||
|
|
||||||
if(string === "@")
|
if(string === "@")
|
||||||
@ -166,7 +170,15 @@ class Utilities {
|
|||||||
else if(button === "{numpaddecimal}")
|
else if(button === "{numpaddecimal}")
|
||||||
output = output + '.';
|
output = output + '.';
|
||||||
else if(!button.includes("{") && !button.includes("}"))
|
else if(!button.includes("{") && !button.includes("}"))
|
||||||
output = output + button;
|
|
||||||
|
updateCaretPos = (length, minus) => {
|
||||||
|
if(minus){
|
||||||
|
this.simpleKeyboardInstance.caretPosition = this.simpleKeyboardInstance.caretPosition - length
|
||||||
|
} else {
|
||||||
|
this.simpleKeyboardInstance.caretPosition = this.simpleKeyboardInstance.caretPosition + length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user