tix-tracker 0.12.0

A terminal issue tracker: markdown + YAML frontmatter issues with a kanban TUI and CLI
Documentation
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#[allow(clippy::wildcard_imports)]
use super::*;

impl App {
    /// Route a [`MouseEvent`] into the active mode's pointer handler (D2),
    /// mirroring [`App::handle_key`]: one dispatch trunk per mode, so mouse and
    /// keyboard share the same single-mode mental model. Modes that declare no
    /// mouse behavior fall through to a no-op. Per-mode handlers land with the
    /// click/hover/dialog tasks.
    pub fn handle_mouse(&mut self, mouse: MouseEvent) -> Result<Action> {
        // The pointer's hovered region is tracked for **every** mode, before the
        // per-mode dispatch, so widgets shared across modes (the vertical mode
        // navigation) highlight wherever they are drawn. Regions come from the
        // previous frame, which is the frame the pointer is actually over.
        if matches!(mouse.kind, MouseEventKind::Moved) {
            self.hover_action = self.resolve_region(mouse.column, mouse.row);
        }
        let mut action = match self.mode.clone() {
            Mode::Board => self.handle_board_mouse(mouse),
            Mode::Detail => self.handle_detail_mouse(mouse),
            Mode::ConfirmDelete => self.handle_confirm_delete_mouse(mouse),
            Mode::Help { .. } => self.handle_help_mouse(mouse),
            Mode::ActionMenu { .. } => self.handle_action_menu_mouse(mouse),
            Mode::FilterModal => self.handle_filter_modal_mouse(mouse),
            Mode::Settings => self.handle_settings_mouse(mouse),
            Mode::Views => self.handle_views_mouse(mouse),
            Mode::DatePicker { .. } => self.handle_date_picker_mouse(mouse),
            Mode::Schedule => self.handle_schedule_mouse(mouse),
            _ => Ok(Action::None),
        }?;
        if action == Action::None
            && matches!(mouse.kind, MouseEventKind::Down(_))
            && !matches!(
                self.mode,
                Mode::ActionMenu { .. }
                    // A confirmation has no actions underneath it: a click must
                    // answer it or be ignored, never run a board hit region.
                    | Mode::ConfirmArchive { .. }
                    // #1510: the conflict prompt's three decisions are the only way
                    // out. A click that fell through to the board drawn underneath
                    // would leave the prompt — and the temp copy it holds — without
                    // a decision ever being made.
                    | Mode::EditConflict { .. }
                    // #1506: the repair prompt's decisions are the only way out for
                    // the same reason, and its retained copy must not be abandoned
                    // by a stray click on the board.
                    | Mode::EditRepair { .. }
                    // tix #1632: the tips modal's decisions are pressed, not
                    // clicked, and a stray click must not run the board action it
                    // happens to land on while the dialog is up.
                    | Mode::Tips { .. }
            )
        {
            // Fall back to widget-recorded hit regions (D3/D6): a click on a
            // region a widget declared during draw runs its associated action,
            // regardless of which mode did not handle the event. The context
            // menu owns every click while it is open (inside = item, outside =
            // dismiss), so underlying board regions must not resolve through
            // the fallback.
            if let Some(region_action) = self.resolve_region(mouse.column, mouse.row) {
                action = region_action;
            }
        }
        Ok(action)
    }

    /// Record a click target bounding `rect` for the current draw (D3).
    /// Widgets call this while rendering; `handle_mouse` resolves the region
    /// under a pointer via [`App::resolve_region`]. Regions are cleared at the
    /// start of every frame, so stale targets from previous frames never fire.
    pub fn record_region(&self, rect: Rect, action: Action) {
        self.frame_hit_regions
            .borrow_mut()
            .push(HitRegion { rect, action });
    }

    /// Whether `action`'s hit region is the one the pointer is currently over.
    /// Widgets use this to style themselves on hover without owning any pointer
    /// state; the value is refreshed by each `Moved` event (see `handle_mouse`).
    pub fn is_hovered(&self, action: &Action) -> bool {
        self.hover_action.as_ref() == Some(action)
    }

