From b509cb6d5028f784f55544a575308f5d6dc06e38 Mon Sep 17 00:00:00 2001 From: Michael Ochmann Date: Mon, 6 Mar 2017 16:11:48 +0100 Subject: [PATCH] fixed scrolling issue on insert mode --- src/Buffer.hpp | 4 ++++ src/Editor.cpp | 4 +++- src/Editor.hpp | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Buffer.hpp b/src/Buffer.hpp index faa63d1..439db8c 100644 --- a/src/Buffer.hpp +++ b/src/Buffer.hpp @@ -48,6 +48,10 @@ namespace groove { std::string& at(int line) { return this->lines.at(line); } + + unsigned long size() { + return this->lines.size(); + } }; } \ No newline at end of file diff --git a/src/Editor.cpp b/src/Editor.cpp index 539da58..a76652f 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -110,6 +110,7 @@ namespace groove { this->y++; this->buffer->linebuffer().at(this->y) += appendix; this->x = 0; + this->scrollDown(); } break; case KEY_BACKSPACE: @@ -133,6 +134,7 @@ namespace groove { } } } + scrollUp(); break; case KEY_DC: if (this->buffer->at(this->y).length() > this->x) @@ -198,7 +200,7 @@ namespace groove { int space = Editor::Digits(this->buffer->linebuffer().size()) + 2; clear(); for (int i = 0; i < LINES - 1 + this->offset; i++) { - int ln = std::sqrt(std::pow(static_cast(this->y - linenumber), 2)); + int ln = static_cast(std::sqrt(std::pow(static_cast(this->y - linenumber), 2))); ln = ln == 0 ? linenumber : ln; if(i >= this->buffer->linebuffer().size()) { move(i - this->offset, 0); diff --git a/src/Editor.hpp b/src/Editor.hpp index 723058f..7c7cbff 100644 --- a/src/Editor.hpp +++ b/src/Editor.hpp @@ -31,7 +31,7 @@ namespace groove { this->offset--; } void scrollDown() { - if (this->y >= LINES - 1) + if (this->y - this->offset >= LINES - 1 && this->y < this->buffer->size()) this->offset++; } void left() { @@ -55,7 +55,7 @@ namespace groove { this->scrollUp(); } void down() { - if (this->y + 1 < this->buffer->linebuffer().size()) + if (this->y + 1 < this->buffer->linebuffer().size() ) this->y++; else { return;