Some keyboard shortcuts like Ctrl+Right Arrow
, and Ctrl+Left Arrow
(along with the Ctrl+Shift
combinations) don’t match the visual order of text in RTL languages.
For example, the right arrow combinations navigate to the word on the left instead of the right.
character-by-character navigation using the left and right arrows works as expected.
This happens for RTL fields regardless of the interface language.
Curiously, when RTL text is typed in a LTR field, the Ctrl+Arrow
combinations works, but not other combinations.
So it seems each operation is handled differently somehow.
It may be understandable that RTL text in a LTR field does not work properly and vice versa due to complex directionality issues,
but for purely RTL text in RTL fields, this should work.
This is a video to demonstrate the problem:
https://drive.google.com/file/d/1t5GwNhfIk20MwwSW7WBU5zfjkYo2Cp43/view
I figured out a solution, though I’m not sure if this is the right way to go about it.
This makes caret navigation works as expected on RTL fields with RTL text.
--- a/qt/ts/src/editor.ts
+++ b/qt/ts/src/editor.ts
@@ -47,6 +47,10 @@ function triggerKeyTimer() {
}, 600);
}
+interface Selection {
+ modify(s: string, t: string, u: string): void;
+}
+
function onKey(evt: KeyboardEvent) {
// esc clears focus, allowing dialog to close
if (evt.which === 27) {
@@ -59,6 +63,27 @@ function onKey(evt: KeyboardEvent) {
focusPrevious();
return;
}
+
+ 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();
}
Note that the Selection
interface should be augmented to allow using the nonstandard function modify
as described here.