tix-tracker 0.11.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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
#[allow(clippy::wildcard_imports)]
use super::*;

impl App {
    pub fn handle_key(&mut self, key: KeyEvent) -> Result<Action> {
        if key.kind != KeyEventKind::Press {
            return Ok(Action::None);
        }
        let context = self.input_context();
        // The mode shell is consulted **before** the `F(12)` sentinel rewrite
        // (tui-mode-navigation, D2). A shell chord (F1–F4/F12, ctrl+n) switches
        // modes only when the active top-level context does not bind the key
        // itself — so `F2` inside a form is still `open_picker`, and a genuinely
        // unbound key still becomes the sentinel.
        if let Some(action) = self.shell_action(context, key) {
            let result = self.run_shell_action(action);
            self.sync_top_mode();
            return result;
        }
        // The rail owns the keyboard while it is focused, and is entered with
        // `h`/`Left` when the active mode has no leftward target of its own
        // (see `rail_entry_available`). Both checks sit after the shell chords,
        // so a mode switch still works from inside the rail, and before the
        // binding resolution, so the rail's `j`/`k`/`Enter` are read raw rather
        // than rewritten to the mode's own bindings. A text-entry context is
        // never intercepted: `h` there is a letter.
        if self.nav_focus.is_some() {
            return self.handle_nav_key(key);
        }
        // The startup tips modal (tix #1632) owns the keyboard raw, and **before**
        // the rail-entry check below: its keys include `Left`/`h`, which that check
        // would otherwise read as "focus the navigation rail". Its keys are raw for
        // the usual reason too — the board binds several of the same letters
        // (`n`, `p`, `d`), and the binding layer would canonicalize them first.
        if matches!(self.mode, Mode::Tips { .. }) {
            return self.handle_tips_key(key);
        }
        // The `F10` Portfolio page's **Roadmap** tab (WP05) owns two raw-key layers
        // ahead of the binding layer (and ahead of the rail-entry check below, so
        // `h` typed into an owner name is a letter rather than a jump to the rail).
        // An open overlay is a text surface, so its keys must not canonicalize
        // (`j` would become `Down`, `q` would become `Esc`); and the tab's command
        // letters (`c`/`e`/`a`/`x`/`f`/`r`) are not bound in
        // `InputContext::Portfolio` and would otherwise be rewritten to the inert
        // `F(12)` sentinel. Everything else on the page — `j`/`k`, `Tab`, `q`, `?` —
        // still resolves through the bindings so a rebind keeps working, and the
        // rail is never focused while an overlay is open.
        if matches!(self.mode, Mode::Portfolio) {
            if self.portfolio_roadmap_overlay.is_some() {
                return self.handle_roadmap_overlay_key(key);
            }
            if self.handle_roadmap_tab_key(key)? {
                return Ok(Action::None);
            }
        }
        if !Self::allows_text_fallback(context)
            && matches!(key.code, KeyCode::Left | KeyCode::Char('h'))
            && self.rail_entry_available()
        {
            self.focus_rail();
            return Ok(Action::None);
        }
        // The filter modal's open value picker owns the keyboard **ahead of** the
        // binding layer, exactly as the triage inbox's dropdown does: its keys must
        // reach `DropdownState` unrewritten, or `l`/`enter` would canonicalize to the
        // modal's open-picker action and the list could neither be filtered nor
        // chosen once it was open. `esc` closes it (raw), and typing filters it.
        if matches!(self.mode, Mode::FilterModal) && self.filter_picker.is_some() {
            return self.handle_filter_picker_key(key);
        }
        // The due-warning overlay's four answers are raw keys, for the reason the
        // picker above is: the board binds `d` (delete) and `g`… the same
        // keystrokes, and the binding layer would canonicalize them to *its*
        // events before the overlay ever saw the key the user pressed.
        if matches!(self.mode, Mode::RecurringWarning) {
            return self.handle_recurring_warning_key(key);
        }
        // The mention surfaces' keys are raw, for the same reason: the board binds
        // some of the same letters, and the binding layer would canonicalize them
        // into *its* events before the overlay saw the key the user pressed.
        if matches!(self.mode, Mode::MentionNotice) {
            return self.handle_mention_notice_key(key);
        }
        if matches!(self.mode, Mode::Mentions) {
            return self.handle_mentions_view_key(key);
        }
        // The F8 Schedule page's own raw layer (WP07 T036/T037), placed with the
        // other raw layers and ahead of the binding layer for the same reason they
        // are: the page's `[keybindings.schedule]` section binds the Series tab's
        // actions, so a `Tab` there resolves to the inert sentinel and `c`/`e`/`a`
        // are unbound. Its bound keys (`j`/`k`, `q`, `g`, `p`, `r`, `s`, `i`) still
        // resolve through the bindings, so a rebind of one keeps working.
        if matches!(self.mode, Mode::Schedule) && self.handle_schedule_raw_key(key)? {
            return Ok(Action::None);
        }
        // The `F7` Stats page's **Burndown** tab (WP06 T030), placed with the other raw
        // layers and ahead of the binding layer for the same reason: the tab's controls
        // (`[`, `]`, `p`, `t`, `u`, `v`, `d`, `D`) are bound nowhere, so the binding layer
        // would rewrite them to the inert `F(12)` sentinel. Its bound keys (`j`/`k`,
        // `Tab`, `?`, `q`) still resolve through the bindings, so a rebind keeps working,
        // and the layer returns `false` on every other Stats tab.
        if matches!(self.mode, Mode::Stats) && self.handle_burndown_raw_key(key)? {
            return Ok(Action::None);
        }
        let key = self
            .bindings
            .action(context, key)
            .map(|action| self.bindings.canonical_event(context, action))
            .unwrap_or_else(|| {
                if Self::allows_text_fallback(context) {
                    key
                } else {
                    KeyEvent::new(KeyCode::F(12), KeyModifiers::NONE)
                }
            });
        let result = self.handle_resolved_key(context, key);
        self.sync_top_mode();
        result
    }

