codetether_agent/tui/app/state/view_save.rs
1//! Save/restore scroll state when switching view modes.
2//!
3//! Streaming events fire `scroll_to_bottom` while the user is away from
4//! Chat (e.g. inspecting `/bus`), which would otherwise yank their
5//! scrollback to the latest message on return. Capture the scroll
6//! position on the way out and replay it on the way back.
7
8impl super::AppState {
9 /// Save chat scroll state before leaving Chat view.
10 pub fn save_scroll_state(&mut self) {
11 self.saved_chat_scroll = self.chat_scroll;
12 self.saved_chat_auto_follow = self.chat_auto_follow;
13 self.saved_tool_preview_scroll = self.tool_preview_scroll;
14 }
15
16 /// Restore chat scroll state when returning to Chat view.
17 pub fn restore_scroll_state(&mut self) {
18 self.chat_scroll = self.saved_chat_scroll;
19 self.chat_auto_follow = self.saved_chat_auto_follow;
20 self.tool_preview_scroll = self.saved_tool_preview_scroll;
21 }
22}