diff --git a/src/keyboard/textinput.js b/src/keyboard/textinput.js index 1ee56031e2c..e307fde09d0 100644 --- a/src/keyboard/textinput.js +++ b/src/keyboard/textinput.js @@ -69,6 +69,8 @@ var TextInput = function(parentNode, host) { if (ignoreFocusEvents) return; host.onBlur(e); isFocused = false; + if (isMobile && !isIOS) + document.removeEventListener("selectionchange", detectSelectionChange); }, host); event.addListener(text, "focus", function(e) { if (ignoreFocusEvents) return; @@ -85,6 +87,8 @@ var TextInput = function(parentNode, host) { setTimeout(resetSelection); else resetSelection(); + if (isMobile && !isIOS) + document.addEventListener("selectionchange", detectSelectionChange); }, host); this.$focusScroll = false; this.focus = function() { @@ -270,6 +274,20 @@ var TextInput = function(parentNode, host) { } }; + function detectSelectionChange(e) { + if (!text || !text.parentElement) + document.removeEventListener("selectionchange", detectSelectionChange); + + var startDiff = text.selectionStart - lastSelectionStart; + if (text.selectionEnd == text.selectionStart && startDiff && !inComposition) { + var repeat = Math.abs(startDiff); + var key = repeat == startDiff ? KEYS.right : KEYS.left; + for (var i = 0; i < Math.abs(startDiff); i++) { + host.onCommandKey({}, 0, key); + } + } + } + var inputHandler = null; this.setInputHandler = function(cb) {inputHandler = cb;}; this.getInputHandler = function() {return inputHandler;};