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
//! Text selection state for the transcript view.
use std::time::Instant;
// === Types ===
/// A selection endpoint in the transcript (line/column).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TranscriptSelectionPoint {
pub line_index: usize,
pub column: usize,
}
/// Current selection state in the transcript view.
#[derive(Debug, Clone, Copy, Default)]
pub struct TranscriptSelection {
pub anchor: Option<TranscriptSelectionPoint>,
pub head: Option<TranscriptSelectionPoint>,
pub dragging: bool,
}
/// Drag-past-edge auto-scroll state. While the user holds the left button
/// and the cursor is above or below the transcript rect, the main loop
/// advances `pending_scroll_delta` and extends the selection head on a
/// fixed cadence so a long passage can be selected in one drag (#1163).
#[derive(Debug, Clone, Copy)]
pub struct SelectionAutoscroll {
/// `-1` scrolls up, `+1` scrolls down. Never `0`.
pub direction: i32,
/// Last in-bounds mouse column, in absolute terminal coordinates.
pub column: u16,
/// When the next tick is allowed to fire.
pub next_tick: Instant,
}
impl TranscriptSelection {
/// Clear any active selection.
pub fn clear(&mut self) {
self.anchor = None;
self.head = None;
self.dragging = false;
}
/// Whether a full selection is active.
#[must_use]
pub fn is_active(&self) -> bool {
self.anchor.is_some() && self.head.is_some()
}
/// Return selection endpoints ordered from start to end.
#[must_use]
pub fn ordered_endpoints(
&self,
) -> Option<(TranscriptSelectionPoint, TranscriptSelectionPoint)> {
let anchor = self.anchor?;
let head = self.head?;
if (head.line_index, head.column) < (anchor.line_index, anchor.column) {
Some((head, anchor))
} else {
Some((anchor, head))
}
}
}