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

◆ selection()

MAYAFLUX_API std::optional< std::pair< size_t, size_t > > MayaFlux::Portal::Text::selection ( const EditableText & s)
nodiscard

The selected byte range as (begin, end), begin first whichever end the cursor is, or nullopt when nothing is selected.

Offsets past the end of the text are clamped to it.

Definition at line 5 of file TextEdit.cpp.

6{
7 if (!s.anchor)
8 return std::nullopt;
9
10 const size_t a = std::min(*s.anchor, s.text.size());
11 const size_t c = std::min(s.cursor, s.text.size());
12 if (a == c)
13 return std::nullopt;
14
15 return std::pair { std::min(a, c), std::max(a, c) };
16}
std::optional< size_t > anchor
The fixed end of a selection; the cursor is the moving end.
Definition TextEdit.hpp:41

References MayaFlux::Portal::Text::EditableText::anchor, MayaFlux::Portal::Text::EditableText::cursor, and MayaFlux::Portal::Text::EditableText::text.

Referenced by erase_selection(), move(), and selected_text().

Here is the caller graph for this function: