Skip to content

Commit e0a8673

Browse files
committed
Merge PR #197: fix(cortex-tui): use terminal height for Page Up/Down scrolling
2 parents 4083bf2 + c680d82 commit e0a8673

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

cortex-tui/src/runner/event_loop.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,8 +2239,20 @@ impl EventLoop {
22392239
// Scroll actions
22402240
KeyAction::ScrollUp => self.app_state.scroll_chat(-1),
22412241
KeyAction::ScrollDown => self.app_state.scroll_chat(1),
2242-
KeyAction::ScrollPageUp => self.app_state.scroll_chat(-10),
2243-
KeyAction::ScrollPageDown => self.app_state.scroll_chat(10),
2242+
KeyAction::ScrollPageUp => {
2243+
// Use terminal height - 1 for standard page scroll (provides context overlap)
2244+
let page_size = (self.app_state.terminal_size.1 as i32)
2245+
.saturating_sub(1)
2246+
.max(1);
2247+
self.app_state.scroll_chat(-page_size);
2248+
}
2249+
KeyAction::ScrollPageDown => {
2250+
// Use terminal height - 1 for standard page scroll (provides context overlap)
2251+
let page_size = (self.app_state.terminal_size.1 as i32)
2252+
.saturating_sub(1)
2253+
.max(1);
2254+
self.app_state.scroll_chat(page_size);
2255+
}
22442256
KeyAction::ScrollToTop => self.app_state.scroll_chat_to_top(),
22452257
KeyAction::ScrollToBottom => self.app_state.scroll_chat_to_bottom(),
22462258

cortex-tui/src/runner/handlers.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,16 @@ impl<'a> ActionHandler<'a> {
115115
// Scrolling
116116
KeyAction::ScrollUp => self.handle_scroll(-1),
117117
KeyAction::ScrollDown => self.handle_scroll(1),
118-
KeyAction::ScrollPageUp => self.handle_scroll(-10),
119-
KeyAction::ScrollPageDown => self.handle_scroll(10),
118+
KeyAction::ScrollPageUp => {
119+
// Use terminal height - 1 for standard page scroll (provides context overlap)
120+
let page_size = (self.state.terminal_size.1 as i32).saturating_sub(1).max(1);
121+
self.handle_scroll(-page_size)
122+
}
123+
KeyAction::ScrollPageDown => {
124+
// Use terminal height - 1 for standard page scroll (provides context overlap)
125+
let page_size = (self.state.terminal_size.1 as i32).saturating_sub(1).max(1);
126+
self.handle_scroll(page_size)
127+
}
120128
KeyAction::ScrollToTop => self.handle_scroll_to_top(),
121129
KeyAction::ScrollToBottom => self.handle_scroll_to_bottom(),
122130

@@ -1072,9 +1080,12 @@ mod tests {
10721080
let mut stream = create_test_stream();
10731081
state.set_focus(FocusTarget::Chat);
10741082

1083+
// Default terminal size is (80, 24), so page size = 24 - 1 = 23
1084+
let expected_page_size = (state.terminal_size.1 as usize).saturating_sub(1).max(1);
1085+
10751086
let result = run_action(&mut state, &mut stream, KeyAction::ScrollPageDown).await;
10761087
assert!(result.is_ok());
10771088
assert!(result.unwrap());
1078-
assert_eq!(state.chat_scroll, 10);
1089+
assert_eq!(state.chat_scroll, expected_page_size);
10791090
}
10801091
}

0 commit comments

Comments
 (0)