    /// The shell action a key resolves to in `context`, if any.
    ///
    /// `None` unless the context is one of the five top-level modes, the context
    /// does **not** bind the key, and the shell context does. The local binding
    /// always wins: this is the single rule that keeps `F2`-in-form as the picker.
    pub(in crate::app) fn shell_action(
        &self,
        context: InputContext,
        key: KeyEvent,
    ) -> Option<TuiAction> {
        if !matches!(
            context,
            InputContext::Board
                | InputContext::Triage
                | InputContext::Cycle
                | InputContext::Milestones
                | InputContext::PlanningManagement
                | InputContext::Settings
                | InputContext::Form
        ) {
            return None;
        }
        if self.bindings.action(context, key).is_some() {
            return None;
        }
        self.bindings.action(InputContext::Shell, key)
    }

    /// Run a shell action: switch modes or cycle the navigation display.
    pub(in crate::app) fn run_shell_action(&mut self, action: TuiAction) -> Result<Action> {
        match action {
            TuiAction::SwitchToBoard => self.switch_top_mode(TopMode::Board),
            TuiAction::SwitchToTriage => self.switch_top_mode(TopMode::Triage),
            TuiAction::SwitchToCycle => self.switch_top_mode(TopMode::Cycle),
            TuiAction::SwitchToMilestones => self.switch_top_mode(TopMode::Milestones),
            TuiAction::SwitchToRepos => self.switch_top_mode(TopMode::Repos),
            TuiAction::SwitchToStats => self.switch_top_mode(TopMode::Stats),
            TuiAction::HealthForm => self.open_health_form(),
            TuiAction::SwitchToSchedule => self.switch_top_mode(TopMode::Schedule),
            TuiAction::SwitchToLibrary => self.switch_top_mode(TopMode::Library),
            TuiAction::SwitchToPortfolio => self.switch_top_mode(TopMode::Portfolio),
            TuiAction::SwitchToNewIssue => self.switch_top_mode(TopMode::NewIssue),
            TuiAction::SwitchToConfig => self.switch_top_mode(TopMode::Config),
            TuiAction::ToggleNavigation => {
                self.nav_display = self.nav_display.next();
                if self.nav_display == NavDisplay::Off {
                    // A cursor on a rail nobody can see is a keyboard trap.
                    self.nav_focus = None;
                }
                Ok(Action::None)
            }
            _ => Ok(Action::None),
        }
    }

