Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: android bug when deleting multiple lines #5248

Merged
merged 4 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/keyboard/textinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ 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 @@ -101,8 +99,6 @@ 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 @@ -291,25 +287,6 @@ var TextInput = function(parentNode, host) {
}
};

function detectSelectionChange(e) {
if (!text || !text.parentNode)
document.removeEventListener("selectionchange", detectSelectionChange);
if (inComposition) return;

if (text.selectionStart !== text.selectionEnd) return;
var startDiff = text.selectionStart - lastSelectionStart;
var oldLenght = lastSelectionEnd - lastSelectionStart;
if (startDiff > 0) {
startDiff = Math.max(startDiff - oldLenght, 1);
} else if (startDiff === 0 && oldLenght) {
startDiff = -1;
}
var repeat = Math.abs(startDiff);
var key = startDiff > 0 ? KEYS.right : KEYS.left;
for (var i = 0; i < repeat; i++) {
host.onCommandKey({}, 0, key);
}
}

var inputHandler = null;
this.setInputHandler = function(cb) {inputHandler = cb;};
Expand Down
40 changes: 0 additions & 40 deletions src/keyboard/textinput_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,46 +153,6 @@ module.exports = {
assert.equal(editor.getValue(), "y");
},

"test: android spacebar moves cursor": function() {
setUserAgentForTests(true, false);
var value = "Juhu kinners!";
editor.setValue(value);
editor.blur();
editor.focus();
var lastCommand = "";
editor.commands.on("exec", function(e) {
lastCommand += e.command.name;
});

textarea.selectionStart = textarea.selectionEnd;
document.dispatchEvent(new CustomEvent("selectionchange"));
assert.equal(lastCommand, "gotoright");
lastCommand = "";

textarea.selectionStart =
textarea.selectionEnd = textarea.selectionStart - 1;
document.dispatchEvent(new CustomEvent("selectionchange"));
assert.equal(lastCommand, "gotoleft");
lastCommand = "";

assert.equal(editor.getSelectedText(), "");
textarea.selectionStart = 0;
textarea.selectionEnd = textarea.value.length;
textarea.dispatchEvent(new CustomEvent("select"));
assert.equal(editor.getSelectedText(), value);

textarea.selectionEnd = textarea.selectionStart;
document.dispatchEvent(new CustomEvent("selectionchange"));
assert.equal(lastCommand, "gotoleft");
lastCommand = "";

textarea.selectionStart =
textarea.selectionEnd = textarea.selectionEnd + 2;
document.dispatchEvent(new CustomEvent("selectionchange"));
assert.equal(lastCommand, "gotorightgotoright");
lastCommand = "";
},

"test: composition with visible textarea": function() {
var data = [
// select ll
Expand Down