Skip to content

Commit

Permalink
fix spacebar swipe not moving selection on android
Browse files Browse the repository at this point in the history
  • Loading branch information
nightwing committed Mar 12, 2023
1 parent 4f7bf17 commit 5d65944
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/keyboard/textinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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;};
Expand Down

0 comments on commit 5d65944

Please sign in to comment.