1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! Selection: hit-testing, the selection range, and text extraction.
//!
//! Selection is a *document* position pair, not a pixel pair. A
//! [`Caret`] names `(message, source-within-message, byte offset)`, so
//! the selection survives everything that moves pixels around — a
//! resize re-wraps, a zoom rescales, an image finishes decoding and
//! grows its row, a history batch prepends above. xtext stored
//! `mark_start` / `mark_end` as byte offsets on each `textentry` plus
//! `select_start_x/y` in widget coordinates, which is why its selection
//! behaves oddly across a resize mid-drag.
//!
//! The engine deliberately owns none of the *interaction* — no notion of
//! button state, drag, or double-click. It answers three questions and
//! the widget does the rest:
//!
//! - where in the document is this pixel? ([`ChatBuffer::hit_test`])
//! - what does the region between two carets look like? ([`Selection`])
//! - what text does that region contain? ([`ChatBuffer::selected_text`])
use crateMessageId;
use crateLineSource;
/// A document position.
/// An ordered selection range.
///
/// `anchor` is where the drag started and `focus` where it is now;
/// either may be the earlier one in document order, which is what makes
/// dragging upwards work.
/// Visual order of a row's texts.
///
/// A row is not one string: it is a gutter followed by body blocks, and
/// a selection boundary can land in any of them. Ranking them is what
/// lets carets in *different* sources be ordered against each other —
/// comparing their byte offsets, which is what the first version did,
/// is meaningless, because the two offsets index unrelated strings.
/// How far a selection extends within one row.