Offset one unit to the left (direction -1) or right (1) of from.
- edit: the text being edited.
- from: the byte offset to start from.
- unit: how far to go.
- direction: -1 for left, 1 for right.
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
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);