lights FAQ Forum github.com/luapower/terra.tr

Portable UI (WIP)
ui
terra.layer
terra.tr

terra.tr_cursor

Cursor navigation and hit testing and text selection


--[[

	Cursor navigation and hit testing and text selection.

	Cursor navigation follows the logical text order, not the visual order.
	Moving the cursor to a new position can select the text in between or not.

	Cursor navigation and hit-testing is only available on aligned text.
	Cursor state can be set anytime and it survives re-shapes. The `x` field
	must be re-computed after re-align.

	The segments array contain the shaped text segments in logical text order.

	Each glyph run (thus each segment) holds two parallel arrays, `cursors.xs`
	and `cursors.offsets`, containing cursor position information for every
	codepoint in the segment plus one, eg. the text "ab cd" results in segments
	"ab " and "cd" with cursor positions "|a|b| |" and "|c|d|", so 4 and 3
	cursor positions respectively, and with the last position on segment "ab "
	being the same as the first position on segment "cd".

	`cursors.offsets` maps a codepoint offset to the codepoint offset for which
	there is a cursor position that can be landed on, since not every codepoint
	can have a cursor position. So `cursors.offsets` can have duplicate values
	(which are always clumped together; the array is not necessarily monotonic).

	`cursors.xs` maps a codepoint offset to the x-coord of the cursor position
	in front of that codepoint (or after it for the last element).
	Adjacent offset-distinct cursor positions have different x-coords.

	The mapping between text offsets and visually-distinct cursor positions is
	not 1:1 like it is on most (all?) text editors, but 1:2, in two cases:
	1. In mixed RTL/LTR lines, at the offsets where the direction changes.
	2. At the offset right after the last character on a wrapped line.
	You can navigate between these visually-distinct-but-logically-the-same
	positions using CURSOR_MODE_POS, or you can skip them with CURSOR_MODE_CHAR
	which brings back the normal behavior of most editors.

]]

See the source code for more info.


Package:terra.tr
Pkg type:Terra
Version: e90920e
Last commit:
Author: Cosmin Apreutesei
License: Public Domain

Required by: terra.layer 


Top