    /// The innermost (last-recorded) region under `(x, y)`, if any (D3).
    pub(in crate::app) fn resolve_region(&self, x: u16, y: u16) -> Option<Action> {
        self.frame_hit_regions
            .borrow()
            .iter()
            .rev()
            .find(|region| region.rect.contains(Position::new(x, y)))
            .map(|region| region.action.clone())
    }

    /// Board-mode pointer handling (D4): `Down` selects a card/column and
    /// records the press origin, `Drag` frames promote an active drag without
    /// touching the board, and a resolving `Up` decides between a plain click,
    /// a double-click (opens the card's detail) and a drag-move to another
    /// real column. Right-click opens the context menu (task 4.2); scroll
    /// wheel behavior lands with task 6.1.
    pub(in crate::app) fn handle_board_mouse(&mut self, mouse: MouseEvent) -> Result<Action> {
        match mouse.kind {
            MouseEventKind::Down(MouseButton::Left) => {
                self.drag_preview_col = None;
                let hit = self.board_hit_at(mouse.column, mouse.row);
                self.mouse_down_left(hit)
            }
            MouseEventKind::Down(MouseButton::Right) => {
                self.drag_preview_col = None;
                let hit = self.board_hit_at(mouse.column, mouse.row);
                self.open_action_menu(hit, true)
            }
            MouseEventKind::Up(MouseButton::Left) => {
                self.drag_preview_col = None;
                self.mouse_up_left(mouse.column, mouse.row)
            }
            MouseEventKind::Drag(_) => {
                self.mouse_drag();
                self.update_drag_preview(mouse.column, mouse.row);
                Ok(Action::None)
            }
            MouseEventKind::ScrollUp => {
                self.board.move_up();
                Ok(Action::None)
            }
            MouseEventKind::ScrollDown => {
                self.board.move_down();
                Ok(Action::None)
            }
            MouseEventKind::Moved => {
                self.drag_preview_col = None;
                if let Some(tab) = self.tab_hover_at(mouse.column, mouse.row) {
                    self.tabs.hovered = Some(tab);
                    self.board.hover = None;
                    self.board.hover_col = None;
                } else {
                    self.tabs.hovered = None;
                    self.mouse_hover(mouse.column, mouse.row);
                }
                Ok(Action::None)
            }
            _ => Ok(Action::None),
        }
    }

    /// Track which tab, if any, the pointer is hovering. This mirrors the tab
    /// bar geometry so the hover highlight stays aligned with the rendered row.
    pub(in crate::app) fn tab_hover_at(&self, x: u16, y: u16) -> Option<usize> {
        if !self.tabs.needs_bar() {
            return None;
        }
        let area = self.frame_size.get();
        if y < area.y || y >= area.y + TAB_HEIGHT {
            return None;
        }
        let tabs_area = Rect {
            y: area.y,
            height: TAB_HEIGHT,
            ..area
        };
        (0..self.tabs.len()).find(|&index| {
            self.tabs
                .tab_rect(index, tabs_area)
                .is_some_and(|rect| rect.contains(Position::new(x, y)))
        })
    }

    /// Track the pointer for the hover highlight (D8): `Moved` records the
    /// card under the pointer on `board.hover` and the column on
    /// `board.hover_col` (never touching the selection). The column is recorded
    /// for empty columns too, so hovering anywhere inside one marks it; both are
    /// cleared over the board chrome or outside the board.
    pub(in crate::app) fn mouse_hover(&mut self, x: u16, y: u16) {
        match self.board_hit_at(x, y) {
            Some(HitTarget::Card { col, row }) => {
                self.board.hover = Some((col, row));
                self.board.hover_col = Some(col);
            }
            Some(HitTarget::Column { col }) => {
                self.board.hover = None;
                self.board.hover_col = Some(col);
            }
            None => {
                self.board.hover = None;
                self.board.hover_col = None;
            }
        }
    }

    /// Update the current drag preview target while a card is held down.
    pub(in crate::app) fn update_drag_preview(&mut self, x: u16, y: u16) {
        match self.board_hit_at(x, y) {
            Some(HitTarget::Card { col, row }) => {
                self.drag_preview_col = Some(col);
                self.board.hover = Some((col, row));
                self.board.hover_col = Some(col);
            }
            Some(HitTarget::Column { col }) if col < self.board.real_cols() => {
                self.drag_preview_col = Some(col);
                self.board.hover = None;
                self.board.hover_col = Some(col);
            }
            _ => {
                self.drag_preview_col = None;
                self.board.hover = None;
                self.board.hover_col = None;
            }
        }
    }

