19 constexpr text_selection() noexcept : _cursor(), _start_first(), _start_last(), _finish_first(), _finish_last()
21 hi_axiom(holds_invariant());
41 auto first =
std::min(_start_first, _finish_first);
42 auto last =
std::max(_start_last, _finish_last);
44 first = first.before_neighbor(size);
45 last = last.after_neighbor(size);
54 auto first =
std::min(_start_first, _finish_first);
55 auto last =
std::max(_start_last, _finish_last);
57 auto first_index = first.after() ? first.index() + 1 : first.index();
58 auto last_index = last.after() ? last.index() + 1 : last.index();
59 return {first_index, last_index};
62 [[nodiscard]]
constexpr bool empty() const noexcept
64 hilet[first_index, last_index] = selection_indices();
65 return first_index >= last_index;
68 constexpr operator bool() const noexcept
73 constexpr text_selection &clear_selection(
size_t size)
noexcept
75 hilet new_cursor =
std::min(_cursor, text_cursor{size - 1,
true, size});
76 return set_cursor(new_cursor);
79 constexpr text_selection &set_cursor(text_cursor new_cursor)
noexcept
81 _cursor = _start_first = _start_last = _finish_first = _finish_last = new_cursor;
82 hi_axiom(holds_invariant());
86 constexpr text_selection &operator=(text_cursor
const &rhs)
noexcept
88 return set_cursor(rhs);
91 constexpr void start_selection(text_cursor new_cursor, text_cursor first, text_cursor last)
noexcept
93 _start_first = _finish_first = first;
94 _start_last = _finish_last = last;
95 _cursor = new_cursor == first ? first : last;
96 hi_axiom(holds_invariant());
101 return start_selection(new_cursor, selection.first, selection.second);
104 constexpr void drag_selection(text_cursor drag_cursor)
noexcept
106 _finish_first = _finish_last = drag_cursor;
107 _cursor = drag_cursor;
110 constexpr void drag_selection(text_cursor drag_cursor, text_cursor first, text_cursor last)
noexcept
112 _finish_first = first;
114 _cursor = first < _start_first ? first : last > _start_last ? last : drag_cursor == first ? first : last;
115 hi_axiom(holds_invariant());
120 return drag_selection(drag_cursor, selection.first, selection.second);
123 [[nodiscard]]
constexpr friend bool operator==(text_selection
const &, text_selection
const &)
noexcept =
default;
126 [[nodiscard]]
constexpr bool holds_invariant() const noexcept
128 return _start_first <= _start_last and _finish_first <= _finish_last and
129 (_cursor == _start_first or _cursor == _start_last or _cursor == _finish_first or _cursor == _finish_last);
141 text_cursor _start_first;
145 text_cursor _start_last;
149 text_cursor _finish_first;
153 text_cursor _finish_last;
constexpr std::pair< size_t, size_t > selection_indices() const noexcept
Get the text indices for the selection.
Definition text_selection.hpp:52
constexpr std::pair< text_cursor, text_cursor > selection(size_t size) const noexcept
Return the selection of characters.
Definition text_selection.hpp:39