From 1f9efb0c66dd2f91c750ff6b50c23c68594eb93b Mon Sep 17 00:00:00 2001 From: Francisco Hodge Date: Thu, 17 Jan 2019 18:36:09 -0500 Subject: [PATCH] Ensure caretPosition is unset on disableCaretPositioning --- src/lib/components/Keyboard.js | 37 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/lib/components/Keyboard.js b/src/lib/components/Keyboard.js index 888dd0cb..caf3d670 100644 --- a/src/lib/components/Keyboard.js +++ b/src/lib/components/Keyboard.js @@ -542,24 +542,29 @@ class SimpleKeyboard { this.dispatch(instance => { if(instance.isMouseHold){ - instance.isMouseHold = false; - } + instance.isMouseHold = false; + } - if( - (targetTagName === "textarea" || - targetTagName === "input") && - !instance.options.disableCaretPositioning - ){ - /** - * Tracks current cursor position - * As keys are pressed, text will be added/removed at that position within the input. - */ - instance.caretPosition = event.target.selectionStart; + if( + (targetTagName === "textarea" || + targetTagName === "input") && + !instance.options.disableCaretPositioning + ){ + /** + * Tracks current cursor position + * As keys are pressed, text will be added/removed at that position within the input. + */ + instance.caretPosition = event.target.selectionStart; - if(instance.options.debug){ - console.log("Caret at: ", event.target.selectionStart, event.target.tagName.toLowerCase(), `(${instance.keyboardDOMClass})`); - } - } + if(instance.options.debug){ + console.log("Caret at: ", event.target.selectionStart, event.target.tagName.toLowerCase(), `(${instance.keyboardDOMClass})`); + } + } else if(instance.options.disableCaretPositioning){ + /** + * If we toggled off disableCaretPositioning, we must ensure caretPosition doesn't persist once reactivated. + */ + instance.caretPosition = null; + } }); }