MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ erase()

MAYAFLUX_API void MayaFlux::Portal::Text::erase ( EditableText &  s,
int  n 
)

Erase n codepoints from the cursor.

Positive n erases forward: the codepoints at and after the cursor, which does not move. Negative n erases backward: the codepoints before the cursor, which moves back by the same count. Clamps at whichever text boundary is reached first.

Definition at line 31 of file TextEdit.cpp.

32{
33 if (n > 0) {
34 for (int i = 0; i < n && s.cursor < s.text.size(); ++i) {
35 const size_t next = next_codepoint_offset(s.text, s.cursor);
36 s.text.erase(s.cursor, next - s.cursor);
37 }
38 } else {
39 for (int i = 0; i > n && s.cursor > 0; --i) {
40 const size_t prev = previous_codepoint_offset(s.text, s.cursor);
41 s.text.erase(prev, s.cursor - prev);
42 s.cursor = prev;
43 }
44 }
45}
size_t next_codepoint_offset(std::string_view text, size_t byte_offset)
Byte offset of the codepoint boundary after byte_offset.

References MayaFlux::Portal::Text::EditableText::cursor, next_codepoint_offset(), previous_codepoint_offset(), and MayaFlux::Portal::Text::EditableText::text.

Referenced by MayaFlux::Portal::Forma::TextField::wire().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: