Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Added boundaries for scrolling #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/edit_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,14 @@ impl EditView {
}

fn constrain_scroll(&mut self) {
let max_scroll = TOP_PAD + LINE_SPACE *
(self.line_cache.height().saturating_sub(1)) as f32;
let mut max_scroll = TOP_PAD + (LINE_SPACE *
(self.line_cache.height().saturating_sub(1)) as f32) - self.size.1 + LINE_SPACE;

// Not allowing to scroll if the text is smaller than the window size
if (LINE_SPACE * self.line_cache.height().saturating_sub(1) as f32) < self.size.1 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You're performing this calculation and typecast twice - might want to store it in a variable instead?
e.g. let visible_lines = LINE_SPACE * self.line_cache.height().saturating_sub(1) as f32

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storing the calculation in a variable would be a better idea of course !

max_scroll = 0 as f32;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to lock the last line at the bottom of the screen if you have something larger than your screen. Was that the behavior you wanted?

Copy link
Author

@antoninklopp antoninklopp Oct 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it was the behavior wanted. Maybe, it should have some extra lines at the end, but I think that this is pretty common behavior for most text editors.

}

if self.scroll_offset < 0.0 {
self.scroll_offset = 0.0;
} else if self.scroll_offset > max_scroll {
Expand Down