    /// Board-detail mouse handling: only the wheel changes scroll offset.
    pub(in crate::app) fn handle_detail_mouse(&mut self, mouse: MouseEvent) -> Result<Action> {
        match mouse.kind {
            MouseEventKind::ScrollUp => {
                if let Some(d) = self.detail.as_mut() {
                    d.scroll_by(-i32::from(WHEEL_ROWS));
                }
            }
            MouseEventKind::ScrollDown => {
                if let Some(d) = self.detail.as_mut() {
                    d.scroll_by(i32::from(WHEEL_ROWS));
                }
            }
            _ => {}
        }
        Ok(Action::None)
    }

    /// The rect the board widget draws into within the frame `area`, mirroring
    /// `render_board`: tabs bar and hover line on top, filter row (when
    /// active), board, then the hint bar at the bottom. `None` when the frame
    /// is too small to contain a board at all.
    pub(in crate::app) fn board_mouse_area(&self, area: Rect) -> Option<Rect> {
        let tab_h: u16 = if self.tabs.needs_bar() { TAB_HEIGHT } else { 0 };
        // The same band the renderers lay out (WP05, T024): a hit test that
        // ignored the saved-view indicator row would be off by one and select the
        // wrong card.
        let band_h = filter_band_height(self);
        let hint_h: u16 = if self.one_shot { 0 } else { HINT_HEIGHT };
        let mention_h = mention_row_height(self);
        if area.height <= hint_h + mention_h + tab_h + HOVER_HEIGHT + band_h {
            return None;
        }
        Some(Rect {
            y: area.y + tab_h + HOVER_HEIGHT + band_h,
            height: area.height - tab_h - HOVER_HEIGHT - band_h - hint_h - mention_h,
            ..area
        })
    }

    /// Resolve a terminal pointer against the board using the geometry of the
    /// most recent draw (D3), or `None` outside the board / when unframed.
    pub(in crate::app) fn board_hit_at(&self, x: u16, y: u16) -> Option<HitTarget> {
        let frame = self.frame_size.get();
        let board_area = self.board_mouse_area(frame)?;
        self.board.hit_test(
            board_area,
            board::BoardDisplay::from(self.active_board_config()),
            self.status_msg.is_some(),
            x,
            y,
        )
    }

    /// Move the cursor to the card or column the pointer resolved to (D4:
    /// selection changes only on `Down`).
    pub(in crate::app) fn select_at(&mut self, hit: HitTarget) {
        match hit {
            HitTarget::Card { col, row } => {
                self.board.active_col = col;
                self.board.selected = row;
            }
            HitTarget::Column { col } => {
                self.board.active_col = col;
                self.board.clamp_selection();
            }
        }
    }

    pub(in crate::app) fn mouse_down_left(&mut self, hit: Option<HitTarget>) -> Result<Action> {
        let Some(target) = hit else {
            return Ok(Action::None);
        };
        self.select_at(target);
        let (col, card) = match target {
            HitTarget::Card { col, row } => (col, Some(row)),
            HitTarget::Column { col } => (col, None),
        };

        // Record the press origin. The release decides whether this was a plain
        // click (open the action menu) or a drag (move/reorder); a second press
        // on the same card inside the window is handled by the menu's own mouse
        // handler as the double-click that opens the detail pane.
        self.mouse.last_down = Some(MouseDown {
            col,
            card,
            at: Instant::now(),
        });
        Ok(Action::None)
    }

    /// Open the detail view for the card at the hit target (mirrors the board
    /// `Enter` branch) — the resolving half of a double-click.
    pub(in crate::app) fn open_detail_for(&mut self, hit: HitTarget) -> Result<Action> {
        if let HitTarget::Card { col, row } = hit {
            if let Some(card) = self.board.column_cards(col).get(row).cloned() {
                let issue = self.store.get(IssueSelector::Filename(card.filename))?;
                self.open_detail_root(issue)?;
            }
        }
        Ok(Action::None)
    }

