29 _start_first.resize(size);
30 _start_last.resize(size);
31 _finish_first.resize(size);
32 _finish_last.resize(size);
48 auto first =
std::min(_start_first, _finish_first);
49 auto last =
std::max(_start_last, _finish_last);
51 first = first.before_neighbor(size);
52 last = last.after_neighbor(size);
61 auto first =
std::min(_start_first, _finish_first);
62 auto last =
std::max(_start_last, _finish_last);
64 auto first_index = first.after() ? first.index() + 1 : first.index();
65 auto last_index = last.after() ? last.index() + 1 : last.index();
66 return {first_index, last_index};
69 [[nodiscard]]
constexpr bool empty() const noexcept
71 hilet[first_index, last_index] = selection_indices();
72 return first_index >= last_index;
75 constexpr explicit operator bool() const noexcept
80 constexpr text_selection& clear_selection(
size_t size)
noexcept
82 return set_cursor(_cursor.resize(size));
85 constexpr text_selection& set_cursor(text_cursor new_cursor)
noexcept
87 _cursor = _start_first = _start_last = _finish_first = _finish_last = new_cursor;
88 hi_axiom(holds_invariant());
92 constexpr text_selection& operator=(text_cursor
const& rhs)
noexcept
94 return set_cursor(rhs);
97 constexpr void start_selection(text_cursor new_cursor, text_cursor first, text_cursor last)
noexcept
99 _start_first = _finish_first = first;
100 _start_last = _finish_last = last;
101 _cursor = new_cursor == first ? first : last;
102 hi_axiom(holds_invariant());
107 return start_selection(new_cursor, selection.first, selection.second);
110 constexpr void drag_selection(text_cursor drag_cursor)
noexcept
112 _finish_first = _finish_last = drag_cursor;
113 _cursor = drag_cursor;
116 constexpr void drag_selection(text_cursor drag_cursor, text_cursor first, text_cursor last)
noexcept
118 _finish_first = first;
120 _cursor = first < _start_first ? first : last > _start_last ? last : drag_cursor == first ? first : last;
121 hi_axiom(holds_invariant());
126 return drag_selection(drag_cursor, selection.first, selection.second);
129 [[nodiscard]]
constexpr friend bool operator==(text_selection
const&, text_selection
const&)
noexcept =
default;
132 [[nodiscard]]
constexpr bool holds_invariant() const noexcept
134 return _start_first <= _start_last and _finish_first <= _finish_last and
135 (_cursor == _start_first or _cursor == _start_last or _cursor == _finish_first or _cursor == _finish_last);
147 text_cursor _start_first;
151 text_cursor _start_last;
155 text_cursor _finish_first;
159 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:59
constexpr std::pair< text_cursor, text_cursor > selection(size_t size) const noexcept
Return the selection of characters.
Definition text_selection.hpp:46