UI module

offset_by

procedureextensionexperimentalsince 0.31.0Source

Offset one unit to the left (direction -1) or right (1) of from.

Example↗
edit: Text_Edit;
defer free_text_edit(*edit);
set_contents(*edit, "ab cd");
assert(offset_by(*edit, 0, .CHARACTER, 1) == 1);
assert(offset_by(*edit, 5, .WORD, -1) == 3);
offset_by :: (edit: *Text_Edit, from: int, unit: Unit, direction: int) -> int

Offset one unit to the left (direction -1) or right (1) of from.

Parameters

edit: *Text_Edit
the text being edited.
from: int
the byte offset to start from.
unit: Unit
how far to go.
direction: int
-1 for left, 1 for right.

Returns

int
Example↗
edit: Text_Edit;
defer free_text_edit(*edit);
set_contents(*edit, "ab cd");
assert(offset_by(*edit, 0, .CHARACTER, 1) == 1);
assert(offset_by(*edit, 5, .WORD, -1) == 3);

See also