luapower / tr0

Unicode text rendering engine in Lua
http://luapower.com/tr0
0 stars 1 forks source link

Cursors not stable when editing #39

Closed capr closed 5 years ago

capr commented 5 years ago

The mapping between text offsets and visually-distinct cursors is not 1:1 like it is on most (all?) text editors, but 1:2. There are two cases when we have two visually-distinct cursors for the same text offset:

  1. In mixed RTL/LTR lines, at the offsets where the direction changes. One cursor has RTL direction, the other LTR, but they point at the same offset. I actually prefer it that way, but I want the cursors to remain stable while editing. This should be easy to fix by also providing a direction along with the offset when looking up a cursor by offset, since we know that they can't both have the same direction.

  2. The offset right after the last character on a wrapped line (usually a space but doesn't have to be) also has two cursors. One cursor is the last cursor on the line, and the other is the first cursor on the next line. I would also like to keep this cursor, but not when it's after a whitespace character, because that would put the cursor outside the text's bounding box and possibly render it invisible if the client clips the text by the textbox (eg. when the text is inside a scrollbox with zero margins).

The cursor objects store seg and i but when editing, we lose this information by using cursor_at_offset() so the cursor can jump to a different visual position. This is what the title of this issue refers to.

capr commented 5 years ago

fixed with added options: unique_offsets to make it behave like most editors (no duplicate cursors) and wrapped_space which is useful for when unique_offsets = false to remove the cursor at the end of a wrapped line that ends with a space char.