ProseMirror / prosemirror

The ProseMirror WYSIWYM editor
http://prosemirror.net/
MIT License
7.61k stars 336 forks source link

RTL keyboard navigation cannot escape from mark #1350

Closed ko-synth closed 1 year ago

ko-synth commented 1 year ago

Keyboard navigation gets locked around any mark when the direction is rtl.

Steps to reproduce:

https://user-images.githubusercontent.com/121867569/214037664-41699aea-da07-423f-8bab-9e1feb498e08.mov

It looks like the prosemirror-view does not recognize the direction and keeps handling navigation to and from marks as ltr.


The following patch appears to fix the rtl direction but doesn't change ltr.

diff --git a/src/capturekeys.ts b/src/capturekeys.ts
index 816022e..fc64c2b 100644
--- a/src/capturekeys.ts
+++ b/src/capturekeys.ts
@@ -258,9 +258,11 @@ export function captureKeyDown(view: EditorView, event: KeyboardEvent) {
   } else if (code == 13 || code == 27) { // Enter, Esc
     return true
   } else if (code == 37 || (browser.mac && code == 66 && mods == "c")) { // Left arrow, Ctrl-b on Mac
-    return selectHorizontally(view, -1, mods) || skipIgnoredNodesLeft(view)
+    const dir = getComputedStyle(view.dom).direction === "ltr" ? -1 : 1;
+    return selectHorizontally(view, dir, mods) || skipIgnoredNodesLeft(view)
   } else if (code == 39 || (browser.mac && code == 70 && mods == "c")) { // Right arrow, Ctrl-f on Mac
-    return selectHorizontally(view, 1, mods) || skipIgnoredNodesRight(view)
+    const dir = getComputedStyle(view.dom).direction === "ltr" ? 1 : -1;
+    return selectHorizontally(view, dir, mods) || skipIgnoredNodesRight(view)
   } else if (code == 38 || (browser.mac && code == 80 && mods == "c")) { // Up arrow, Ctrl-p on Mac
     return selectVertically(view, -1, mods) || skipIgnoredNodesLeft(view)
   } else if (code == 40 || (browser.mac && code == 78 && mods == "c")) { // Down arrow, Ctrl-n on Mac