fixed scrolling issue on insert mode

development
Michael Ochmann 8 years ago
parent 1f675cf276
commit b509cb6d50
  1. 4
      src/Buffer.hpp
  2. 4
      src/Editor.cpp
  3. 2
      src/Editor.hpp

@ -48,6 +48,10 @@ namespace groove {
std::string& at(int line) { std::string& at(int line) {
return this->lines.at(line); return this->lines.at(line);
} }
unsigned long size() {
return this->lines.size();
}
}; };
} }

@ -110,6 +110,7 @@ namespace groove {
this->y++; this->y++;
this->buffer->linebuffer().at(this->y) += appendix; this->buffer->linebuffer().at(this->y) += appendix;
this->x = 0; this->x = 0;
this->scrollDown();
} }
break; break;
case KEY_BACKSPACE: case KEY_BACKSPACE:
@ -133,6 +134,7 @@ namespace groove {
} }
} }
} }
scrollUp();
break; break;
case KEY_DC: case KEY_DC:
if (this->buffer->at(this->y).length() > this->x) if (this->buffer->at(this->y).length() > this->x)
@ -198,7 +200,7 @@ namespace groove {
int space = Editor::Digits(this->buffer->linebuffer().size()) + 2; int space = Editor::Digits(this->buffer->linebuffer().size()) + 2;
clear(); clear();
for (int i = 0; i < LINES - 1 + this->offset; i++) { for (int i = 0; i < LINES - 1 + this->offset; i++) {
int ln = std::sqrt(std::pow(static_cast<double>(this->y - linenumber), 2)); int ln = static_cast<int>(std::sqrt(std::pow(static_cast<double>(this->y - linenumber), 2)));
ln = ln == 0 ? linenumber : ln; ln = ln == 0 ? linenumber : ln;
if(i >= this->buffer->linebuffer().size()) { if(i >= this->buffer->linebuffer().size()) {
move(i - this->offset, 0); move(i - this->offset, 0);

@ -31,7 +31,7 @@ namespace groove {
this->offset--; this->offset--;
} }
void scrollDown() { void scrollDown() {
if (this->y >= LINES - 1) if (this->y - this->offset >= LINES - 1 && this->y < this->buffer->size())
this->offset++; this->offset++;
} }
void left() { void left() {

Loading…
Cancel
Save