mnml-rs 0.2.14

A NvChad-style terminal IDE in Rust — vim or standard editing, LSP, git, and an embedded HTTP client.
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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
//! Right-click (`MouseEventKind::Down(MouseButton::Right)`) dispatch
//! — extracted from `mouse/mod.rs` (T-4 of the file-split refactor,
//! 2026-06-29). The right-click handler is a ~440-line cascade of
//! `if let Some(rect) = ...rects.X && contains(*, x, y) { open_X_menu;
//! return; }` early-outs. Cleanly isolatable since every arm returns
//! after consuming.
//!
//! Public surface: `handle_right_click(app, x, y)`. Called from
//! `dispatch_mouse`'s `MouseEventKind::Down(MouseButton::Right)`
//! arm. Returns nothing — its `return;`s exit this function only,
//! after which the caller's match arm completes naturally.

use crate::app::App;
use crate::pane::Pane;

pub(super) fn handle_right_click(app: &mut App, x: u16, y: u16) {
    if app.debug_click_inspector {
        let hits = app.rects.inspect_click_targets(x, y);
        let msg = if hits.is_empty() {
            format!("right-click @ ({x}, {y}): no PaneRects hit")
        } else {
            format!("right-click @ ({x}, {y}): {}", hits.join(" · "))
        };
        app.toast(msg);
    }
    // Right-click on a `{{var}}` token → var context menu (set
    // value, jump to definition, copy name). Checked first because
    // token rects overlap the URL / body / value-cell rects that
    // fall through to more generic menus below.
    if let Some((_, name)) = app
        .rects
        .request_var_click_rects
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        let name = name.clone();
        app.open_request_var_context_menu(&name, (x, y));
        return;
    }
    // vscode-user-mouse SEV-3 — right-click on the palette
    // search chip mirrors the dropdown chevron and opens
    // recents directly (browser-style "back / forward / open
    // recents" via context menu).
    if let Some(r) = app.rects.palette_search_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        let _ = crate::command::run("picker.recent", app);
        return;
    }
    // Right-click on the activity-bar gear mirrors left-click
    // — opens the same Settings / Cmd Palette / Themes /
    // About menu (matches macOS gear-icon UX where right-click
    // is the canonical way to expose options).
    if let Some(r) = app.rects.activity_bar_gear
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_gear_context_menu((x, y));
        return;
    }
    // mouse-hunter v3 SEV-2 F — right-click on a right-panel
    // tab chip opens a small context menu (switch to / close).
    if let Some(&(_, tab_idx)) = app
        .rects
        .right_panel_tabs
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        app.open_right_panel_tab_context_menu(tab_idx, (x, y));
        return;
    }
    // vscode-user-mouse 2026-06-28 SEV-3 — right-click on the
    // panel × close button (was a 1-cell dead zone). Open
    // the same active-tab menu the right-click on a tab
    // chip would for parity. If no tab is hosted, toast.
    if let Some(rect) = app.rects.right_panel_close
        && crate::app::dispatch::contains(rect, x, y)
    {
        let idx = app.right_panel_active_idx;
        if !app.right_panel_panes.is_empty() && idx < app.right_panel_panes.len() {
            app.open_right_panel_tab_context_menu(idx, (x, y));
        } else {
            app.toast("right panel empty — Ctrl+Shift+B to hide");
        }
        return;
    }
    // Right-click on a session tab → context menu.
    if let Some(&(_, pid)) = app
        .rects
        .session_tabs
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        app.open_session_tab_context_menu(pid, (x, y));
        return;
    }
    // Right-click on a dock widget (body, title, or kebab)
    // → open the kebab menu anchored at the click. Same
    // menu as the `⋮` glyph; gives power users a faster
    // path. Checked first so the menu wins over per-pane
    // right-click handlers below.
    if let Some(id) = app
        .rects
        .dock_widget_bodies
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
        .map(|(_, id)| *id)
        .or_else(|| {
            app.rects
                .dock_widget_titles
                .iter()
                .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
                .map(|(_, id)| *id)
        })
        .or_else(|| {
            app.rects
                .dock_widget_kebabs
                .iter()
                .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
                .map(|(_, id)| *id)
        })
    {
        if let Some(w) = app.dock_widgets.iter().find(|w| w.id == id) {
            app.dock_kebab_menu = Some(crate::dock::KebabMenuState::build(w, x, y));
        }
        return;
    }
    // 2026-06-21 vscode-mouse SEV-2: right-click on a
    // Claude Agents dashboard row → context menu. Currently 6
    // items: Open transcript / Resume in mnml pty / Yank session
    // id / Yank cwd / Export as markdown / Kill session.
    // (qa-6th 2026-06-29 doc fix — was claiming 7.)
    if let Some(&(_, pid, row_idx)) = app.rects.list_rows.iter().find(|(r, pid, _)| {
        matches!(app.panes.get(*pid), Some(Pane::ClaudeAgents(_)))
            && crate::app::dispatch::contains(*r, x, y)
    }) {
        app.open_dashboard_row_context_menu(pid, row_idx, (x, y));
        return;
    }
    // Cloud Agents panel row → 3-item context menu:
    // Copy runId · Open CloudWatch logs · Open PR (if set).
    if let Some(&(_, row_idx)) = app
        .rects
        .cloud_agents_rows
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        app.open_cloud_row_context_menu(row_idx, (x, y));
        return;
    }
    // 2026-06-21 — right-click on a Files drill-down panel
    // row in the dashboard → 4-item context menu
    // (Open / Reveal in tree / Yank path / Copy to scratch).
    if let Some(path) = app
        .rects
        .claude_drill_files
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
        .map(|(_, p)| p.clone())
    {
        app.open_dashboard_file_context_menu(path, (x, y));
        return;
    }
    // #polish 2026-07-06 — right-click on the GIT rail header
    // opens a small menu with Refresh / Collapse-section /
    // Fetch quick actions.
    if let Some(r) = app.rects.git_section_toggle
        && crate::app::dispatch::contains(r, x, y)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let items = vec![
            MenuItem::new("Fetch", MenuAction::Command("git.fetch")),
            MenuItem::new("Pull", MenuAction::Command("git.pull")),
            MenuItem::new("Open graph", MenuAction::Command("git.graph")),
        ];
        app.context_menu = Some(ContextMenu::new(
            Some("Git rail".to_string()),
            (x, y),
            items,
        ));
        return;
    }
    // #polish 2026-07-06 — right-click on the Cloud Agents view
    // chip → density menu (both options + toggle for consistency).
    if let Some(r) = app.rects.cloud_agents_view_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let cur = app.cloud_agents_view;
        let compact_label = if cur == crate::app::CloudAgentsView::Compact {
            "✓ Compact"
        } else {
            "  Compact"
        };
        let standard_label = if cur == crate::app::CloudAgentsView::Standard {
            "✓ Standard"
        } else {
            "  Standard"
        };
        let items = vec![
            MenuItem::new(
                compact_label,
                MenuAction::Command("cloud_agents.view_compact"),
            ),
            MenuItem::new(
                standard_label,
                MenuAction::Command("cloud_agents.view_standard"),
            ),
        ];
        app.context_menu = Some(ContextMenu::new(
            Some("Row density".to_string()),
            (x, y),
            items,
        ));
        return;
    }
    // #polish 2026-07-06 — right-click on a Notes-panel file row.
    if let Some(path) = app
        .rects
        .notes_panel_files
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
        .map(|(_, p)| p.clone())
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let rel = crate::app::rel_path(&app.workspace, &path);
        let title = path
            .file_name()
            .map(|s| s.to_string_lossy().to_string())
            .unwrap_or_else(|| "note".to_string());
        let items = vec![
            MenuItem::new("Open", MenuAction::OpenPath(path.clone())),
            MenuItem::new("Open in split", MenuAction::OpenInSplit(path.clone())),
            MenuItem::new("Reveal in tree", MenuAction::RevealInFinder(path.clone())),
            MenuItem::new("Yank path", MenuAction::CopyPath(rel)),
            MenuItem::new("Rename…", MenuAction::Rename(path.clone())),
            MenuItem::new("Delete…", MenuAction::Delete(path)),
        ];
        app.context_menu = Some(ContextMenu::new(Some(title), (x, y), items));
        return;
    }
    // #polish 2026-07-06 — right-click on an activity-bar icon
    // opens a small menu with "Show / Focus this rail" (mirrors
    // left-click) + convenient jumps. Users familiar with VS
    // Code will recognize the pattern.
    if let Some(&(_, section)) = app
        .rects
        .activity_bar_icons
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let (_, _, label, cmd_id) = section.meta();
        // Section-specific quick actions in addition to the
        // basic show/focus.
        let mut items: Vec<MenuItem> = Vec::new();
        items.push(MenuItem::new(
            format!("Show {label}"),
            MenuAction::Command(cmd_id),
        ));
        use crate::app::ActivitySection;
        match section {
            ActivitySection::Explorer => {
                items.push(MenuItem::new(
                    "Reveal active file",
                    MenuAction::Command("view.reveal_active"),
                ));
                items.push(MenuItem::new(
                    "Refresh tree",
                    MenuAction::Command("tree.refresh"),
                ));
            }
            ActivitySection::Http => {
                items.push(MenuItem::new(
                    "+ New request",
                    MenuAction::Command("http.new"),
                ));
                items.push(MenuItem::new(
                    "Paste curl from clipboard",
                    MenuAction::Command("http.paste_curl"),
                ));
            }
            ActivitySection::Notes => {
                items.push(MenuItem::new(
                    "+ New note",
                    MenuAction::Command("notes.new"),
                ));
            }
            ActivitySection::Todos => {
                items.push(MenuItem::new(
                    "Rescan",
                    MenuAction::Command("todos.refresh"),
                ));
            }
            ActivitySection::Agents => {
                items.push(MenuItem::new(
                    "Open dashboard",
                    MenuAction::Command("ai.dashboard"),
                ));
            }
            // mouse-round-16 F4 2026-07-17 — fill in the 5 sparse
            // "Show X"-only activity-bar menus with a section-
            // specific quick action. Each is a single well-scoped
            // verb the user hits most on that panel — not an
            // exhaustive list; users still have the palette for
            // everything else.
            ActivitySection::Search => {
                items.push(MenuItem::new(
                    "New search",
                    MenuAction::Command("find.grep"),
                ));
            }
            ActivitySection::Git => {
                items.push(MenuItem::new(
                    "Open git graph",
                    MenuAction::Command("git.graph"),
                ));
                items.push(MenuItem::new("Fetch", MenuAction::Command("git.fetch")));
                items.push(MenuItem::new("Commit…", MenuAction::Command("git.commit")));
            }
            ActivitySection::Debug => {
                items.push(MenuItem::new("Run", MenuAction::Command("dap.run")));
                items.push(MenuItem::new(
                    "Toggle breakpoint at cursor",
                    MenuAction::Command("dap.toggle_breakpoint"),
                ));
            }
            ActivitySection::Integrations => {
                items.push(MenuItem::new(
                    "Refresh integrations",
                    MenuAction::Command("integrations.refresh"),
                ));
                items.push(MenuItem::new(
                    "Refresh binary cache",
                    MenuAction::Command("integrations.refresh_binary_cache"),
                ));
            }
            ActivitySection::Sessions => {
                items.push(MenuItem::new(
                    "+ New Claude Code session",
                    MenuAction::Command("ai.claude_code_new"),
                ));
                items.push(MenuItem::new(
                    "+ New Codex session",
                    MenuAction::Command("ai.codex_new"),
                ));
            }
            ActivitySection::CloudAgents => {
                items.push(MenuItem::new(
                    "+ New cloud run",
                    MenuAction::Command("cloud_agents.new_run"),
                ));
                items.push(MenuItem::new(
                    "+ New from wizard",
                    MenuAction::Command("cloud_agents.new_run_wizard"),
                ));
            }
            // 2026-07-20 — LauncherIcon reorder + unpin actions.
            // Replace the default items entirely — "Show
            // Launcher" is not a real command (LauncherIcon is
            // click-to-fire, not a section). Then Move to
            // top / Move up / Move down / Move to bottom (matching
            // the sidebar chip right-click order the user
            // asked for) + Remove from activity bar.
            ActivitySection::LauncherIcon(idx) => {
                let idx_us = idx as usize;
                let list = &app.config.ui.activity_bar_pinned_integrations;
                let is_first = idx_us == 0;
                let is_last = idx_us + 1 >= list.len();
                let integ_id = list.get(idx_us).cloned();
                items.clear();
                if let Some(id) = integ_id.clone() {
                    // Custom launch item at the top so users can
                    // fire without hunting for the exact icon.
                    items.push(MenuItem::new(
                        "Launch",
                        MenuAction::LaunchPinnedIntegration(id.clone()),
                    ));
                    if !is_first {
                        items.push(MenuItem::new(
                            "Move to top",
                            MenuAction::MovePinnedIntegrationToTop(id.clone()),
                        ));
                        items.push(MenuItem::new(
                            "Move up",
                            MenuAction::MovePinnedIntegrationUp(id.clone()),
                        ));
                    }
                    if !is_last {
                        items.push(MenuItem::new(
                            "Move down",
                            MenuAction::MovePinnedIntegrationDown(id.clone()),
                        ));
                        items.push(MenuItem::new(
                            "Move to bottom",
                            MenuAction::MovePinnedIntegrationToBottom(id.clone()),
                        ));
                    }
                    items.push(MenuItem::new(
                        "Remove from activity bar",
                        MenuAction::RemoveIntegrationFromActivityBar(id),
                    ));
                }
            }
            _ => {}
        }
        app.context_menu = Some(ContextMenu::new(Some(label.to_string()), (x, y), items));
        return;
    }
    // #21 v6 — right-click on a response tab (Body / Headers /
    // Timeline / Tests) opens a small menu of tab-scoped actions.
    if let Some(tab) = app
        .rects
        .request_response_tabs
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
        .map(|(_, t)| *t)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        use crate::request_pane::ResponseTab;
        let (title, items) = match tab {
            ResponseTab::Body => (
                "Response Body",
                vec![
                    MenuItem::new("Copy body", MenuAction::Command("http.copy_response_body")),
                    MenuItem::new("Format JSON", MenuAction::Command("http.format_body")),
                    MenuItem::new("Save to file…", MenuAction::Command("http.save_response")),
                ],
            ),
            ResponseTab::Headers => (
                "Response Headers",
                vec![MenuItem::new(
                    "Copy headers",
                    MenuAction::Command("http.copy_response_headers"),
                )],
            ),
            ResponseTab::Timeline => (
                "Response Timeline",
                vec![MenuItem::new(
                    "Diff last two responses",
                    MenuAction::Command("http.diff_last_two"),
                )],
            ),
            ResponseTab::Tests => (
                "Response Tests",
                vec![MenuItem::new("Re-run", MenuAction::Command("http.send"))],
            ),
        };
        app.context_menu = Some(ContextMenu::new(Some(title.to_string()), (x, y), items));
        return;
    }
    // #21 v3 — right-click on Send / Save / Clear / Code chips
    // opens a small kebab-menu that surfaces the useful adjacent
    // actions (fire options for Send, save-as / open source for
    // Save, copy-as for Code).
    if let Some(r) = app.rects.request_send_button
        && crate::app::dispatch::contains(r, x, y)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let items = vec![
            MenuItem::new("Send", MenuAction::Command("http.send")),
            MenuItem::new("Abort in-flight", MenuAction::Command("http.abort")),
            MenuItem::new(
                "Diff last two responses",
                MenuAction::Command("http.diff_last_two"),
            ),
        ];
        app.context_menu = Some(ContextMenu::new(Some("Send".to_string()), (x, y), items));
        return;
    }
    if let Some(r) = app.rects.request_save_button
        && crate::app::dispatch::contains(r, x, y)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let items = vec![
            MenuItem::new("Save request", MenuAction::Command("http.save")),
            MenuItem::new(
                "Save response as mock",
                MenuAction::Command("http.save_mock"),
            ),
            MenuItem::new(
                "Save response to file…",
                MenuAction::Command("http.save_response"),
            ),
        ];
        app.context_menu = Some(ContextMenu::new(Some("Save".to_string()), (x, y), items));
        return;
    }
    // (Code chip menu references `http.generate_code`, which was
    // just added above alongside `http.save`.)
    if let Some(r) = app.rects.request_clear_button
        && crate::app::dispatch::contains(r, x, y)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let items = vec![MenuItem::new(
            "Clear request",
            MenuAction::Command("http.new"),
        )];
        app.context_menu = Some(ContextMenu::new(Some("Clear".to_string()), (x, y), items));
        return;
    }
    if let Some(r) = app.rects.request_code_button
        && crate::app::dispatch::contains(r, x, y)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let items = vec![
            MenuItem::new("Copy as curl", MenuAction::Command("http.copy_curl")),
            MenuItem::new("Generate code…", MenuAction::Command("http.generate_code")),
        ];
        app.context_menu = Some(ContextMenu::new(Some("Code".to_string()), (x, y), items));
        return;
    }
    // #23 v2 — right-click on a Vars-tab row → Edit / Copy / Delete
    // shortcut menu (bypasses the two-step prompt for delete).
    if let Some(key) = app
        .rects
        .request_vars_rows
        .iter()
        .find(|(r, _, _)| crate::app::dispatch::contains(*r, x, y))
        .map(|(_, k, _)| k.clone())
    {
        if !key.is_empty() {
            use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
            let items = vec![
                MenuItem::new("Edit…", MenuAction::CopyPath(format!("edit:{key}"))),
                MenuItem::new("Yank name", MenuAction::CopyPath(key.clone())),
                MenuItem::new("Delete…", MenuAction::Command("http.delete_env_key")),
            ];
            app.pending_env_key_delete = Some(key.clone());
            app.context_menu = Some(ContextMenu::new(Some(key), (x, y), items));
        }
        return;
    }
    // Right-click on the Request pane's Env chip — quick switch /
    // edit / clear-override menu.
    if let Some(r) = app.rects.request_env_button
        && crate::app::dispatch::contains(r, x, y)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let has_override = app.http_env_override.is_some();
        let mut items = vec![
            MenuItem::new("Switch env…", MenuAction::Command("http.pick_env")),
            MenuItem::new("Edit env file", MenuAction::Command("http.edit_env")),
        ];
        if has_override {
            items.push(MenuItem::new(
                "Clear override",
                MenuAction::Command("http.reset_env"),
            ));
        }
        app.context_menu = Some(ContextMenu::new(Some("Env".to_string()), (x, y), items));
        return;
    }
    // Right-click on an HTTP-sidebar file row — Open / Reveal /
    // Delete / Copy path. Fixes the 9-scratch-file cleanup pain
    // from the mouse audit (was left-click-only = open, no way to
    // delete without dropping to the tree).
    if let Some(path) = app
        .rects
        .http_panel_files
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
        .map(|(_, p)| p.clone())
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let rel = crate::app::rel_path(&app.workspace, &path);
        let title = path
            .file_name()
            .map(|s| s.to_string_lossy().to_string())
            .unwrap_or_else(|| rel.clone());
        let items = vec![
            MenuItem::new("Open", MenuAction::OpenPath(path.clone())),
            MenuItem::new("Open as text", MenuAction::OpenPathAsText(path.clone())),
            MenuItem::new("Open in split", MenuAction::OpenInSplit(path.clone())),
            MenuItem::new("Reveal in tree", MenuAction::RevealInFinder(path.clone())),
            MenuItem::new("Yank path", MenuAction::CopyPath(rel)),
            MenuItem::new("Rename…", MenuAction::Rename(path.clone())),
            MenuItem::new("Delete…", MenuAction::Delete(path)),
        ];
        app.context_menu = Some(ContextMenu::new(Some(title), (x, y), items));
        return;
    }
    // Right-click on RECENT row — open, copy curl, delete entry.
    if let Some(idx) = app
        .rects
        .http_panel_recent_rows
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
        .map(|(_, i)| *i)
    {
        if let Some(entry) = app.http_panel_recent_cache.get(idx).cloned() {
            use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
            let (curl, method, url) = crate::http::history::entry_to_curl(&entry);
            let title = format!("{method} {}", &url[..40.min(url.len())]);
            let items = vec![
                MenuItem::new("Open as scratch", MenuAction::CopyPath(curl.clone())),
                MenuItem::new("Yank curl", MenuAction::CopyPath(curl)),
                MenuItem::new("Yank URL", MenuAction::CopyPath(url)),
            ];
            app.context_menu = Some(ContextMenu::new(Some(title), (x, y), items));
        }
        return;
    }
    // Right-click on CAPTURED row — open as curl / copy curl / copy URL.
    if let Some(idx) = app
        .rects
        .http_panel_captured_rows
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
        .map(|(_, i)| *i)
    {
        if let Some(row) = app.http_panel_captured_cache.get(idx).cloned() {
            use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
            let curl = row.to_curl();
            let title = format!("{} {}", row.method, &row.url[..40.min(row.url.len())]);
            let items = vec![
                MenuItem::new("Open as scratch", MenuAction::CopyPath(curl.clone())),
                MenuItem::new("Yank curl", MenuAction::CopyPath(curl)),
                MenuItem::new("Yank URL", MenuAction::CopyPath(row.url)),
            ];
            app.context_menu = Some(ContextMenu::new(Some(title), (x, y), items));
        }
        return;
    }
    // Right-click on ENVS row — quick actions for that env file.
    if let Some(name) = app
        .rects
        .http_panel_env_rows
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
        .map(|(_, n)| n.clone())
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        // Prefer `.mnml/env/<name>.env` (mnml-native), fall back to
        // `.rqst/env/<name>.env` (legacy). This matches
        // `EnvSet::load` precedence.
        let mnml_path = app
            .workspace
            .join(".mnml")
            .join("env")
            .join(format!("{name}.env"));
        let rqst_path = app
            .workspace
            .join(".rqst")
            .join("env")
            .join(format!("{name}.env"));
        let env_file = if mnml_path.exists() {
            mnml_path
        } else {
            rqst_path
        };
        let rel = crate::app::rel_path(&app.workspace, &env_file);
        let items = vec![
            MenuItem::new("Set active", MenuAction::Command("http.pick_env")),
            MenuItem::new("Open file", MenuAction::OpenPath(env_file.clone())),
            MenuItem::new("Yank name", MenuAction::CopyPath(name.clone())),
            MenuItem::new("Yank path", MenuAction::CopyPath(rel)),
            MenuItem::new("Rename…", MenuAction::Rename(env_file.clone())),
            MenuItem::new("Delete…", MenuAction::Delete(env_file)),
        ];
        app.context_menu = Some(ContextMenu::new(Some(name), (x, y), items));
        return;
    }
    // Right-click on CHAINS row — Run / Open / Reveal / Delete.
    if let Some(path) = app
        .rects
        .http_panel_chain_rows
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
        .map(|(_, p)| p.clone())
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let title = path
            .file_name()
            .map(|s| s.to_string_lossy().to_string())
            .unwrap_or_else(|| "chain".to_string());
        let rel = crate::app::rel_path(&app.workspace, &path);
        let items = vec![
            MenuItem::new("Run chain", MenuAction::OpenPath(path.clone())),
            MenuItem::new("Open file", MenuAction::OpenPath(path.clone())),
            MenuItem::new("Reveal in tree", MenuAction::RevealInFinder(path.clone())),
            MenuItem::new("Yank path", MenuAction::CopyPath(rel)),
            MenuItem::new("Delete…", MenuAction::Delete(path)),
        ];
        app.context_menu = Some(ContextMenu::new(Some(title), (x, y), items));
        return;
    }
    // #22 v4 — right-click on a Collections file row.
    if let Some(path) = app
        .rects
        .http_panel_collection_rows
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
        .map(|(_, p)| p.clone())
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let title = path
            .file_name()
            .map(|s| s.to_string_lossy().to_string())
            .unwrap_or_else(|| "request".to_string());
        let rel = crate::app::rel_path(&app.workspace, &path);
        let items = vec![
            MenuItem::new("Open", MenuAction::OpenPath(path.clone())),
            MenuItem::new("Open as text", MenuAction::OpenPathAsText(path.clone())),
            MenuItem::new("Open in split", MenuAction::OpenInSplit(path.clone())),
            MenuItem::new("Reveal in tree", MenuAction::RevealInFinder(path.clone())),
            MenuItem::new("Yank path", MenuAction::CopyPath(rel)),
            MenuItem::new("Rename…", MenuAction::Rename(path.clone())),
            MenuItem::new("Delete…", MenuAction::Delete(path)),
        ];
        app.context_menu = Some(ContextMenu::new(Some(title), (x, y), items));
        return;
    }
    // #22 v4 — right-click on a Collections folder row.
    if let Some(dir) = app
        .rects
        .http_panel_collection_folder_rows
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
        .map(|(_, d)| d.clone())
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let title = dir
            .file_name()
            .map(|s| format!("{}/", s.to_string_lossy()))
            .unwrap_or_else(|| "collection".to_string());
        let rel = crate::app::rel_path(&app.workspace, &dir);
        let items = vec![
            MenuItem::new("New request…", MenuAction::NewFile(dir.clone())),
            MenuItem::new("New sub-collection…", MenuAction::NewFolder(dir.clone())),
            MenuItem::new("Reveal in tree", MenuAction::RevealInFinder(dir.clone())),
            MenuItem::new("Yank path", MenuAction::CopyPath(rel)),
            MenuItem::new("Rename…", MenuAction::Rename(dir.clone())),
            MenuItem::new("Delete collection…", MenuAction::Delete(dir)),
        ];
        app.context_menu = Some(ContextMenu::new(Some(title), (x, y), items));
        return;
    }
    // Right-click on MOCKS row — Replay / Open / Reveal / Delete.
    if let Some(path) = app
        .rects
        .http_panel_mock_rows
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
        .map(|(_, p)| p.clone())
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let title = path
            .file_name()
            .map(|s| s.to_string_lossy().to_string())
            .unwrap_or_else(|| "mock".to_string());
        let rel = crate::app::rel_path(&app.workspace, &path);
        let items = vec![
            MenuItem::new("Replay mock", MenuAction::OpenPath(path.clone())),
            MenuItem::new("Open file", MenuAction::OpenPath(path.clone())),
            MenuItem::new("Reveal in tree", MenuAction::RevealInFinder(path.clone())),
            MenuItem::new("Yank path", MenuAction::CopyPath(rel)),
            MenuItem::new("Delete…", MenuAction::Delete(path)),
        ];
        app.context_menu = Some(ContextMenu::new(Some(title), (x, y), items));
        return;
    }
    // Right-click on a statusline chip — context menus for the four
    // clickable chips (branch / workspace / mode / clock).
    if let Some(r) = app.rects.statusline_branch_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_statusline_branch_context_menu((x, y));
        return;
    }
    if let Some(r) = app.rects.statusline_workspace_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_statusline_workspace_context_menu((x, y));
        return;
    }
    if let Some(r) = app.rects.statusline_mode_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_statusline_mode_context_menu((x, y));
        return;
    }
    // design-critic round-3 finding #3 2026-07-11 — the file chip's
    // tooltip promised a "buffer menu" on right-click but nothing
    // was wired. Fulfill the promise with a compact menu that
    // covers the common needs: reveal in tree, copy paths, close.
    if let Some(r) = app.rects.statusline_file_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_statusline_file_context_menu((x, y));
        return;
    }
    // design-critic round-3 finding #6 2026-07-11 — PR chip
    // right-click. Left-click already opens the URL; right-click
    // exposes copy actions so users can paste the URL / number into
    // a commit body, PR description, or chat message.
    if let Some(r) = app.rects.statusline_pr_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_statusline_pr_context_menu((x, y));
        return;
    }
    // mouse-round-9 SEV-3 2026-07-11 — palette back/forward buttons
    // right-click. Left-click steps buffer MRU; right-click shows
    // a picker of nav history + a "clear" option.
    if let Some(r) = app.rects.palette_back_button
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_palette_nav_context_menu(false, (x, y));
        return;
    }
    if let Some(r) = app.rects.palette_forward_button
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_palette_nav_context_menu(true, (x, y));
        return;
    }
    // mouse-round-7 SEV-2 2026-07-12 — sidebar / right-panel
    // toggle chips + dropdown chevron gained right-click menus so
    // the "chips have menus" mental model isn't broken on the
    // built-in chrome chips. Left-click on each is unchanged.
    if let Some(r) = app.rects.palette_sidebar_button
        && crate::app::dispatch::contains(r, x, y)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let visible = app.tree_visible;
        let items = vec![
            MenuItem::new(
                if visible {
                    "Hide sidebar"
                } else {
                    "Show sidebar"
                },
                MenuAction::Command("view.toggle_tree"),
            ),
            MenuItem::new(
                "Reset sidebar width",
                MenuAction::Command("view.reset_tree_width"),
            ),
            MenuItem::new("Focus sidebar", MenuAction::Command("view.focus_tree")),
        ];
        app.context_menu = Some(ContextMenu::new(Some("Sidebar".to_string()), (x, y), items));
        return;
    }
    if let Some(r) = app.rects.palette_right_panel_button
        && crate::app::dispatch::contains(r, x, y)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let visible = app.right_panel_visible;
        let items = vec![
            MenuItem::new(
                if visible {
                    "Hide right panel"
                } else {
                    "Show right panel"
                },
                MenuAction::Command("view.toggle_right_panel"),
            ),
            MenuItem::new(
                "Focus right panel",
                MenuAction::Command("view.focus_right_panel"),
            ),
            MenuItem::new("Add Outline", MenuAction::Command("outline.show")),
            MenuItem::new("Add Problems", MenuAction::Command("lsp.diagnostics")),
        ];
        app.context_menu = Some(ContextMenu::new(
            Some("Right panel".to_string()),
            (x, y),
            items,
        ));
        return;
    }
    if let Some(r) = app.rects.palette_dropdown_button
        && crate::app::dispatch::contains(r, x, y)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let items = vec![
            MenuItem::new("Recent files", MenuAction::Command("picker.recent")),
            MenuItem::new(
                "Recent commands",
                MenuAction::Command("picker.recent_commands"),
            ),
            MenuItem::new("All files", MenuAction::Command("picker.files")),
            MenuItem::new("Command palette", MenuAction::Command("palette")),
        ];
        app.context_menu = Some(ContextMenu::new(Some("Open…".to_string()), (x, y), items));
        return;
    }
    // Stress meter — both the statusline chip and the top-right
    // mirror show the same menu. 2026-07-12 user request.
    if let Some(r) = app.rects.palette_stress_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_stress_meter_context_menu((x, y));
        return;
    }
    // Right-click on the bufferline `+` new-tab button — offer a
    // "New tab" menu with the reopen-closed action so users have a
    // mouse path to Ctrl+Shift+T. mouse-round-10 SEV-3 2026-07-12.
    if let Some(r) = app.rects.bufferline_new_tab_button
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_new_tab_context_menu((x, y));
        return;
    }
    // Right-click on the bufferline theme-toggle chip → theme menu.
    // Left-click already toggles primary ↔ configured alt; right-click
    // gives access to the picker + default reset. mouse-round-8 SEV-3
    // 2026-07-12.
    if let Some(r) = app.rects.bufferline_theme_toggle
        && crate::app::dispatch::contains(r, x, y)
    {
        // R7 vscode-mouse F1 2026-08-09 — enrich the theme menu with
        // a full theme list. Was: Pick theme… / Toggle / Reset — the
        // Pick opened a fuzzy picker overlay. That's one extra hop
        // when the user already knows which theme they want, and
        // Chrome's extension menu (the closest UI analog) lists
        // installed themes inline.
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let cur = crate::ui::theme::cur().name.to_string();
        let alt = app.config.ui.theme_toggle.clone();
        let mut items: Vec<MenuItem> = Vec::new();
        items.push(MenuItem::new(
            format!("Theme: {cur}"),
            MenuAction::Command("noop.info"),
        ));
        // The two "quick" actions stay at the top so muscle memory
        // survives — Toggle + Reset are the fastest common paths.
        items.push(MenuItem::new(
            match alt.as_deref() {
                Some(a) if !a.eq_ignore_ascii_case(&cur) => {
                    format!("Toggle → {a}")
                }
                Some(_) => "Toggle (primary ↔ alt)".to_string(),
                None => "Toggle (configure [ui] theme_toggle first)".to_string(),
            },
            MenuAction::Command("theme.toggle"),
        ));
        // #1023 (2026-08-18) — same command now enables tick-based
        // polling, so the menu label reflects the toggle state.
        if app.config.ui.theme_auto_system {
            items.push(MenuItem::new(
                "Auto: match system ● (stop syncing)",
                MenuAction::Command("theme.auto_system_off"),
            ));
        } else {
            items.push(MenuItem::new(
                "Auto: match system (light/dark)",
                MenuAction::Command("theme.auto_system"),
            ));
        }
        items.push(MenuItem::new(
            "Reset to config default",
            MenuAction::Command("theme.reset"),
        ));
        items.push(MenuItem::new(
            "Pick theme…  (fuzzy)",
            MenuAction::Command("theme.pick"),
        ));
        // Separator-style divider before the per-theme rows.
        items.push(MenuItem::new(
            "── themes ──".to_string(),
            MenuAction::Command("noop.info"),
        ));
        for name in crate::ui::theme::names() {
            let marker = if name.eq_ignore_ascii_case(&cur) {
                ""
            } else {
                " "
            };
            items.push(MenuItem::new(
                format!("{marker} {name}"),
                MenuAction::SetTheme(name.to_string()),
            ));
        }
        app.context_menu = Some(ContextMenu::new(Some("Theme".to_string()), (x, y), items));
        return;
    }
    // vscode-user-mouse 2026-07-30 SEV-3 #10 — right-click on menu-
    // bar words. Was dead; users expect a "customize menu bar" or
    // mode-toggle affordance given every other chip has right-click.
    // Minimal menu: cycle menu-bar mode (auto / always / hidden).
    if app
        .rects
        .menu_bar_words
        .iter()
        .any(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let cur = app.config.ui.menu_bar.as_str();
        let items = vec![
            MenuItem::new(format!("Menu bar: {cur}"), MenuAction::Command("noop.info")),
            MenuItem::new(
                "Cycle mode (auto → always → hidden)",
                MenuAction::Command("view.menu_bar_cycle"),
            ),
        ];
        app.context_menu = Some(ContextMenu::new(
            Some("Menu Bar".to_string()),
            (x, y),
            items,
        ));
        return;
    }
    // vscode-user-mouse 2026-07-30 SEV-3 #6 — right-click on the
    // `×` window-close chip. Left-click always fires quit-confirm;
    // right-click gives quick access to Save-all-and-quit / Force-
    // quit (no-save) without going through the dialog.
    if let Some(r) = app.rects.bufferline_window_close
        && crate::app::dispatch::contains(r, x, y)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let items = vec![
            MenuItem::new("Quit (with confirm)", MenuAction::Command("app.quit")),
            MenuItem::new("Save all", MenuAction::Command("file.save_all")),
            MenuItem::new("Restart", MenuAction::Command("app.restart")),
        ];
        app.context_menu = Some(ContextMenu::new(Some("mnml".to_string()), (x, y), items));
        return;
    }
    // Undo chip right-click — dismiss without committing. Left-click
    // commits; right-click cancels. mouse-round-10 SEV-3 2026-07-12.
    if let Some(r) = app.rects.pending_undo_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.pending_undo = None;
        app.toast("undo chip dismissed");
        return;
    }
    // Right-click on a toast body — offer a dismiss / dismiss-all
    // menu instead of falling through into the pane below.
    // mouse-round-10 SEV-2 2026-07-12.
    if let Some((idx, r)) = app
        .rects
        .toast_stack_rects
        .iter()
        .enumerate()
        .find(|(_, r)| crate::app::dispatch::contains(**r, x, y))
    {
        app.open_toast_context_menu(idx, (r.x, r.y));
        return;
    }
    if let Some(r) = app.rects.statusline_stress_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_stress_meter_context_menu((x, y));
        return;
    }
    // design-critic round-3 finding #6 batch 2 — remaining statusline
    // chips gain right-click menus.
    if let Some(r) = app.rects.statusline_diagnostics_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_statusline_diagnostics_context_menu((x, y));
        return;
    }
    if let Some(r) = app.rects.statusline_language_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_statusline_language_context_menu((x, y));
        return;
    }
    if let Some(r) = app.rects.statusline_lncol_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_statusline_lncol_context_menu((x, y));
        return;
    }
    if let Some(r) = app.rects.statusline_find_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_statusline_find_context_menu((x, y));
        return;
    }
    if let Some(r) = app.rects.statusline_sel_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_statusline_sel_context_menu((x, y));
        return;
    }
    if let Some(r) = app.rects.statusline_filesize_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_statusline_filesize_context_menu((x, y));
        return;
    }
    // #21 v2 — right-click coverage for the remaining statusline
    // chips (WRAP / LSP / Autosave / Test). Small menus that
    // surface the underlying palette commands so users can
    // discover config knobs without dropping to `:`.
    if let Some(r) = app.rects.statusline_wrap_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        // R9 vscode-mouse SEV-3 — the previous menu was a bare
        // one-item "Disable wrap" that hid the current state.
        // Now: title reveals state, single toggle row shows the
        // action that flips it, plus Settings jump for the
        // fold-arrows / per-buffer preferences a right-click user
        // would want next.
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let cur = app.config.ui.wrap;
        let title = format!("Wrap · {}", if cur { "on" } else { "off" });
        let toggle_label = if cur { "Disable wrap" } else { "Enable wrap" };
        let items = vec![
            MenuItem::new(toggle_label, MenuAction::Command("view.toggle_wrap")),
            MenuItem::new("Editor settings…", MenuAction::Command("view.settings")),
        ];
        app.context_menu = Some(ContextMenu::new(Some(title), (x, y), items));
        return;
    }
    // Autosave chip — no menu; the existing left-click already
    // toasts the current interval + how to change it. Adding a
    // right-click menu for "change interval" would just repeat
    // that toast (no dedicated command yet). Left-click is fine.
    if let Some(r) = app.rects.statusline_lsp_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        // mouse-round-8 SEV-3 2026-07-12 — was a single "Status" row
        // with a phantom empty row below. Now offers the LSP verbs a
        // user actually reaches for from the chip: symbols/references,
        // hover, code-actions, diagnostics, plus the raw status.
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let items = vec![
            MenuItem::new("Status", MenuAction::Command("LspStatus")),
            MenuItem::new("Symbols in file", MenuAction::Command("lsp.symbols")),
            MenuItem::new(
                "Symbols in workspace",
                MenuAction::Command("lsp.workspace_symbols"),
            ),
            MenuItem::new("Diagnostics list", MenuAction::Command("lsp.diagnostics")),
            MenuItem::new("Find references", MenuAction::Command("lsp.references")),
            MenuItem::new("Rename symbol", MenuAction::Command("lsp.rename")),
            MenuItem::new("Format file", MenuAction::Command("lsp.format")),
            MenuItem::new("Code actions", MenuAction::Command("lsp.code_action")),
            MenuItem::new(
                "Toggle inlay hints",
                MenuAction::Command("lsp.inlay_hints_toggle"),
            ),
        ];
        app.context_menu = Some(ContextMenu::new(Some("LSP".to_string()), (x, y), items));
        return;
    }
    if let Some(r) = app.rects.statusline_test_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let items = vec![
            MenuItem::new("Run all", MenuAction::Command("test.run_all")),
            MenuItem::new("Run file", MenuAction::Command("test.run_file")),
            MenuItem::new("Run at cursor", MenuAction::Command("test.run_at_cursor")),
        ];
        app.context_menu = Some(ContextMenu::new(Some("Tests".to_string()), (x, y), items));
        return;
    }
    if let Some(r) = app.rects.statusline_clock_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_statusline_clock_context_menu((x, y));
        return;
    }
    // Task #915 (R5 SEV-2 F3) — `+ dock` chip right-click. Left-click
    // on this chip fires `dock.new_text_br` (bottom-right text widget);
    // right-click used to fall through to the pane beneath, exposing
    // that pane's context menu instead of a dock-scoped one. Now
    // opens a small dock-add picker so mouse-first users can choose
    // the widget kind and corner without going through the palette.
    if let Some(r) = app.rects.dock_empty_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let items = vec![
            MenuItem::new(
                "Add text widget (bottom-right)",
                MenuAction::Command("dock.new_text_br"),
            ),
            MenuItem::new(
                "Add text widget (bottom-left)",
                MenuAction::Command("dock.new_text"),
            ),
            MenuItem::new(
                "Add text widget (top-right)",
                MenuAction::Command("dock.new_text_tr"),
            ),
            MenuItem::new(
                "Add text widget (top-left)",
                MenuAction::Command("dock.new_text_tl"),
            ),
            MenuItem::new("Add log tail", MenuAction::Command("dock.new_log_tail")),
        ];
        app.context_menu = Some(ContextMenu::new(Some("Dock".to_string()), (x, y), items));
        return;
    }
    // Task #915 (R5 SEV-2 F1) — AI Claude chip. Was silent on
    // right-click; menu now surfaces the same ai.* commands the
    // palette can invoke.
    if let Some(r) = app.rects.statusline_ai_claude_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_statusline_ai_context_menu((x, y), false);
        return;
    }
    // Task #915 (R5 SEV-2 F2) — AI Codex chip. Same menu.
    if let Some(r) = app.rects.statusline_ai_codex_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_statusline_ai_context_menu((x, y), true);
        return;
    }
    // Task #875 (R5 SEV-3 F8) — coverage chip right-click.
    if let Some(r) = app.rects.statusline_coverage_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_statusline_coverage_context_menu((x, y));
        return;
    }
    // #1102 (2026-08-20) — dynamic statusline segment (manifest-
    // declared / IPC-set). Walk `statusline_segment_hits` (already
    // in render order) and open the "Move left / Move right" menu
    // for whichever segment's rect contains (x, y).
    if let Some(idx) = app
        .rects
        .statusline_segment_hits
        .iter()
        .position(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        app.open_statusline_segment_context_menu(idx, (x, y));
        return;
    }
    // qa-6th mouse SEV-3 2026-06-29: mixr chip on the statusline
    // had a left-click action (mixr.show) but no right-click menu
    // and no hover tooltip — felt like a black box. Added a small
    // menu: open mixr in a pane, or copy the now-playing track.
    if let Some(r) = app.rects.statusline_mixr_chip
        && crate::app::dispatch::contains(r, x, y)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        // 2026-08-22 — menu shape:
        //   Row 1: Beatport auth status (● signed in / ○ not) —
        //           clicking toasts the same string, non-destructive.
        //   Row 2: Play a random chart (same as play-glyph click).
        //   Row 3: Open mixr (same as label click).
        //   Row 4: Copy track title (only when a track is playing).
        // The auto-play toggle from the previous menu was retired
        // once the chip split into [play] [label] — the play-glyph
        // IS the toggle-equivalent.
        let authed = crate::app::ai::mixr_beatport_authed();
        let favs = crate::app::ai::mixr_has_favorite_genres();
        let auth_label = match (authed, favs) {
            (true, true) => "● Beatport: signed in · favorites set",
            (true, false) => "● Beatport: signed in · no favorites",
            (false, _) => "○ Beatport: not signed in",
        };
        // 2026-08-22 — three-way preferred-app switcher rows. Radio-
        // style: `(●)` on the current pick, `( )` on the others. The
        // idle chip + play-glyph action follow this choice.
        let cur = app.config.ui.preferred_music_app.as_str();
        let mark = |v: &str| if cur == v { "(●)" } else { "( )" };
        let mut items = vec![
            MenuItem::new(auth_label, MenuAction::Command("mixr.show_auth_status")),
            MenuItem::new(
                format!("{} mixr (Beatport)", mark("mixr")),
                MenuAction::Command("mixr.set_preferred_mixr"),
            ),
            MenuItem::new(
                format!("{} Music", mark("music")),
                MenuAction::Command("mixr.set_preferred_music"),
            ),
            MenuItem::new(
                format!("{} Spotify", mark("spotify")),
                MenuAction::Command("mixr.set_preferred_spotify"),
            ),
            MenuItem::new("Play random chart", MenuAction::Command("mixr.play_now")),
            MenuItem::new("Open mixr", MenuAction::Command("mixr.show")),
        ];
        if let Some(np) = app.now_playing.as_ref()
            && !np.track.is_empty()
        {
            items.push(MenuItem::new(
                "Copy track title",
                MenuAction::Command("mixr.copy_track"),
            ));
        }
        app.context_menu = Some(ContextMenu::new(Some("mixr".to_string()), (x, y), items));
        return;
    }
    // Right-click on the `> WORKSPACE` header → workspace menu.
    if let Some(tr) = app.rects.tree_toggle
        && crate::app::dispatch::contains(tr, x, y)
    {
        app.open_workspace_header_context_menu((x, y));
        return;
    }
    // 2026-07-31 — Right-click on a detail-pane link row → copy the
    // URL. Runs before the activity-panel chip check because a
    // click can land on both when the detail pane covers the
    // integration-panel area (right-panel host).
    if let Some((_, pane_id, url)) = app
        .rects
        .integration_detail_links
        .iter()
        .find(|(r, _, _)| crate::app::dispatch::contains(*r, x, y))
        .map(|(r, pid, url)| (*r, *pid, url.clone()))
    {
        crate::ui::integration_detail_view::copy_link_url(app, pane_id, url);
        return;
    }
    // Right-click on an integration chip → Edit / Remove
    // quick-actions. Lets a user tweak a chip without
    // going through the discovery overlay first.
    if let Some(&(_, icon_idx)) = app
        .rects
        .integration_icon_rects
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        app.open_integration_chip_context_menu(icon_idx, (x, y));
        return;
    }
    // 2026-08-07 vscode-mouse r1 F2 — marketplace rows were the only
    // clickable list surface with a dead right-click. Simple menu
    // gives parity with other lists + saves the trip to the detail
    // pane for common quick-lookups.
    if let Some(&(_, entry_idx)) = app
        .rects
        .marketplace_row_rects
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let entry = app.marketplace_entries.get(entry_idx).cloned();
        let items = if let Some(e) = entry {
            let is_installed = app.config.ui.integration_icons.iter().any(|i| i.id == e.id);
            let _ = &e;
            // 2026-08-07 design-critic r2 #3: lead with the state-
            // changing action (Install) when it's meaningful, matching
            // integration-chip menu convention. View details demoted
            // to second — it's a pure duplicate of left-click.
            let mut items: Vec<MenuItem> = Vec::new();
            if !is_installed {
                items.push(MenuItem::new(
                    "Install",
                    MenuAction::Command("marketplace.install_focused"),
                ));
            }
            items.push(MenuItem::new(
                "View details",
                MenuAction::Command("marketplace.open_detail_focused"),
            ));
            items.push(MenuItem::new(
                "Copy id",
                MenuAction::Command("marketplace.copy_id_focused"),
            ));
            items
        } else {
            vec![MenuItem::new(
                "View details",
                MenuAction::Command("marketplace.open_detail_focused"),
            )]
        };
        // Focus the row so the "focused" commands know which entry.
        app.pending_marketplace_install_idx = Some(entry_idx);
        app.context_menu = Some(ContextMenu::new(
            Some("Marketplace entry".into()),
            (x, y),
            items,
        ));
        return;
    }
    // 2026-08-01 (P2) — launcher-chip right-click routing deleted
    // with the LauncherIcon retirement. Integration chip menu covers
    // the surface.
    // Right-click on the TABS label → cluster mode chooser
    // (Expanded / Compact / Auto).
    if let Some(r) = app.rects.bufferline_tabs_label
        && crate::app::dispatch::contains(r, x, y)
    {
        app.open_top_bar_cluster_context_menu((x, y));
        return;
    }
    // mouse-round-16 F3 2026-07-17 — split-strip `[│]` / `[─]`
    // / `[$]` chips got no right-click menu. Left-click already
    // fires the primary action (H/V split; open shell) so this
    // is discoverability + orientation-choice for the split
    // arrows. Terminal chip gets Open shell / Open shell in split.
    if let Some(&(_, leaf_active, dir)) = app
        .rects
        .split_strip_buttons
        .iter()
        .find(|(r, _, _)| crate::app::dispatch::contains(*r, x, y))
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        if let Some(la) = leaf_active {
            app.active = Some(la);
        }
        let (title, items) = match dir {
            crate::layout::SplitDir::Horizontal => (
                "Split horizontal",
                vec![
                    MenuItem::new("Split right", MenuAction::Command("view.split_right")),
                    MenuItem::new(
                        "Equalize splits",
                        MenuAction::Command("view.equalize_splits"),
                    ),
                    MenuItem::new("Grow width", MenuAction::Command("view.split_grow_width")),
                    MenuItem::new(
                        "Shrink width",
                        MenuAction::Command("view.split_shrink_width"),
                    ),
                    MenuItem::new("Close active pane", MenuAction::Command("buffer.close")),
                ],
            ),
            crate::layout::SplitDir::Vertical => (
                "Split vertical",
                vec![
                    MenuItem::new("Split down", MenuAction::Command("view.split_down")),
                    MenuItem::new(
                        "Equalize splits",
                        MenuAction::Command("view.equalize_splits"),
                    ),
                    MenuItem::new("Grow height", MenuAction::Command("view.split_grow_height")),
                    MenuItem::new(
                        "Shrink height",
                        MenuAction::Command("view.split_shrink_height"),
                    ),
                    MenuItem::new("Close active pane", MenuAction::Command("buffer.close")),
                ],
            ),
        };
        app.context_menu = Some(ContextMenu::new(Some(title.into()), (x, y), items));
        return;
    }
    if let Some(&(_, leaf_active)) = app
        .rects
        .split_strip_term_buttons
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        if let Some(la) = leaf_active {
            app.active = Some(la);
        }
        // 2026-07-22 — match the AI-chip menu shape. Was: 2-item menu
        // (Open shell / Open scratch). User: "the terminal icon when
        // right clicked should allow more placement options."
        let items = vec![
            MenuItem::new("Open shell (beside)", MenuAction::Command("term.shell")),
            MenuItem::new(
                "Open shell in left half",
                MenuAction::Command("term.shell_left"),
            ),
            MenuItem::new(
                "Open shell in right half",
                MenuAction::Command("term.shell_right"),
            ),
            MenuItem::new(
                "Open shell in top half",
                MenuAction::Command("term.shell_top"),
            ),
            MenuItem::new(
                "Open shell in bottom half",
                MenuAction::Command("term.shell_bottom"),
            ),
            MenuItem::new(
                "Open scratch terminal",
                MenuAction::Command("term.scratch_toggle"),
            ),
        ];
        app.context_menu = Some(ContextMenu::new(Some("Terminal".into()), (x, y), items));
        return;
    }
    // Right-click on the split-strip AI button → choose
    // between Claude / Codex without changing the configured
    // default. Tab-strip Term + Split buttons are single-
    // action so they don't need menus.
    if let Some(&(_, leaf_active, tag)) = app
        .rects
        .split_strip_ai_buttons
        .iter()
        .find(|(r, _, _)| crate::app::dispatch::contains(*r, x, y))
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        if let Some(la) = leaf_active {
            app.active = Some(la);
        }
        // `tag == 1` = Codex chip; anything else (`0`) = Claude Code
        // — matches the down_left click routing.
        let is_codex = tag == 1;
        let (kind_label, new_cmd, toggle_cmd, left_cmd, right_cmd, top_cmd, bottom_cmd) =
            if is_codex {
                (
                    "Codex",
                    "ai.codex_new",
                    "ai.codex",
                    "ai.codex_new_left",
                    "ai.codex_new_right",
                    "ai.codex_new_top",
                    "ai.codex_new_bottom",
                )
            } else {
                (
                    "Claude Code",
                    "ai.claude_code_new",
                    "ai.claude_code",
                    "ai.claude_code_new_left",
                    "ai.claude_code_new_right",
                    "ai.claude_code_new_top",
                    "ai.claude_code_new_bottom",
                )
            };
        // design-critic 2026-07-09: the previous menu had two
        // items that ran the same code path — "Open new session
        // (right dock)" and "Place new session in right half"
        // both split horizontally and put the new pane on the
        // second (right) side. Dropped the parenthetical and
        // kept the four half-placement items so the six-item
        // menu now maps to five distinct outcomes: toggle
        // existing + place in {left, right, top, bottom}.
        // 2026-07-13 user requests — visibility toggles + glyph
        // edit access straight from the chip's own menu (was
        // config-only). Codepoint for the glyph builder is the
        // PUA slot each AI kind uses (F8B0 / F8B1); the builder
        // lets users nudge width/height/center to fix baseline
        // drift against integration codicons.
        // 2026-08-07 — dropped the `Show Claude only / Show Codex
        // only / Show both / Hide these icons` submenu. AI chip
        // visibility is now controlled per-chip through the
        // Integrations panel (right-click a chip → Enable/Disable,
        // persisted to ~/.config/mnml/integrations/<id>.toml). The
        // old `tab_bar_ai_icon` config knob is retained only for
        // backward-compat with older configs — new state should
        // never write it. `mark(...)` closure removed with the
        // items that used it.
        // 2026-07-19 — chip renderer moved from JBM-NF-patched
        // F8B0/F8B1 to mnml-owned F1E00/F1E01 in MnmlSymbols.ttf.
        // Point the glyph builder at the new codepoints so
        // "Edit glyph…" actually tunes what the chip renders.
        let glyph_cp: u32 = if is_codex { 0xF1E01 } else { 0xF1E00 };
        // Layout mode toggle — `[ui] ai_layout_mode` chooses
        // whether a new AI session grows the grid (auto-tile
        // splits, capped at 8) or just appends a tab to the
        // active leaf (single big pane, N tabs). 2026-07-19.
        let layout_mode = app.config.ui.ai_layout_mode.clone();
        let layout_mark = |val: &str| if layout_mode == val { "" } else { "  " };
        let items = vec![
            MenuItem::new(
                format!("Toggle existing {kind_label} pane"),
                MenuAction::Command(toggle_cmd),
            ),
            MenuItem::new(
                format!("New {kind_label} session in left half"),
                MenuAction::Command(left_cmd),
            ),
            MenuItem::new(
                format!("New {kind_label} session in right half"),
                MenuAction::Command(right_cmd),
            ),
            MenuItem::new(
                format!("New {kind_label} session in top half"),
                MenuAction::Command(top_cmd),
            ),
            MenuItem::new(
                format!("New {kind_label} session in bottom half"),
                MenuAction::Command(bottom_cmd),
            ),
            // Layout mode toggle.
            MenuItem::new(
                format!("{}Layout: Grid (splits)", layout_mark("grid")),
                MenuAction::Command("view.ai_layout_grid"),
            ),
            MenuItem::new(
                format!("{}Layout: Tabs (stack in leaf)", layout_mark("tabs")),
                MenuAction::Command("view.ai_layout_tabs"),
            ),
            // Font glyph controls (2026-07-19). "Bake" installs the
            // AI chip glyphs into MnmlSymbols.ttf using the defaults
            // in `BUILTIN_GLYPHS`; "Edit" opens the glyph builder
            // for iterative center_frac tuning. "Use mnml AI glyphs"
            // flips the chip renderer from the JBM-NF-patched pair
            // to the mnml-baked F1E00/F1E01 pair — only enable
            // after baking, or the chip renders as tofu.
            MenuItem::new(
                "Bake AI glyphs into MnmlSymbols",
                MenuAction::Command("integrations.bake_ai_glyphs"),
            ),
            MenuItem::new(
                {
                    let mark = if app.config.ui.ai_chip_use_mnml_glyphs {
                        ""
                    } else {
                        "  "
                    };
                    format!("{mark}Use mnml AI glyphs (baked)")
                },
                MenuAction::Command("view.ai_chip_toggle_font"),
            ),
            MenuItem::new(
                format!("Edit {kind_label} glyph… (center)"),
                MenuAction::OpenGlyphBuilderForCp(glyph_cp),
            ),
        ];
        // Suppress the unused vars from the earlier item set —
        // kept the local for the toggle path above.
        let _ = new_cmd;
        app.context_menu = Some(ContextMenu::new(
            Some(format!("{kind_label} launcher")),
            (x, y),
            items,
        ));
        return;
    }
    // Right-click on the rail INTEGRATIONS section header.
    // Quick add-integration + collapse — other rail headers
    // (Workspace, Git) have context menus; integrations was
    // the lone exception.
    if let Some(r) = app.rects.integration_section_toggle
        && crate::app::dispatch::contains(r, x, y)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let items = vec![MenuItem::new(
            if app.integration_section_expanded {
                "Collapse section"
            } else {
                "Expand section"
            },
            MenuAction::Command("view.toggle_integrations_section"),
        )];
        app.context_menu = Some(ContextMenu::new(
            Some("integrations".to_string()),
            (x, y),
            items,
        ));
        return;
    }
    // Right-click on an extra-workspace header → that workspace's menu.
    if let Some(&(_, ws_idx)) = app
        .rects
        .extra_workspace_toggles
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        app.open_extra_workspace_header_context_menu(ws_idx, (x, y));
        return;
    }
    // Right-click on a Request pane URL/Method/Headers/Body row →
    // copy-as-curl / send / toggle view.
    if let Some(&(_, pid, field)) = app
        .rects
        .request_fields
        .iter()
        .find(|(r, _, _)| crate::app::dispatch::contains(*r, x, y))
    {
        app.active = Some(pid);
        app.focus_pane();
        // 2026-07-22 fix: also set `rp.focus` to the right-clicked
        // field. The Copy/Paste/Cut/Select-all menu items read
        // `rp.focus` — without this update they'd operate on
        // whichever field was previously focused via Tab/click,
        // silently producing wrong-field output that looked like
        // "the menu items are no-ops" from the user's perspective.
        if let Some(Pane::Request(rp)) = app.panes.get_mut(pid) {
            rp.focus = field;
        }
        app.open_request_field_context_menu(field, (x, y));
        return;
    }
    // Right-click anywhere inside an AI pane → re-ask / cancel /
    // promote menu.
    if let Some(cur) = app.active
        && matches!(app.panes.get(cur), Some(Pane::Ai(_)))
    {
        app.open_ai_pane_context_menu((x, y));
        return;
    }
    // Right-click on a pty pane (terminal / Claude / Codex) →
    // dock-position menu (left / right / top / bottom / maximize /
    // zen). Pty panes register their rect in `editor_panes`.
    if let Some(&(_, pid)) = app.rects.editor_panes.iter().find(|(r, pid)| {
        crate::app::dispatch::contains(*r, x, y)
            && matches!(app.panes.get(*pid), Some(Pane::Pty(_)))
    }) {
        app.open_pty_dock_context_menu(pid, (x, y));
        return;
    }
    // Right-click on an editor gutter → per-line menu.
    if let Some(&(gr, pid)) = app
        .rects
        .editor_gutters
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        let row_in_pane = (y - gr.y) as usize;
        let line = match app.panes.get(pid) {
            Some(Pane::Editor(b)) => b.scroll + row_in_pane,
            _ => row_in_pane,
        };
        app.open_editor_gutter_context_menu(pid, line as u32, (x, y));
        return;
    }
    // Right-click on a fold arrow (visible `▾` on hover or `▸` when
    // folded) → seek cursor to that line and open the editor body
    // menu with Toggle Fold at the ready. vscode-user-mouse round 2
    // SEV-3 2026-07-11 — was routing to the editor line menu which
    // still has Toggle Fold but buried under 10+ items.
    if let Some(&(_, pid, line_no)) = app
        .rects
        .fold_arrows
        .iter()
        .find(|(r, _, _)| crate::app::dispatch::contains(*r, x, y))
    {
        app.active = Some(pid);
        app.focus_pane();
        if let Some(Pane::Editor(b)) = app.panes.get_mut(pid) {
            b.editor.place_cursor(line_no, 0);
        }
        app.open_editor_body_context_menu(pid, line_no, 0, (x, y));
        return;
    }
    // Right-click on the editor BODY → text-scoped menu.
    if let Some(&(tr, pid)) = app
        .rects
        .editor_panes
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        let wrap = app.config.ui.wrap;
        if let Some(Pane::Editor(b)) = app.panes.get(pid) {
            let (row, col) = crate::app::dispatch::click_to_file_pos(b, tr, wrap, x, y);
            app.open_editor_body_context_menu(pid, row, col, (x, y));
            return;
        }
    }
    // Right-click a pty pane's tab strip (Claude / Codex / shell) →
    // rename / close that session.
    if let Some(&(_, pid)) = app
        .rects
        .pty_tabs
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        app.open_pty_tab_context_menu(pid, (x, y));
        return;
    }
    // Right-click → a context menu on the bufferline tab / tree row under it.
    if let Some(&(_, id)) = app
        .rects
        .bufferline_tabs
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        app.open_tab_context_menu(id, (x, y));
        return;
    }
    // 2026-06-22 — per-split tab chips also get a right-click context menu.
    if let Some(&(_, _, tab_pane)) = app
        .rects
        .split_tab_chips
        .iter()
        .find(|(r, _, _)| crate::app::dispatch::contains(*r, x, y))
    {
        app.open_tab_context_menu(tab_pane, (x, y));
        return;
    }
    // mouse-round-11 SEV-2 2026-07-12 — right-click on an
    // HTTP-panel section header (COLLECTIONS / FILES / ENVS /
    // CHAINS / MOCKS / RECENT / CAPTURED). Section-level verbs.
    if let Some(&(_, section)) = app
        .rects
        .http_panel_section_headers
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        app.open_http_panel_section_context_menu(section, (x, y));
        return;
    }
    // mouse-round-11 SEV-3 2026-07-12 — right-click on the tree's
    // `..` up-nav row → workspace-navigation menu (up one, project
    // root, copy current path, open externally). Left-click still
    // navigates up one level.
    if let Some(r) = app.rects.tree_up_row
        && crate::app::dispatch::contains(r, x, y)
    {
        use crate::context_menu::{ContextMenu, MenuAction, MenuItem};
        let cur = app.workspace.display().to_string();
        let items = vec![
            MenuItem::new(
                "Navigate up one level",
                MenuAction::Command("view.workspace_up"),
            ),
            MenuItem::new("Copy current path", MenuAction::CopyPath(cur.clone())),
            MenuItem::new(
                crate::app::reveal_in_files_label(),
                MenuAction::RevealInFinder(app.workspace.clone()),
            ),
            MenuItem::new(
                "Open in terminal here",
                MenuAction::OpenTerminal(app.workspace.clone()),
            ),
        ];
        app.context_menu = Some(ContextMenu::new(
            Some("Workspace".to_string()),
            (x, y),
            items,
        ));
        return;
    }
    if let Some(tr) = app.rects.tree
        && crate::app::dispatch::contains(tr, x, y)
    {
        let idx = (y - tr.y) as usize + app.rects.tree_scroll;
        if idx < app.tree.visible_rows().len() {
            app.tree.set_cursor(idx);
            app.focus_tree();
            if let Some(row) = app.tree.selected_row() {
                app.open_tree_context_menu(row.path.clone(), row.is_dir, (x, y));
            }
        } else {
            // mouse-round-16 F5 2026-07-17 — right-click on the
            // empty tree space below the last file was a dead
            // zone. Match VS Code's Explorer empty-space menu:
            // create-at-root verbs + refresh. Uses the workspace-
            // root context menu which already covers these verbs
            // (New file / New folder / Cut/Copy/Paste / Refresh).
            app.focus_tree();
            app.open_workspace_header_context_menu((x, y));
        }
        return;
    }
    // Right-click on an EXTRA workspace's file rows — was primary-only
    // until now, which read as broken (the primary tree ate the whole
    // right-click "space" but any secondary repo's rows had no menu).
    if let Some(&(tr, ws_idx, scroll)) = app
        .rects
        .extra_workspace_bodies
        .iter()
        .find(|(r, _, _)| crate::app::dispatch::contains(*r, x, y))
    {
        let row_idx = (y - tr.y) as usize + scroll;
        app.open_extra_workspace_tree_row_context_menu(ws_idx, row_idx, (x, y));
        return;
    }
    // Right-click on a GIT-section row → per-row context menu.
    if let Some(&(_, hit)) = app
        .rects
        .git_rail_rows
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        app.open_git_rail_context_menu(hit, (x, y));
        return;
    }
    // Right-click on a git-palette row.
    if let Some(&(_, hit)) = app
        .rects
        .git_palette_rows
        .iter()
        .find(|(r, _)| crate::app::dispatch::contains(*r, x, y))
    {
        match hit {
            crate::ui::git_palette::GitPaletteHit::Branch(i) => {
                app.open_git_rail_context_menu(crate::git::rail::GitRailHit::Branch(i), (x, y));
            }
            crate::ui::git_palette::GitPaletteHit::Worktree(i) => {
                app.open_git_rail_context_menu(crate::git::rail::GitRailHit::Worktree(i), (x, y));
            }
            crate::ui::git_palette::GitPaletteHit::Pull(i) => {
                app.open_git_rail_context_menu(crate::git::rail::GitRailHit::Pull(i), (x, y));
            }
            crate::ui::git_palette::GitPaletteHit::Stash(i) => {
                app.open_git_palette_stash_context_menu(i, (x, y));
            }
            crate::ui::git_palette::GitPaletteHit::Tag(i) => {
                app.open_git_palette_tag_context_menu(i, (x, y));
            }
            crate::ui::git_palette::GitPaletteHit::RemoteBranch(i) => {
                app.open_git_palette_remote_branch_context_menu(i, (x, y));
            }
        }
        return;
    }
    // Right-click on a Diff / GitStatus list-row.
    if let Some(&(_, pid, idx)) = app
        .rects
        .list_rows
        .iter()
        .find(|(r, _, _)| crate::app::dispatch::contains(*r, x, y))
    {
        match app.panes.get(pid) {
            Some(Pane::Diff(_)) => {
                app.active = Some(pid);
                app.focus_pane();
                app.open_diff_context_menu(pid, idx, (x, y));
            }
            Some(Pane::GitGraph(g)) if g.embedded_diff.is_some() => {
                app.active = Some(pid);
                app.focus_pane();
                app.open_diff_context_menu(pid, idx, (x, y));
            }
            Some(Pane::GitStatus(_)) => {
                app.active = Some(pid);
                app.focus_pane();
                app.open_git_status_context_menu(pid, idx, (x, y));
            }
            _ => {}
        }
    }
}