Skip to content

End key in an RTL paragraph moves the caret to the start of the line, like Home #3986

Description

@Nathaniel-260

What happened?

In a right-to-left paragraph (<w:bidi/>), the End key moves the caret to the
start of the visual line instead of its end — the same position Home gives.
In an LTR paragraph in the same document End is correct.

Expected: End moves the caret to the logical end of the visual line the caret is
on, in both directions. That is what Word does, and what SuperDoc already does in
LTR paragraphs.
Actual: in an RTL paragraph End and Home land on the same offset — the line start.

Everything else about caret motion is direction-aware, which is why this looks
like an isolated gap rather than a general RTL problem: Home, Ctrl+Home,
Ctrl+End, and the arrow keys all behave correctly in the same document
(ArrowRight moves back one logical position, ArrowLeft forward), and clicking
in the empty space past the end of an RTL line correctly places the caret at the
line's logical end. Only End is mirrored.

This is not cosmetic — it changes where text goes. A user who presses End to get
back to the end of a Hebrew sentence and types the closing full stop gets that
character as the first character of the paragraph, and in the first paragraph
that means the start of the document. That is how it was reported to us by a
user, who saw it in the saved .docx after editing.

Shift+End inherits the same behaviour and selects backwards, from the line
start to the caret, instead of from the caret to the line end.

Steps to reproduce

Minimal document — one paragraph, one run, Hebrew text, w:bidi on the paragraph:

<w:p>
  <w:pPr><w:bidi/></w:pPr>
  <w:r><w:t xml:space="preserve">משפט קצר בעברית</w:t></w:r>
</w:p>
  1. Open it in SuperDoc (v2 / presentation editor).
  2. Click inside the line. selection.current() reports the expected offset — for
    a click in the empty area past the end of the line it correctly reports 15,
    the logical end.
  3. Press End. selection.current() now reports offset 0.
  4. Type .

Exported word/document.xml:

<w:p w14:paraId="00000001">
  <w:pPr><w:bidi/></w:pPr>
  <w:r><w:t>.</w:t></w:r>
  <w:r><w:t xml:space="preserve">משפט קצר בעברית</w:t></w:r>
</w:p>

The period is a run of its own at the head of the paragraph. Word renders that
document the same way SuperDoc does, so the document really is wrong, not just
the view.

The same happens in a paragraph that wraps: with the caret in the middle of the
first visual line, End lands on the line's first offset instead of its last one,
and in the second visual line it lands on that line's first offset. In an LTR
paragraph of the same length in the same document, End lands on the end of the
visual line, as expected.

SuperDoc version

2.13.0 (@superdoc/docx-engine 0.12.0). Also reproduces on 2.12.0.

Browser

Chrome (Windows).

Additional context

Related but different, both already open: #3955 (caret painting on an empty RTL
line) and #3943 (caret painted one position back after a trailing space in RTL,
WebKit). Those are about where the caret is drawn; this one is about where the
key moves it.

For RTL-first users this is one of the more disruptive keyboard issues, because
End is the natural way to get back to the end of a sentence, and the damage lands
in the saved file rather than on screen. Thanks for the fast turnaround on the
other RTL reports — happy to test a fix against a Hebrew corpus if that helps.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: queuedEngineering work is queued; no delivery date is committed.

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions