From 5b77a15fdfa2658de740a6f1c943aed50f5612f8 Mon Sep 17 00:00:00 2001 From: antonin 31 Date: Sun, 7 Oct 2018 13:10:41 +0200 Subject: [PATCH] Added boundaries for scrolling --- src/edit_view.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/edit_view.rs b/src/edit_view.rs index b75e51e..c598608 100644 --- a/src/edit_view.rs +++ b/src/edit_view.rs @@ -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 { + max_scroll = 0 as f32; + } + if self.scroll_offset < 0.0 { self.scroll_offset = 0.0; } else if self.scroll_offset > max_scroll {