Bidirectional Text Editing

Cursor position

The cursor position contains both character index and on which side the cursor is in logical text-ordering.

Although more complex then keeping just track of just a character index, it allows for more correct cursor movement in bidirectional text.

Glossary and Symbols

Symbols used in examples:

Rendering the insert cursors

There are two cursors when editing text, the primary cursor which is the actual cursor position, the secondary cursor is the neighboring cursor.

The LTR cursor is where left-to-right text will be inserted, it is displayed with a little flag at the top pointing to the right. The RTL cursor is the reverse.

The primary cursor is the actual cursor position; the secondary is the neighboring cursor position in logical text-ordering, the secondary cursor is drawn in a different color.

When the primary and secondary cursor share the same position in display order, then the secondary cursor suppressed as is the LTR/RTL-flag on the primary cursor. This means in most cases when writing in one direction it will seem like there is just a single cursor.

In the example below we have the text “theREDfox”. “RED” is written in a RTL language, which makes the display order of the text “theDERfox”. The example show the cursor to be before the letter ‘R’ in logical order.

logical order:
  t   h   e   R   E   D   f   o   x
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7
             ^

display order:
  t   h   e[  D   E   R]  f   o   x
 0 1 2 3 4 5 1 0 9 8 7 6 2 3 4 5 6 7
                       ^