    /// Switch the shell to `target`, reusing each mode's existing open path.
    ///
    /// The sibling top-level state is dropped first so a switch does not leave a
    /// stale modal behind to reappear when the mode is left again; the *openers*
    /// are the same methods the letter keys call.
    pub fn switch_top_mode(&mut self, target: TopMode) -> Result<Action> {
        // Released by default; only the Milestones arm re-arms it after opening
        // the Config surface. Keeping this here (not derived from the target in
        // `open_settings`) means every other entry point — `s`, `b` — is Config.
        self.milestone_mode = false;
        match target {
            TopMode::Board => {
                self.close_top_level_state();
                self.mode = Mode::Board;
                self.rebuild_board();
            }
            TopMode::Triage => {
                self.close_top_level_state();
                self.mode = Mode::Board;
                let result = self.open_triage_inbox();
                self.sync_top_mode();
                return result;
            }
            TopMode::Cycle => {
                self.close_top_level_state();
                self.cycle_state = Some(crate::ui::cycle::CycleState::default());
                self.mode = Mode::Cycle;
            }
            TopMode::NewIssue => {
                self.close_top_level_state();
                self.open_new_issue_form();
            }
            TopMode::Config => {
                self.close_top_level_state();
                self.open_settings(None);
            }
            TopMode::Milestones => {
                // The Milestones mode is the Config surface pinned to the
                // milestones section, with the section rail hidden (`render_config`
                // checks `milestone_mode`). Pinning the planning segment here means
                // the body's row cursor is already the milestones list.
                self.close_top_level_state();
                self.open_settings(None);
                self.milestone_mode = true;
                if let Some(settings) = self.settings.as_mut() {
                    settings.section = ConfigSection::Milestones;
                    // No rail is drawn; the index owns the keys.
                    settings.focus(ConfigLevel::Index);
                }
                let modal = self.planning.get_or_insert_with(PlanningModal::new);
                modal.segment = PlanningSegment::Milestones;
                modal.prompt = None;
                modal.selected = 0;
            }
            TopMode::Repos => {
                self.close_top_level_state();
                self.repos_cursor = 0;
                self.mode = Mode::Repos;
            }
            TopMode::Stats => {
                self.close_top_level_state();
                self.stats_cursor = 0;
                // WP05: the page opens on the tab it always showed, and the Time tab's
                // snapshot is taken when that tab is first shown (or after a mutation),
                // never per frame.
                self.stats_tab = StatsTab::Health;
                self.stats_time = None;
                // WP06: the Burndown tab's selections are session state too, and its fold
                // is taken when the tab is first shown — so the page opens on the tab it
                // always showed, with no analytics read at all.
                self.stats_burndown = None;
                // Re-read before drawing: a page that opened with a stale document
                // would show a state the files no longer have.
                self.refresh_health();
                self.mode = Mode::Stats;
            }
            TopMode::Schedule => {
                self.close_top_level_state();
                self.schedule = Some(crate::ui::schedule::ScheduleState::new());
                // A page opened with a stale read would show a state the files no
                // longer have: the capacity read and the schedule warnings are
                // re-derived before the mode draws.
                self.refresh_capacity_view();
                self.refresh_cycle_schedule_warnings();
                self.mode = Mode::Schedule;
            }
            TopMode::Library => {
                self.close_top_level_state();
                self.library = Some(crate::ui::library::LibraryState::new());
                self.mode = Mode::Library;
            }
            TopMode::Portfolio => {
                self.close_top_level_state();
                self.portfolio = Some(crate::ui::portfolio::PortfolioState::new());
                // The page opens on the empty filter; a filter is session state and
                // is never persisted, so a fresh visit starts from "everything".
                self.roadmap_filter = crate::roadmap::RoadmapFilter::default();
                self.refresh_portfolio_projects();
                self.mode = Mode::Portfolio;
            }
        }
        self.sync_top_mode();
        Ok(Action::None)
    }

    /// Drop the state of any top-level mode, so a switch starts clean.
    pub(in crate::app) fn close_top_level_state(&mut self) {
        self.triage = None;
        self.cycle_state = None;
        self.settings = None;
        self.planning = None;
        self.planning_form = None;
        self.date_picker = None;
        self.form = None;
        self.form_picker = None;
        self.filter_modal = None;
        self.filter_picker = None;
        self.schedule = None;
        self.library = None;
        self.portfolio = None;
        self.portfolio_projects = None;
        self.portfolio_reports = None;
        self.portfolio_epics = None;
        self.portfolio_roadmap = None;
        self.portfolio_roadmap_overlay = None;
        // WP05: the two time overlays belong to the Stats page; leaving the page (or
        // entering another) drops them rather than leaving a form over an unrelated
        // mode. The Time tab's snapshot is dropped with them, so the next visit
        // re-reads the files (see `switch_top_mode`).
        self.time_form = None;
        self.time_filter_form = None;
        self.stats_time = None;
        // A message about the mode being left would be stale over the mode being
        // entered; a refusal raised by the new mode's opener sets its own afterwards.
        self.status_msg = None;
    }