    /// A press followed by `Drag` frames promotes the recorded press into an
    /// active drag (D4). The board is not mutated during drag frames; the
    /// eventual `Up` decides the outcome. Dragging requires a card origin —
    /// grabbing empty column space never moves anything.
    pub(in crate::app) fn mouse_drag(&mut self) {
        if self.mouse.drag.is_none() {
            if let Some(down) = &self.mouse.last_down {
                if down.card.is_some() {
                    self.mouse.drag = Some(Drag {
                        col: down.col,
                        card: down.card,
                    });
                }
            }
        }
    }

    /// Resolve a left-button release (D4): an active drag becomes a drop —
    /// moved to a different real column via `move_selected_to`, no-op on the
    /// source column, the mismatched column, or outside the board — while a
    /// plain click keeps the press recorded so a fast second press on the same
    /// card registers as a double-click.
    pub(in crate::app) fn mouse_up_left(&mut self, x: u16, y: u16) -> Result<Action> {
        self.board.hover = None;
        self.board.hover_col = None;
        if let Some(drag) = self.mouse.drag.take() {
            self.mouse.last_down = None;
            if drag.card.is_none() {
                return Ok(Action::None);
            }
            let target = match self.board_hit_at(x, y) {
                Some(target) => target,
                None => return Ok(Action::None),
            };
            match target {
                HitTarget::Card { col, row } if col == drag.col => {
                    if Some(row) == drag.card {
                        return Ok(Action::None);
                    }
                    return self.reorder_selected_within_column(col, drag.card.unwrap(), row);
                }
                HitTarget::Column { col } if col == drag.col => {
                    return self.reorder_selected_within_column(
                        col,
                        drag.card.unwrap(),
                        self.board.column_cards(col).len().saturating_sub(1),
                    );
                }
                HitTarget::Card { col, .. } | HitTarget::Column { col }
                    if col < self.board.real_cols() && col != drag.col =>
                {
                    return self.move_selected_to(col);
                }
                _ => return Ok(Action::None),
            }
        }

        // A plain left click (no drag) opens the action menu for the card it
        // started and ended on. Drags already returned above, so a move is never
        // mistaken for a click.
        if let Some(down) = self.mouse.last_down.as_ref()
            && let Some(HitTarget::Card { col, row }) = self.board_hit_at(x, y)
            && down.col == col
            && down.card == Some(row)
        {
            return self.open_action_menu(Some(HitTarget::Card { col, row }), false);
        }
        Ok(Action::None)
    }

    #[allow(clippy::unused_self, clippy::unnecessary_wraps)]
    pub(in crate::app) fn handle_confirm_delete_mouse(
        &mut self,
        _mouse: MouseEvent,
    ) -> Result<Action> {
        Ok(Action::None)
    }

    #[allow(clippy::unnecessary_wraps)]
    pub(in crate::app) fn handle_help_mouse(&mut self, mouse: MouseEvent) -> Result<Action> {
        // tix #1441: the wheel scrolls the overlay, like the board and the detail
        // pane already did. It used to resolve to a click-anywhere-closes region,
        // which is still true for clicks — a wheel event is not a click.
        match mouse.kind {
            MouseEventKind::ScrollUp => self.scroll_help(-i32::from(WHEEL_ROWS)),
            MouseEventKind::ScrollDown => self.scroll_help(i32::from(WHEEL_ROWS)),
            _ => {}
        }
        Ok(Action::None)
    }

    #[allow(clippy::unused_self, clippy::unnecessary_wraps)]
    pub(in crate::app) fn handle_filter_modal_mouse(
        &mut self,
        _mouse: MouseEvent,
    ) -> Result<Action> {
        Ok(Action::None)
    }

    #[allow(clippy::unused_self, clippy::unnecessary_wraps)]
    pub(in crate::app) fn handle_settings_mouse(&mut self, _mouse: MouseEvent) -> Result<Action> {
        Ok(Action::None)
    }

    #[allow(clippy::unused_self, clippy::unnecessary_wraps)]
    pub(in crate::app) fn handle_date_picker_mouse(
        &mut self,
        _mouse: MouseEvent,
    ) -> Result<Action> {
        Ok(Action::None)
    }
}