ttx 0.1.0
Loading...
Searching...
No Matches
selection.h
Go to the documentation of this file.
1#pragma once
2
3#include "di/container/algorithm/minmax.h"
6
7namespace ttx::terminal {
9struct Selection {
12
14 constexpr auto normalize() const -> Selection {
15 auto [s, e] = di::minmax({ start, end });
16 return { s, e };
17 }
18
19 void apply_reflow_result(ReflowResult const& reflow_result) {
20 start = reflow_result.map_position(start);
21 end = reflow_result.map_position(end);
22 }
23
24 constexpr auto operator==(Selection const& other) const -> bool {
25 auto a = this->normalize();
26 auto b = other.normalize();
27 return a.start == b.start && a.end == other.end;
28 }
29
30 constexpr friend auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<Selection>) {
31 return di::make_fields<"Selection">(di::field<"start", &Selection::start>, di::field<"end", &Selection::end>);
32 }
33};
34}
Represents the result of reflowing a RowGroup.
Definition reflow_result.h:22
auto map_position(AbsolutePosition position) const -> AbsolutePosition
Map a provided position into the new coordinate space.
Definition reflow_result.cpp:54
Definition absolute_position.h:6
Represents a coordinate anywhere in a screen, including scroll back.
Definition absolute_position.h:11
Represents the visual selection of a terminal.
Definition selection.h:9
constexpr auto normalize() const -> Selection
Normalize the selection so that start <= end.
Definition selection.h:14
constexpr friend auto tag_invoke(di::Tag< di::reflect >, di::InPlaceType< Selection >)
Definition selection.h:30
AbsolutePosition start
The start of the selection.
Definition selection.h:10
void apply_reflow_result(ReflowResult const &reflow_result)
Definition selection.h:19
constexpr auto operator==(Selection const &other) const -> bool
Definition selection.h:24
AbsolutePosition end
The end of the selection (inclusive)
Definition selection.h:11