From 112cdc74d606645c60cf119d497c09633ad128b4 Mon Sep 17 00:00:00 2001 From: Felix Angell Date: Sun, 15 Apr 2018 19:23:35 +0100 Subject: [PATCH] scrolling bounds checks --- gui/buffer.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/gui/buffer.go b/gui/buffer.go index 3327093..46ec6e8 100644 --- a/gui/buffer.go +++ b/gui/buffer.go @@ -370,13 +370,15 @@ func (b *Buffer) scrollUp() { } func (b *Buffer) scrollDown() { - // TODO move the cursor down 45 lines - // IF the buffer exceeds the window size. - lineScrollAmount := 10 + if b.cam.y < len(b.contents) { + // TODO move the cursor down 45 lines + // IF the buffer exceeds the window size. + lineScrollAmount := 10 - b.cam.y += lineScrollAmount - for i := 0; i < lineScrollAmount; i++ { - b.moveDown() + b.cam.y += lineScrollAmount + for i := 0; i < lineScrollAmount; i++ { + b.moveDown() + } } }