    /// Record the top-level mode implied by the current [`Mode`].
    ///
    /// Derived rather than assigned at every entry point: `t`, `m`, `n`, `s`, and
    /// every close path already move `mode`, so reading it back keeps the
    /// navigation highlight in step without a second place to update.
    ///
    /// A planning form or date picker opened **from the Config mode** belongs to
    /// Config, not to the Cycle mode its input context would otherwise imply:
    /// `settings` is `Some` exactly while the Config mode's state is present, and
    /// its sub-surfaces keep it.
    pub(in crate::app) fn sync_top_mode(&mut self) {
        if self.settings.is_some() {
            // The Config surface hosts two top-level modes: F12 Config, and the
            // F5 Milestones mode that borrows it (`milestone_mode`). The flag,
            // not the `InputContext`, decides which — `Milestones` is only one of
            // the contexts this surface can be in.
            self.top_mode = if self.milestone_mode {
                TopMode::Milestones
            } else {
                TopMode::Config
            };
            return;
        }
        if let Some(mode) = Self::top_mode_for_context(self.input_context()) {
            self.top_mode = mode;
        }
    }

    pub(in crate::app) fn top_mode_for_context(context: InputContext) -> Option<TopMode> {
        match context {
            InputContext::Board => Some(TopMode::Board),
            InputContext::Triage => Some(TopMode::Triage),
            InputContext::Cycle => Some(TopMode::Cycle),
            InputContext::PlanningManagement
            | InputContext::PlanningConfirm
            | InputContext::PlanningForm
            | InputContext::DatePicker => Some(TopMode::Cycle),
            InputContext::Settings | InputContext::SettingsPrompt => Some(TopMode::Config),
            InputContext::Milestones => Some(TopMode::Milestones),
            InputContext::Repos => Some(TopMode::Repos),
            InputContext::Stats => Some(TopMode::Stats),
            InputContext::Schedule => Some(TopMode::Schedule),
            InputContext::Library => Some(TopMode::Library),
            InputContext::Portfolio => Some(TopMode::Portfolio),
            InputContext::Form | InputContext::FormPicker => Some(TopMode::NewIssue),
            _ => None,
        }
    }

    pub(in crate::app) fn allows_text_fallback(context: InputContext) -> bool {
        matches!(
            context,
            InputContext::Form
                | InputContext::FormPicker
                | InputContext::Filter
                | InputContext::FilterModal
                // #1496: the overlay's `/` line takes free text. Without this, every
                // letter arrives as `F(12)` — the rewrite happens before the handler sees
                // the key — and the search line would be untypeable. The *list* mode is
                // deliberately not listed here: it has no text entry, so an unbound key
                // there is a no-op either way.
                | InputContext::HelpSearch
                | InputContext::ContextMenu
                | InputContext::PlanningForm
                | InputContext::Comment
                | InputContext::Asset
                | InputContext::MoveIntoDone
                | InputContext::LinkPrompt
                | InputContext::SettingsPrompt
                | InputContext::BulkModal
                | InputContext::Triage
                // WP05: the views modal's name prompt. The **list** context is
                // deliberately absent: it is a menu, so an unbound key there must
                // be inert rather than typed.
                | InputContext::ViewsPrompt
        )
    }

