28 _start_first.resize(size);
29 _start_last.resize(size);
30 _finish_first.resize(size);
31 _finish_last.resize(size);
47 auto first =
std::min(_start_first, _finish_first);
48 auto last =
std::max(_start_last, _finish_last);
50 first = first.before_neighbor(size);
51 last = last.after_neighbor(size);
60 auto first =
std::min(_start_first, _finish_first);
61 auto last =
std::max(_start_last, _finish_last);
63 auto first_index = first.after() ? first.index() + 1 : first.index();
64 auto last_index = last.after() ? last.index() + 1 : last.index();
65 return {first_index, last_index};
68 [[nodiscard]]
constexpr bool empty() const noexcept
70 hilet[first_index, last_index] = selection_indices();
71 return first_index >= last_index;
74 constexpr explicit operator bool() const noexcept
79 constexpr text_selection& clear_selection(
size_t size)
noexcept
81 return set_cursor(_cursor.resize(size));
84 constexpr text_selection& set_cursor(text_cursor new_cursor)
noexcept
86 _cursor = _start_first = _start_last = _finish_first = _finish_last = new_cursor;
87 hi_axiom(holds_invariant());
91 constexpr text_selection& operator=(text_cursor
const& rhs)
noexcept
93 return set_cursor(rhs);
96 constexpr void start_selection(text_cursor new_cursor, text_cursor first, text_cursor last)
noexcept
98 _start_first = _finish_first = first;
99 _start_last = _finish_last = last;
100 _cursor = new_cursor == first ? first : last;
101 hi_axiom(holds_invariant());
106 return start_selection(new_cursor, selection.first, selection.second);
109 constexpr void drag_selection(text_cursor drag_cursor)
noexcept
111 _finish_first = _finish_last = drag_cursor;
112 _cursor = drag_cursor;
115 constexpr void drag_selection(text_cursor drag_cursor, text_cursor first, text_cursor last)
noexcept
117 _finish_first = first;
119 _cursor = first < _start_first ? first : last > _start_last ? last : drag_cursor == first ? first : last;
120 hi_axiom(holds_invariant());
125 return drag_selection(drag_cursor, selection.first, selection.second);
128 [[nodiscard]]
constexpr friend bool operator==(text_selection
const&, text_selection
const&)
noexcept =
default;
131 [[nodiscard]]
constexpr bool holds_invariant() const noexcept
133 return _start_first <= _start_last and _finish_first <= _finish_last and
134 (_cursor == _start_first or _cursor == _start_last or _cursor == _finish_first or _cursor == _finish_last);
146 text_cursor _start_first;
150 text_cursor _start_last;
154 text_cursor _finish_first;
158 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:58
constexpr std::pair< text_cursor, text_cursor > selection(size_t size) const noexcept
Return the selection of characters.
Definition text_selection.hpp:45