Merge pull request #730 from ANH25/rtl-editing

fix Ctrl+right/left handling in RTL fields
This commit is contained in:
Damien Elmes 2020-08-13 20:09:51 +10:00 committed by GitHub
commit 6a379add1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -47,6 +47,10 @@ function triggerKeyTimer() {
}, 600); }, 600);
} }
interface Selection {
modify(s: string, t: string, u: string): void;
}
function onKey(evt: KeyboardEvent) { function onKey(evt: KeyboardEvent) {
// esc clears focus, allowing dialog to close // esc clears focus, allowing dialog to close
if (evt.which === 27) { if (evt.which === 27) {
@ -59,6 +63,29 @@ function onKey(evt: KeyboardEvent) {
focusPrevious(); focusPrevious();
return; return;
} }
// fix Ctrl+right/left handling in RTL fields
if (currentField.dir === "rtl") {
const selection = window.getSelection();
let granularity = "character";
let alter = "move";
if (evt.ctrlKey) {
granularity = "word";
}
if (evt.shiftKey) {
alter = "extend";
}
if (evt.which === 39) {
selection.modify(alter, "right", granularity);
evt.preventDefault();
return;
} else if (evt.which === 37) {
selection.modify(alter, "left", granularity);
evt.preventDefault();
return;
}
}
triggerKeyTimer(); triggerKeyTimer();
} }