    pub(in crate::app) fn input_context(&self) -> InputContext {
        match &self.mode {
            Mode::Board => InputContext::Board,
            Mode::RolloverDialog => InputContext::Rollover,
            Mode::Detail if self.related_picker.is_some() => InputContext::RelatedPicker,
            Mode::Detail => InputContext::Detail,
            Mode::Form if self.form_picker.is_some() => InputContext::FormPicker,
            Mode::Form => InputContext::Form,
            Mode::ConfirmDelete | Mode::ConfirmArchive { .. } => InputContext::ConfirmDelete,
            Mode::MoveIntoDone { .. } => InputContext::MoveIntoDone,
            Mode::TransitionReason { .. } => InputContext::MoveIntoDone,
            Mode::ConfirmBlockedMove { .. } => InputContext::ConfirmBlockedMove,
            Mode::Help { .. } if self.help_searching => InputContext::HelpSearch,
            Mode::Help { .. } => InputContext::Help,
            // The tips modal draws over the board (or the create form) and reads
            // its own keys raw, so the board's context is the honest one: it is
            // what the modal is standing in for while it is open.
            Mode::Tips { .. } => InputContext::Board,
            Mode::ActionMenu { .. } => InputContext::ContextMenu,
            Mode::Filter { .. } => InputContext::Filter,
            Mode::FilterModal => InputContext::FilterModal,
            Mode::Settings
                if self
                    .settings
                    .as_ref()
                    .is_some_and(|modal| modal.prompt.is_some())
                    // A planning delete confirmation raised from the Config
                    // mode's cycles/milestones sections is answered with the
                    // same `y`/`esc` keys, so it uses the same context.
                    || self
                        .planning
                        .as_ref()
                        .is_some_and(|modal| modal.prompt.is_some()) =>
            {
                InputContext::SettingsPrompt
            }
            Mode::Settings if self.milestone_mode => InputContext::Milestones,
            Mode::Settings => InputContext::Settings,
            Mode::PlanningManagement
                if self
                    .planning
                    .as_ref()
                    .is_some_and(|modal| modal.prompt.is_some()) =>
            {
                InputContext::PlanningConfirm
            }
            Mode::PlanningManagement => InputContext::PlanningManagement,
            Mode::PlanningForm => InputContext::PlanningForm,
            Mode::DatePicker { .. } => InputContext::DatePicker,
            Mode::Comment { .. } => InputContext::Comment,
            Mode::Asset { .. } => InputContext::Asset,
            Mode::EditRepair { .. } => InputContext::EditRepair,
            Mode::EditConflict { .. } => InputContext::EditConflict,
            Mode::LinkCreate { .. } | Mode::LinkEdit { .. } => InputContext::LinkPrompt,
            // #1384: a single-line selector prompt, so it shares the link prompt's
            // Submit/Cancel bindings rather than adding a context that would bind
            // the same two keys.
            Mode::ParentPrompt { .. } => InputContext::LinkPrompt,
            Mode::ConfirmRemoveRelationship { .. } => InputContext::ConfirmDelete,
            Mode::BulkModal => InputContext::BulkModal,
            Mode::TriageInbox => InputContext::Triage,
            Mode::Cycle => InputContext::Cycle,
            Mode::Repos => InputContext::Repos,
            Mode::Stats => InputContext::Stats,
            // The form carries free text, so it takes the typing context — the same
            // one the WIP override prompt uses.
            Mode::HealthForm => InputContext::Comment,
            // WP05: both time overlays carry free text (minutes, a date, a reason, an
            // author), so they take the typing context for the same reason.
            Mode::TimeForm | Mode::TimeFilterForm => InputContext::Comment,
            // The overlay draws over the board and its keys never reach the
            // binding layer (see `handle_key`), so the board's context is the
            // honest one: what is on screen underneath is the board.
            // Both mention surfaces draw over the board and read their own keys
            // raw (see `handle_key`), so the board's context is the honest one.
            Mode::Mentions | Mode::MentionNotice => InputContext::Board,
            Mode::RecurringWarning => InputContext::Board,
            // The override modal carries the one free-text field, so it takes the
            // text context: a reason is typed, not pressed.
            Mode::WipOverride { .. } => InputContext::Comment,
            Mode::Schedule => InputContext::Schedule,
            Mode::Library => InputContext::Library,
            Mode::Portfolio => InputContext::Portfolio,
            // WP05. The views modal has two key layers, exactly as the settings
            // modal has one and the triage inbox has one: a prompt takes the keys
            // first (and is the only layer that carries free text), the list has
            // them otherwise. A delete confirmation borrows the shared
            // `ConfirmDelete` context, so `y`/`esc` mean here what they mean
            // everywhere else that confirms.
            Mode::Views => match self.views.as_ref().and_then(|modal| modal.prompt.as_ref()) {
                Some(ViewsPrompt::ConfirmDelete { .. }) => InputContext::ConfirmDelete,
                Some(ViewsPrompt::Create(_) | ViewsPrompt::Rename { .. }) => {
                    InputContext::ViewsPrompt
                }
                None => InputContext::Views,
            },
        }
    }

