From 0d77b3cf9265a434c81c84ab4b30c1c2fae00dc3 Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 14 Jun 2022 22:15:02 +0200 Subject: [PATCH] Reword comments and code slightly --- cove-tui/src/chat/tree/cursor.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cove-tui/src/chat/tree/cursor.rs b/cove-tui/src/chat/tree/cursor.rs index ad0dd3e..7629ed5 100644 --- a/cove-tui/src/chat/tree/cursor.rs +++ b/cove-tui/src/chat/tree/cursor.rs @@ -41,7 +41,7 @@ impl TreeView { } // The cursor should be visible in its entirety on the screen now. If it - // isn't, we should scroll the screen such that the cursor becomes fully + // isn't, we need to scroll the screen such that the cursor becomes fully // visible again. To do this, we'll need to re-layout because the cursor // could've moved anywhere. let blocks = self @@ -50,10 +50,12 @@ impl TreeView { let cursor_block = blocks.find(&cursor.id).expect("cursor must be in blocks"); // First, ensure the cursor's last line is not below the bottom of the // screen. Then, ensure its top line is not above the top of the screen. - // If the cursor is higher than the screen, the user should still see - // the top of the cursor so they can start reading its contents. + // If the cursor has more lines than the screen, the user should still + // see the top of the cursor so they can start reading its contents. + let min_line = 0; let max_line = size.height as i32 - cursor_block.height; - let cursor_line = cursor_block.line.min(max_line).max(0); + // Not using clamp because it is possible that max_line < min_line + let cursor_line = cursor_block.line.min(max_line).max(min_line); cursor.proportion = util::line_to_proportion(size.height, cursor_line); // There is no need to ensure the screen is not scrolled too far up or