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
|
use bytes::Bytes;
use crossterm::event::KeyCode;
use tracing::{debug, warn};
use crate::{
app::{App, Mode},
input::TerminalKey,
};
struct PreparedPaneInput {
ws_idx: usize,
pane_id: crate::layout::PaneId,
bytes: Bytes,
}
fn is_modifier_only_key(code: &KeyCode) -> bool {
matches!(code, KeyCode::Modifier(_))
}
impl App {
pub(crate) fn handle_terminal_key_headless(&mut self, key: TerminalKey) {
let Some(input) = self.prepare_terminal_key_forward(key) else {
return;
};
if let Some(runtime) = self.lookup_runtime_sender(input.ws_idx, input.pane_id) {
let _ = runtime.try_send_bytes(input.bytes);
}
}
fn prepare_terminal_key_forward(&mut self, key: TerminalKey) -> Option<PreparedPaneInput> {
self.state.clear_selection();
self.selection_autoscroll_deadline = None;
self.state.update_dismissed = true;
let key_event = key.as_key_event();
if let Some(action) = super::terminal_direct_navigation_action(&self.state, &key_event) {
debug!(
code = ?key_event.code,
modifiers = ?key_event.modifiers,
kind = ?key_event.kind,
action = ?action,
"intercepted terminal direct navigation key before forwarding to pane"
);
super::navigate::execute_navigate_action(&mut self.state, action);
return None;
}
if self.state.is_prefix(&key_event) {
self.state.mobile_switcher_scroll = 0;
self.state.mode = Mode::Navigate;
return None;
}
if is_modifier_only_key(&key_event.code) {
debug!(
code = ?key_event.code,
modifiers = ?key_event.modifiers,
kind = ?key_event.kind,
"dropping modifier-only terminal key event instead of forwarding it to pane"
);
return None;
}
let ws_idx = self.state.active?;
let ws = self.state.workspaces.get(ws_idx)?;
let pane_id = ws.focused_pane_id()?;
let rt = self.state.runtime_for_pane_in_workspace(ws_idx, pane_id)?;
// Intercept plain PageUp/PageDown presses for pane scrollback when the
// focused pane doesn't handle its own scrolling (e.g., a plain shell
// with mouse off). Modified page keys are pane shortcuts, and release
// events should not produce a second host-scroll action.
// Only intercept when we know the pane state; if input_state is unknown,
// fail-open and forward the key to the pane.
if matches!(key_event.code, KeyCode::PageUp | KeyCode::PageDown)
&& key_event.modifiers.is_empty()
{
if let Some(input_state) = rt.input_state() {
if !input_state.alternate_screen && !input_state.mouse_reporting_enabled() {
if key_event.kind == crossterm::event::KeyEventKind::Release {
return None;
}
if matches!(
key_event.kind,
crossterm::event::KeyEventKind::Press
| crossterm::event::KeyEventKind::Repeat
) {
let lines = self
.state
.pane_info_by_id(pane_id)
.map(|info| info.inner_rect.height as usize)
.unwrap_or(10)
.max(1);
if key_event.code == KeyCode::PageUp {
self.state.scroll_pane_up(pane_id, lines);
} else {
self.state.scroll_pane_down(pane_id, lines);
}
debug!(
code = ?key_event.code,
lines,
"intercepted page key for pane scrollback"
);
return None;
}
}
}
}
rt.scroll_reset();
let protocol = rt.keyboard_protocol();
let bytes = rt.encode_terminal_key(key);
if matches!(key_event.code, KeyCode::Esc)
|| key_event
.modifiers
.contains(crossterm::event::KeyModifiers::ALT)
{
debug!(
code = ?key_event.code,
modifiers = ?key_event.modifiers,
kind = ?key_event.kind,
protocol = ?protocol,
encoded = ?bytes,
"forwarding potentially-ambiguous terminal key to pane"
);
}
if bytes.is_empty() {
if key.kind != crossterm::event::KeyEventKind::Release
&& !matches!(
key.code,
KeyCode::CapsLock
| KeyCode::ScrollLock
| KeyCode::NumLock
| KeyCode::PrintScreen
| KeyCode::Pause
| KeyCode::Menu
| KeyCode::KeypadBegin
| KeyCode::Media(_)
| KeyCode::Modifier(_)
)
{
warn!(code = ?key_event.code, mods = ?key_event.modifiers, state = ?key_event.state, "key produced empty encoding");
}
return None;
}
Some(PreparedPaneInput {
ws_idx,
pane_id,
bytes: Bytes::from(bytes),
})
}
pub(super) async fn handle_terminal_key(&mut self, key: TerminalKey) {
let Some(input) = self.prepare_terminal_key_forward(key) else {
return;
};
if let Some(runtime) = self.lookup_runtime_sender(input.ws_idx, input.pane_id) {
let _ = runtime.send_bytes(input.bytes).await;
}
}
}
#[cfg(test)]
mod tests {
use crossterm::event::{KeyCode, KeyEventKind, KeyModifiers, MouseButton, MouseEventKind};
use ratatui::layout::Rect;
use super::super::{app_for_mouse_test, mouse, numbered_lines_bytes};
use super::*;
use crate::{config::Config, workspace::Workspace};
#[tokio::test]
async fn dragging_selection_above_pane_autoscrolls_and_extends_into_scrollback() {
let mut app = app_for_mouse_test();
let mut ws = Workspace::test_new("test");
let pane_id = ws.tabs[0].root_pane;
let pane_infos = ws.tabs[0].layout.panes(Rect::new(26, 2, 80, 18));
let info = pane_infos[0].clone();
ws.insert_test_runtime(
pane_id,
crate::terminal::TerminalRuntime::test_with_scrollback_bytes(
info.inner_rect.width,
info.inner_rect.height,
16 * 1024,
&numbered_lines_bytes(64),
),
);
app.state.workspaces = vec![ws];
app.state.active = Some(0);
app.state.selected = 0;
app.state.mode = Mode::Terminal;
app.state.view.pane_infos = pane_infos;
let start_metrics = app
.state
.runtime_for_pane(pane_id)
.and_then(crate::terminal::TerminalRuntime::scroll_metrics)
.expect("initial scroll metrics");
let start_row = info.inner_rect.y;
let start_col = info.inner_rect.x + 2;
app.handle_mouse(mouse(
MouseEventKind::Down(MouseButton::Left),
start_col,
start_row,
));
app.handle_mouse(mouse(
MouseEventKind::Drag(MouseButton::Left),
start_col,
info.inner_rect.y.saturating_sub(1),
));
let end_metrics = app
.state
.runtime_for_pane(pane_id)
.and_then(crate::terminal::TerminalRuntime::scroll_metrics)
.expect("scroll metrics after drag");
assert_eq!(
end_metrics.offset_from_bottom,
start_metrics.offset_from_bottom + 3
);
let selection = app.state.selection.as_ref().expect("selection after drag");
assert!(selection.is_visible());
assert_eq!(
selection.ordered_cells(),
(
(
(start_metrics.max_offset_from_bottom - end_metrics.offset_from_bottom) as u32,
2,
),
(start_metrics.max_offset_from_bottom as u32, 2),
)
);
}
#[tokio::test]
async fn releasing_dragged_selection_clears_highlight_after_copy() {
let mut app = app_for_mouse_test();
let mut ws = Workspace::test_new("test");
let pane_id = ws.tabs[0].root_pane;
let pane_infos = ws.tabs[0].layout.panes(Rect::new(26, 2, 80, 18));
let info = pane_infos[0].clone();
ws.insert_test_runtime(
pane_id,
crate::terminal::TerminalRuntime::test_with_scrollback_bytes(
info.inner_rect.width,
info.inner_rect.height,
16 * 1024,
&numbered_lines_bytes(64),
),
);
app.state.workspaces = vec![ws];
app.state.active = Some(0);
app.state.selected = 0;
app.state.mode = Mode::Terminal;
app.state.view.pane_infos = pane_infos;
let row = info.inner_rect.y;
let start_col = info.inner_rect.x + 1;
let end_col = info.inner_rect.x + 4;
app.handle_mouse(mouse(
MouseEventKind::Down(MouseButton::Left),
start_col,
row,
));
app.handle_mouse(mouse(MouseEventKind::Drag(MouseButton::Left), end_col, row));
assert!(app.state.selection.is_some());
app.handle_mouse(mouse(MouseEventKind::Up(MouseButton::Left), end_col, row));
assert!(app.state.selection.is_none());
}
#[tokio::test]
async fn wheel_scroll_keeps_in_progress_selection_and_extends_it() {
let mut app = app_for_mouse_test();
let mut ws = Workspace::test_new("test");
let pane_id = ws.tabs[0].root_pane;
let pane_infos = ws.tabs[0].layout.panes(Rect::new(26, 2, 80, 18));
let info = pane_infos[0].clone();
ws.insert_test_runtime(
pane_id,
crate::terminal::TerminalRuntime::test_with_scrollback_bytes(
info.inner_rect.width,
info.inner_rect.height,
16 * 1024,
&numbered_lines_bytes(64),
),
);
app.state.workspaces = vec![ws];
app.state.active = Some(0);
app.state.selected = 0;
app.state.mode = Mode::Terminal;
app.state.view.pane_infos = pane_infos;
let start_metrics = app
.state
.runtime_for_pane(pane_id)
.and_then(crate::terminal::TerminalRuntime::scroll_metrics)
.expect("initial scroll metrics");
let top_row = info.inner_rect.y;
let col = info.inner_rect.x + 2;
app.handle_mouse(mouse(MouseEventKind::Down(MouseButton::Left), col, top_row));
app.handle_mouse(mouse(MouseEventKind::ScrollUp, col, top_row));
let end_metrics = app
.state
.runtime_for_pane(pane_id)
.and_then(crate::terminal::TerminalRuntime::scroll_metrics)
.expect("scroll metrics after wheel");
assert_eq!(
end_metrics.offset_from_bottom,
start_metrics.offset_from_bottom + 3
);
let selection = app.state.selection.as_ref().expect("selection after wheel");
assert!(selection.is_visible());
assert_eq!(
selection.ordered_cells(),
(
(
(start_metrics.max_offset_from_bottom - end_metrics.offset_from_bottom) as u32,
2,
),
(start_metrics.max_offset_from_bottom as u32, 2),
)
);
}
#[tokio::test]
async fn clicking_unfocused_pane_with_mouse_reporting_focuses_it_via_left_button() {
let mut app = app_for_mouse_test();
let mut ws = Workspace::test_new("test");
let first_pane = ws.tabs[0].root_pane;
let second_pane = ws.test_split(ratatui::layout::Direction::Vertical);
let terminal_area = Rect::new(26, 2, 80, 18);
let pane_infos = ws.tabs[0].layout.panes(terminal_area);
let first_info = pane_infos
.iter()
.find(|p| p.id == first_pane)
.unwrap()
.clone();
let second_info = pane_infos
.iter()
.find(|p| p.id == second_pane)
.unwrap()
.clone();
ws.insert_test_runtime(
first_pane,
crate::terminal::TerminalRuntime::test_with_screen_bytes(
first_info.inner_rect.width.max(1),
first_info.inner_rect.height.max(1),
b"",
),
);
ws.insert_test_runtime(
second_pane,
crate::terminal::TerminalRuntime::test_with_screen_bytes(
second_info.inner_rect.width.max(1),
second_info.inner_rect.height.max(1),
b"\x1b[?1002h",
),
);
ws.tabs[0].layout.focus_pane(first_pane);
app.state.workspaces = vec![ws];
app.state.active = Some(0);
app.state.selected = 0;
app.state.mode = Mode::Terminal;
app.state.view.pane_infos = pane_infos;
app.handle_mouse(mouse(
MouseEventKind::Down(MouseButton::Left),
second_info.inner_rect.x + 2,
second_info.inner_rect.y + 2,
));
assert_eq!(
app.state.workspaces[0].tabs[0].layout.focused(),
second_pane
);
assert_eq!(app.state.mode, Mode::Terminal);
}
#[tokio::test]
async fn clicking_unfocused_pane_with_mouse_reporting_focuses_it_via_right_button() {
let mut app = app_for_mouse_test();
let mut ws = Workspace::test_new("test");
let first_pane = ws.tabs[0].root_pane;
let second_pane = ws.test_split(ratatui::layout::Direction::Vertical);
let terminal_area = Rect::new(26, 2, 80, 18);
let pane_infos = ws.tabs[0].layout.panes(terminal_area);
let first_info = pane_infos
.iter()
.find(|p| p.id == first_pane)
.unwrap()
.clone();
let second_info = pane_infos
.iter()
.find(|p| p.id == second_pane)
.unwrap()
.clone();
ws.insert_test_runtime(
first_pane,
crate::terminal::TerminalRuntime::test_with_screen_bytes(
first_info.inner_rect.width.max(1),
first_info.inner_rect.height.max(1),
b"",
),
);
ws.insert_test_runtime(
second_pane,
crate::terminal::TerminalRuntime::test_with_screen_bytes(
second_info.inner_rect.width.max(1),
second_info.inner_rect.height.max(1),
b"\x1b[?1002h",
),
);
ws.tabs[0].layout.focus_pane(first_pane);
app.state.workspaces = vec![ws];
app.state.active = Some(0);
app.state.selected = 0;
app.state.mode = Mode::Terminal;
app.state.view.pane_infos = pane_infos;
app.handle_mouse(mouse(
MouseEventKind::Down(MouseButton::Right),
second_info.inner_rect.x + 2,
second_info.inner_rect.y + 2,
));
assert_eq!(
app.state.workspaces[0].tabs[0].layout.focused(),
second_pane
);
assert_eq!(app.state.mode, Mode::ContextMenu);
assert!(app.state.context_menu.is_some());
}
#[tokio::test]
async fn terminal_direct_focus_pane_shortcut_switches_focus_without_leaving_terminal_mode() {
let (_api_tx, api_rx) = tokio::sync::mpsc::unbounded_channel();
let mut app = App::new(
&Config::default(),
true,
None,
api_rx,
crate::api::EventHub::default(),
);
app.state.workspaces = vec![Workspace::test_new("test")];
app.state.active = Some(0);
app.state.selected = 0;
app.state.mode = Mode::Terminal;
app.state.workspaces[0].test_split(ratatui::layout::Direction::Horizontal);
app.state.view.pane_infos = app.state.workspaces[0]
.active_tab()
.unwrap()
.layout
.panes(Rect::new(0, 0, 80, 24));
let focused_before = app.state.workspaces[0].layout.focused();
app.state.keybinds.focus_pane_left = Some((KeyCode::Char('h'), KeyModifiers::ALT));
app.state.keybinds.focus_pane_left_label = Some("alt+h".into());
app.handle_terminal_key(TerminalKey::new(KeyCode::Char('h'), KeyModifiers::ALT))
.await;
assert_ne!(app.state.workspaces[0].layout.focused(), focused_before);
assert_eq!(app.state.mode, Mode::Terminal);
}
#[tokio::test]
async fn alt_backspace_is_forwarded_to_focused_pane() {
let mut app = app_for_mouse_test();
let mut ws = Workspace::test_new("test");
let pane_id = ws.tabs[0].root_pane;
let pane_infos = ws.tabs[0].layout.panes(Rect::new(0, 0, 80, 24));
let info = pane_infos[0].clone();
let (runtime, mut rx) = crate::pane::PaneRuntime::test_with_channel(
info.inner_rect.width,
info.inner_rect.height,
);
ws.tabs[0].runtimes.insert(pane_id, runtime);
app.state.workspaces = vec![ws];
app.state.active = Some(0);
app.state.selected = 0;
app.state.mode = Mode::Terminal;
app.state.view.pane_infos = pane_infos;
let key = crate::input::parse_terminal_key_sequence("\x1b\x7f").unwrap();
app.handle_terminal_key_headless(key);
let bytes = rx.try_recv().unwrap();
assert_eq!(bytes.as_ref(), b"\x1b\x7f");
assert!(rx.try_recv().is_err());
}
#[tokio::test]
async fn page_up_scrolls_plain_shell_pane() {
let mut app = app_for_mouse_test();
let mut ws = Workspace::test_new("test");
let pane_id = ws.tabs[0].root_pane;
let pane_infos = ws.tabs[0].layout.panes(Rect::new(26, 2, 80, 18));
let info = pane_infos[0].clone();
ws.tabs[0].runtimes.insert(
pane_id,
crate::pane::PaneRuntime::test_with_scrollback_bytes(
info.inner_rect.width,
info.inner_rect.height,
16 * 1024,
&numbered_lines_bytes(64),
),
);
app.state.workspaces = vec![ws];
app.state.active = Some(0);
app.state.selected = 0;
app.state.mode = Mode::Terminal;
app.state.view.pane_infos = pane_infos;
let start_metrics = app
.state
.runtime_for_pane_in_workspace(0, pane_id)
.and_then(crate::pane::PaneRuntime::scroll_metrics)
.expect("initial scroll metrics");
assert_eq!(start_metrics.offset_from_bottom, 0);
app.handle_terminal_key_headless(TerminalKey::new(KeyCode::PageUp, KeyModifiers::empty()));
let end_metrics = app
.state
.runtime_for_pane_in_workspace(0, pane_id)
.and_then(crate::pane::PaneRuntime::scroll_metrics)
.expect("scroll metrics after PageUp");
assert_eq!(
end_metrics.offset_from_bottom,
info.inner_rect.height as usize
);
}
#[tokio::test]
async fn page_down_returns_to_bottom_after_page_up() {
let mut app = app_for_mouse_test();
let mut ws = Workspace::test_new("test");
let pane_id = ws.tabs[0].root_pane;
let pane_infos = ws.tabs[0].layout.panes(Rect::new(26, 2, 80, 18));
let info = pane_infos[0].clone();
ws.tabs[0].runtimes.insert(
pane_id,
crate::pane::PaneRuntime::test_with_scrollback_bytes(
info.inner_rect.width,
info.inner_rect.height,
16 * 1024,
&numbered_lines_bytes(64),
),
);
app.state.workspaces = vec![ws];
app.state.active = Some(0);
app.state.selected = 0;
app.state.mode = Mode::Terminal;
app.state.view.pane_infos = pane_infos;
app.handle_terminal_key_headless(TerminalKey::new(KeyCode::PageUp, KeyModifiers::empty()));
let after_up = app
.state
.runtime_for_pane_in_workspace(0, pane_id)
.and_then(crate::pane::PaneRuntime::scroll_metrics)
.expect("scroll metrics after PageUp");
assert!(after_up.offset_from_bottom > 0);
app.handle_terminal_key_headless(TerminalKey::new(
KeyCode::PageDown,
KeyModifiers::empty(),
));
let after_down = app
.state
.runtime_for_pane_in_workspace(0, pane_id)
.and_then(crate::pane::PaneRuntime::scroll_metrics)
.expect("scroll metrics after PageDown");
assert_eq!(after_down.offset_from_bottom, 0);
}
#[tokio::test]
async fn page_up_release_does_not_scroll_plain_shell_pane_again() {
let mut app = app_for_mouse_test();
let mut ws = Workspace::test_new("test");
let pane_id = ws.tabs[0].root_pane;
let pane_infos = ws.tabs[0].layout.panes(Rect::new(26, 2, 80, 18));
let info = pane_infos[0].clone();
ws.tabs[0].runtimes.insert(
pane_id,
crate::pane::PaneRuntime::test_with_scrollback_bytes(
info.inner_rect.width,
info.inner_rect.height,
16 * 1024,
&numbered_lines_bytes(64),
),
);
app.state.workspaces = vec![ws];
app.state.active = Some(0);
app.state.selected = 0;
app.state.mode = Mode::Terminal;
app.state.view.pane_infos = pane_infos;
app.handle_terminal_key_headless(TerminalKey::new(KeyCode::PageUp, KeyModifiers::empty()));
let after_press = app
.state
.runtime_for_pane_in_workspace(0, pane_id)
.and_then(crate::pane::PaneRuntime::scroll_metrics)
.expect("scroll metrics after PageUp press");
assert_eq!(
after_press.offset_from_bottom,
info.inner_rect.height as usize
);
app.handle_terminal_key_headless(
TerminalKey::new(KeyCode::PageUp, KeyModifiers::empty())
.with_kind(KeyEventKind::Release),
);
let after_release = app
.state
.runtime_for_pane_in_workspace(0, pane_id)
.and_then(crate::pane::PaneRuntime::scroll_metrics)
.expect("scroll metrics after PageUp release");
assert_eq!(
after_release.offset_from_bottom,
after_press.offset_from_bottom
);
}
#[tokio::test]
async fn modified_page_up_does_not_host_scroll_plain_shell_pane() {
let mut app = app_for_mouse_test();
let mut ws = Workspace::test_new("test");
let pane_id = ws.tabs[0].root_pane;
let pane_infos = ws.tabs[0].layout.panes(Rect::new(26, 2, 80, 18));
let info = pane_infos[0].clone();
ws.tabs[0].runtimes.insert(
pane_id,
crate::pane::PaneRuntime::test_with_scrollback_bytes(
info.inner_rect.width,
info.inner_rect.height,
16 * 1024,
&numbered_lines_bytes(64),
),
);
app.state.workspaces = vec![ws];
app.state.active = Some(0);
app.state.selected = 0;
app.state.mode = Mode::Terminal;
app.state.view.pane_infos = pane_infos;
app.handle_terminal_key_headless(TerminalKey::new(KeyCode::PageUp, KeyModifiers::CONTROL));
let metrics = app
.state
.runtime_for_pane_in_workspace(0, pane_id)
.and_then(crate::pane::PaneRuntime::scroll_metrics)
.expect("scroll metrics after modified PageUp");
assert_eq!(metrics.offset_from_bottom, 0);
}
#[tokio::test]
async fn page_up_forwarded_to_mouse_reporting_pane() {
let mut app = app_for_mouse_test();
let mut ws = Workspace::test_new("test");
let pane_id = ws.tabs[0].root_pane;
let pane_infos = ws.tabs[0].layout.panes(Rect::new(26, 2, 80, 18));
let info = pane_infos[0].clone();
let mut bytes = b"\x1b[?1002h".to_vec();
bytes.extend_from_slice(&numbered_lines_bytes(64));
ws.tabs[0].runtimes.insert(
pane_id,
crate::pane::PaneRuntime::test_with_scrollback_bytes(
info.inner_rect.width,
info.inner_rect.height,
16 * 1024,
&bytes,
),
);
app.state.workspaces = vec![ws];
app.state.active = Some(0);
app.state.selected = 0;
app.state.mode = Mode::Terminal;
app.state.view.pane_infos = pane_infos;
let start_metrics = app
.state
.runtime_for_pane_in_workspace(0, pane_id)
.and_then(crate::pane::PaneRuntime::scroll_metrics)
.expect("initial scroll metrics");
assert_eq!(start_metrics.offset_from_bottom, 0);
app.handle_terminal_key_headless(TerminalKey::new(KeyCode::PageUp, KeyModifiers::empty()));
let end_metrics = app
.state
.runtime_for_pane_in_workspace(0, pane_id)
.and_then(crate::pane::PaneRuntime::scroll_metrics)
.expect("scroll metrics after PageUp");
// Forwarded to pane, so test runtime doesn't process it — scroll stays at bottom.
assert_eq!(end_metrics.offset_from_bottom, 0);
}
}
|