返回 DeepSeek-TUI-2026
selection.rs
根目录 / crates / tui / src / tui / selection.rs
1 //! Text selection state for the transcript view.
2
3 // === Types ===
4
5 /// A selection endpoint in the transcript (line/column).
6 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
7 pub struct TranscriptSelectionPoint {
8 pub line_index: usize,
9 pub column: usize,
10 }
11
12 /// Current selection state in the transcript view.
13 #[derive(Debug, Clone, Copy, Default)]
14 pub struct TranscriptSelection {
15 pub anchor: Option<TranscriptSelectionPoint>,
16 pub head: Option<TranscriptSelectionPoint>,
17 pub dragging: bool,
18 }
19
20 impl TranscriptSelection {
21 /// Clear any active selection.
22 pub fn clear(&mut self) {
23 self.anchor = None;
24 self.head = None;
25 self.dragging = false;
26 }
27
28 /// Whether a full selection is active.
29 #[must_use]
30 pub fn is_active(&self) -> bool {
31 self.anchor.is_some() && self.head.is_some()
32 }
33
34 /// Return selection endpoints ordered from start to end.
35 #[must_use]
36 pub fn ordered_endpoints(
37 &self,
38 ) -> Option<(TranscriptSelectionPoint, TranscriptSelectionPoint)> {
39 let anchor = self.anchor?;
40 let head = self.head?;
41 if (head.line_index, head.column) < (anchor.line_index, anchor.column) {
42 Some((head, anchor))
43 } else {
44 Some((anchor, head))
45 }
46 }
47 }
48
48 lines RUST