Cursor position support

This commit is contained in:
Francisco Hodge
2018-10-06 02:22:02 -04:00
parent d923c5d920
commit 2ad0ba8506
2 changed files with 41 additions and 2 deletions
+27
View File
@@ -167,6 +167,8 @@ class SimpleKeyboard {
clear = () => {
this.keyboardDOM.innerHTML = '';
this.keyboardDOM.className = this.keyboardDOMClass;
this.buttonElements = {};
this.caretPosition = null;
}
dispatch = (callback) => {
@@ -196,6 +198,31 @@ class SimpleKeyboard {
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 = () => {
/**
* Clear keyboard