feat(tui/history): Home/End jump to history start/end when input is empty\n\n- Add layout_scroll::to_top/to_bottom helpers\n- In ChatWidget, map Home/End to jump when composer has no text

This commit is contained in:
James Peter
2025-09-08 12:29:30 +10:00
parent 1315b93ec1
commit 7287fa71db
2 changed files with 40 additions and 0 deletions
+13
View File
@@ -1502,6 +1502,19 @@ impl ChatWidget<'_> {
layout_scroll::page_down(self);
return;
}
// Home/End: when the composer is empty, jump the history to start/end
if let crossterm::event::KeyEvent { code: crossterm::event::KeyCode::Home, kind: KeyEventKind::Press | KeyEventKind::Repeat, .. } = key_event {
if self.composer_is_empty() {
layout_scroll::to_top(self);
return;
}
}
if let crossterm::event::KeyEvent { code: crossterm::event::KeyCode::End, kind: KeyEventKind::Press | KeyEventKind::Repeat, .. } = key_event {
if self.composer_is_empty() {
layout_scroll::to_bottom(self);
return;
}
}
match self.bottom_pane.handle_key_event(key_event) {
InputResult::Submitted(text) => {
@@ -83,6 +83,33 @@ pub(super) fn flash_scrollbar(chat: &ChatWidget<'_>) {
});
}
/// Jump to the very top of the history (oldest content).
pub(super) fn to_top(chat: &mut ChatWidget<'_>) {
chat.layout.scroll_offset = chat.layout.last_max_scroll.get();
chat.bottom_pane.set_compact_compose(true);
flash_scrollbar(chat);
chat.app_event_tx
.send(crate::app_event::AppEvent::RequestRedraw);
chat.height_manager
.borrow_mut()
.record_event(HeightEvent::UserScroll);
chat.maybe_show_history_nav_hint_on_first_scroll();
}
/// Jump to the very bottom of the history (latest content).
pub(super) fn to_bottom(chat: &mut ChatWidget<'_>) {
chat.layout.scroll_offset = 0;
chat.bottom_pane.set_compact_compose(false);
flash_scrollbar(chat);
chat.app_event_tx
.send(crate::app_event::AppEvent::RequestRedraw);
chat.height_manager
.borrow_mut()
.record_event(HeightEvent::UserScroll);
// No hint necessary when landing at bottom, but keep behavior consistent
chat.maybe_show_history_nav_hint_on_first_scroll();
}
pub(super) fn toggle_browser_hud(chat: &mut ChatWidget<'_>) {
let new_state = !chat.layout.browser_hud_expanded;
chat.layout.browser_hud_expanded = new_state;