diff --git a/src/attach.rs b/src/attach.rs index 4a50550..bec20b0 100644 --- a/src/attach.rs +++ b/src/attach.rs @@ -142,7 +142,7 @@ fn adjust_scroll(input: &str, cursor: usize, scroll: &mut usize, cols: usize) { if cursor < *scroll { *scroll = cursor; } - if *scroll + max_visible > nchars { + if cursor < *scroll + threshold && *scroll + max_visible > nchars { *scroll = nchars.saturating_sub(max_visible); } } @@ -192,7 +192,7 @@ fn draw_all( out.push_str("\x1b[K"); out.push_str(RESET); - let cursor_col = prompt.len() + cursor.saturating_sub(scroll); + let cursor_col = (prompt.len() + cursor.saturating_sub(scroll)).min(cols - 1); out.push_str(&format!("\x1b[{};{}H", rows, cursor_col + 1)); let _ = stdout.write_all(out.as_bytes());