in lib/ace/keyboard/textinput.js [682:744]
var detectArrowKeys = function(e) {
if (document.activeElement !== text) return;
if (typing || inComposition || host.$mouseHandler.isMousePressed) return;
if (copied) {
return;
}
var selectionStart = text.selectionStart;
var selectionEnd = text.selectionEnd;
var key = null;
var modifier = 0;
// console.log(selectionStart, selectionEnd);
if (selectionStart == 0) {
key = KEYS.up;
} else if (selectionStart == 1) {
key = KEYS.home;
} else if (selectionEnd > lastSelectionEnd && lastValue[selectionEnd] == "\n") {
key = KEYS.end;
} else if (selectionStart < lastSelectionStart && lastValue[selectionStart - 1] == " ") {
key = KEYS.left;
modifier = MODS.option;
} else if (
selectionStart < lastSelectionStart
|| (
selectionStart == lastSelectionStart
&& lastSelectionEnd != lastSelectionStart
&& selectionStart == selectionEnd
)
) {
key = KEYS.left;
} else if (selectionEnd > lastSelectionEnd && lastValue.slice(0, selectionEnd).split("\n").length > 2) {
key = KEYS.down;
} else if (selectionEnd > lastSelectionEnd && lastValue[selectionEnd - 1] == " ") {
key = KEYS.right;
modifier = MODS.option;
} else if (
selectionEnd > lastSelectionEnd
|| (
selectionEnd == lastSelectionEnd
&& lastSelectionEnd != lastSelectionStart
&& selectionStart == selectionEnd
)
) {
key = KEYS.right;
}
if (selectionStart !== selectionEnd)
modifier |= MODS.shift;
if (key) {
var result = host.onCommandKey({}, modifier, key);
if (!result && host.commands) {
key = KEYS.keyCodeToString(key);
var command = host.commands.findKeyCommand(modifier, key);
if (command)
host.execCommand(command);
}
lastSelectionStart = selectionStart;
lastSelectionEnd = selectionEnd;
resetSelection("");
}
};