    /// The batch modal's keys (WP07 T032/T033).
    ///
    /// Every branch here either changes the modal's **own** state or calls a shared
    /// service. There is no `IssuePatch` built here and no `store.update` here: the
    /// modal holds `PatchFlags` and the plan/apply live in `bulk::plan`/`bulk::apply`,
    /// which is what "reject TUI-local patch construction or direct writes" asks for.
    ///
    /// `p` previews, `y` **arms** and then `y` again confirms, and `esc` cancels from
    /// any state. Two `y` presses because "I saw it" and "I approved it" are two
    /// decisions, and one `y` conflates them.
    /// Open the batch modal, optionally marking the card under the cursor first.
    ///
    /// `mark` is what makes `space` on a card the first press rather than two. It
    /// marks **only if** the selection is not already refused — a duplicate or a
    /// full selection is reported on the modal's note, not silently swallowed, so
    /// the second `space` on the same card tells the user why nothing changed.
    ///
    /// The board's `(active_col, selected)` cursor is never written here, so opening
    /// and cancelling the modal restores the board exactly (T031).
    pub(in crate::app) fn open_bulk_modal(
        &mut self,
        action: crate::ui::bulk::BatchAction,
        mark: bool,
    ) {
        if mark {
            let number = self.board.get_selected_card().map(|c| c.number);
            let mut modal = self
                .bulk
                .take()
                .unwrap_or_else(|| crate::ui::bulk::BulkModal::new(action));
            if let Some(number) = number {
                if let Err(problem) = modal.selection.toggle(number) {
                    modal.note = Some(problem.to_string());
                }
            }
            self.bulk = Some(modal);
        } else if self.bulk.is_none() {
            self.bulk = Some(crate::ui::bulk::BulkModal::new(action));
        }
        self.mode = Mode::BulkModal;
    }

    pub(in crate::app) fn handle_resolved_key(
        &mut self,
        _context: InputContext,
        key: KeyEvent,
    ) -> Result<Action> {
        match self.mode.clone() {
            Mode::Board => self.handle_board_key(key),
            Mode::RolloverDialog => self.handle_rollover_dialog_key(key),
            Mode::Detail => self.handle_detail_key(key),
            Mode::Form => self.handle_form_key(key),
            Mode::ConfirmDelete => self.handle_confirm_delete_key(key),
            Mode::ConfirmArchive { .. } => self.handle_confirm_archive_key(key),
            Mode::MoveIntoDone { .. } => self.handle_move_into_done_key(key),
            Mode::TransitionReason { .. } => self.handle_transition_reason_key(key),
            Mode::ConfirmBlockedMove { warning } => {
                self.handle_confirm_blocked_move_key(key, &warning)
            }
            Mode::Help { .. } => self.handle_help_key(key),
            Mode::Tips { .. } => self.handle_tips_key(key),
            Mode::ActionMenu { .. } => self.handle_action_menu_key(key),
            Mode::Filter { .. } => self.handle_filter_key(key),
            Mode::FilterModal => self.handle_filter_modal_key(key),
            Mode::BulkModal => self.handle_bulk_modal_key(key),
            Mode::TriageInbox => self.handle_triage_key(key),
            Mode::Cycle => self.handle_cycle_key(key),
            Mode::Repos => self.handle_repos_key(key),
            Mode::Stats => self.handle_stats_key(key),
            Mode::HealthForm => self.handle_health_form_key(key),
            Mode::TimeForm => self.handle_time_form_key(key),
            Mode::TimeFilterForm => self.handle_time_filter_form_key(key),
            Mode::MentionNotice => self.handle_mention_notice_key(key),
            Mode::Mentions => self.handle_mentions_view_key(key),
            Mode::RecurringWarning => self.handle_recurring_warning_key(key),
            Mode::WipOverride { .. } => self.handle_wip_override_key(key),
            Mode::Schedule => self.handle_schedule_key(key),
            Mode::Library => self.handle_library_key(key),
            Mode::Portfolio => self.handle_portfolio_key(key),
            Mode::Views => self.handle_views_key(key),
            Mode::Settings => self.handle_settings_key(key),
            Mode::PlanningManagement => self.handle_planning_key(key),
            Mode::PlanningForm => self.handle_planning_form_key(key),
            Mode::DatePicker { .. } => self.handle_date_picker_key(key),
            Mode::Comment { .. } => self.handle_comment_key(key),
            Mode::Asset { .. } => self.handle_asset_key(key),
            Mode::EditRepair { .. } => self.handle_edit_repair_key(key),
            Mode::EditConflict { .. } => self.handle_edit_conflict_key(key),
            Mode::LinkCreate { .. } => self.handle_link_prompt_key(key),
            Mode::LinkEdit { .. } => self.handle_link_prompt_key(key),
            Mode::ParentPrompt { .. } => self.handle_parent_prompt_key(key),
            Mode::ConfirmRemoveRelationship { .. } => self.handle_remove_relationship_key(key),
        }
    }
}