🏄🏼♂️ The blackboard for coding agents - agentic development environment for claude code, codex, cursor, opencode, grok and more.
Rust adeai-agentsclaudeclaude-codecodexcursorgeminigrokopencodespec-driven-developmentvibe-codingvim
fix: clamp scroll_up offset to prevent phantom scroll dead zone (#52)
Trần Hoàng Túae0024239aec
diff --git a/src/tui/shell_popup.rs b/src/tui/shell_popup.rsindex bfea673..e7e5ca0 100644--- a/src/tui/shell_popup.rs+++ b/src/tui/shell_popup.rs@@ -30,12 +30,17 @@ impl ShellPopup {}}- /// Scroll up into history+ /// Scroll up into history, clamped to content bounds.pub fn scroll_up(&mut self, lines: i32) {- self.scroll_offset -= lines;+ // Derive the total line count from text lines rather than raw '\n' bytes,+ // so that a final line without a trailing newline is still counted.+ let content_str = String::from_utf8_lossy(&self.cached_content);+ let total_lines = content_str.lines().count() as i32;+ let min_offset = -(total_lines.max(0));+ self.scroll_offset = (self.scroll_offset - lines).max(min_offset);}- /// Scroll down toward current content+ /// Scroll down toward current content, clamped to 0.pub fn scroll_down(&mut self, lines: i32) {self.scroll_offset = (self.scroll_offset + lines).min(0);}diff --git a/tests/shell_popup_tests.rs b/tests/shell_popup_tests.rsindex 6a249f5..e0146df 100644--- a/tests/shell_popup_tests.rs+++ b/tests/shell_popup_tests.rs@@ -20,6 +20,8 @@ fn test_shell_popup_new() {#[test]fn test_shell_popup_scroll_up() {let mut popup = ShellPopup::new("Test".to_string(), "window".to_string());+ // Add content with 20 lines so scroll has room+ popup.cached_content = b"line\n".repeat(20).to_vec();assert_eq!(popup.scroll_offset, 0);popup.scroll_up(5);@@ -29,6 +31,16 @@ fn test_shell_popup_scroll_up() {assert_eq!(popup.scroll_offset, -15);}+#[test]+fn test_shell_popup_scroll_up_clamped_to_content() {+ let mut popup = ShellPopup::new("Test".to_string(), "window".to_string());+ // Only 3 lines of content+ popup.cached_content = b"a\nb\nc\n".to_vec();++ popup.scroll_up(100);+ assert_eq!(popup.scroll_offset, -3); // Clamped to -(total lines)+}+#[test]fn test_shell_popup_scroll_down_clamped() {let mut popup = ShellPopup::new("Test".to_string(), "window".to_string());@@ -63,6 +75,7 @@ fn test_shell_popup_scroll_to_bottom() {#[test]fn test_shell_popup_is_at_bottom() {let mut popup = ShellPopup::new("Test".to_string(), "window".to_string());+ popup.cached_content = b"line\n".repeat(10).to_vec();assert!(popup.is_at_bottom());popup.scroll_up(5);