minor fixes of scrolling; performance boost by culling to current view buffer

development
Michael Ochmann 8 years ago
parent 5c7f5856ef
commit cecf3079f6
  1. 4
      CMakeLists.txt
  2. 20
      src/Editor.cpp
  3. 10
      src/Editor.hpp
  4. 6
      src/Highlighter.cpp
  5. 2
      src/Highlighter.hpp
  6. 2
      src/modes/Edit.cpp
  7. 2
      src/modes/Edit.hpp
  8. 2
      src/modes/Insert.hpp

@ -23,4 +23,6 @@ include_directories(
add_executable(groove main.cpp ${SOURCE_FILES} ${HEADER_FILES})
target_link_libraries(groove ncursesw)
target_link_libraries(groove ncursesw)
install(TARGETS groove DESTINATION /usr/bin)

@ -55,11 +55,11 @@ namespace groove {
}
void Editor::render() {
int linenumber = 0;
long linenumber = this->offset;
this->vspace = Editor::Digits(this->buffer->linebuffer().size()) + 2;
clear();
for (int i = 0; i < LINES - 1 + this->offset; i++) {
unsigned long ln = static_cast<unsigned long>(std::sqrt(std::pow(static_cast<double>(this->y - linenumber), 2)));
for (int i = this->offset; i < LINES - 1 + this->offset; i++) {
long ln = static_cast<long>(std::sqrt(std::pow(static_cast<double>(this->y - linenumber), 2)));
ln = ln == 0 ? linenumber : ln;
if(i >= this->buffer->linebuffer().size()) {
move(i - this->offset, 0);
@ -68,15 +68,15 @@ namespace groove {
else {
std::string line = this->buffer->at(i);
Highlighter highlighter(line);
std::unordered_map<int, std::pair<int, ncurses::Colors>> hilist = highlighter.get();
int x = this->vspace;
int found = -1;
int len = -1;
std::unordered_map<long, std::pair<long, ncurses::Colors>> hilist = highlighter.get();
long x = this->vspace;
long found = -1;
long len = -1;
std::string label = std::string(x - Editor::Digits(ln) - 1, ' ');
label += std::to_string(ln) + ' ';
if (linenumber != this->y)
attron(A_REVERSE);
mvprintw(i - this->offset, 0, label.c_str());
mvprintw(i - offset, 0, label.c_str());
if (linenumber != this->y)
attroff(A_REVERSE);
for (auto& car : line) {
@ -119,8 +119,8 @@ namespace groove {
attroff(COLOR_PAIR(ncurses::Colors::STATUSBAR));
}
unsigned long Editor::Digits(unsigned long number) {
return number > 0 ? static_cast<unsigned long>(log10 ((double) number) + 1) : 1;
long Editor::Digits(long number) {
return number > 0 ? static_cast<long>(log10 ((double) number) + 1) : 1;
}
}

@ -25,9 +25,9 @@ namespace groove {
friend class modes::Quit;
friend class modes::Save;
private:
unsigned long x, y;
long x, y;
int offset;
unsigned long vspace;
long vspace;
char lastChar = 0;
std::unique_ptr<Buffer> buffer;
Mode mode_;
@ -73,7 +73,7 @@ namespace groove {
return;
}
if (this->x >= this->buffer->linebuffer().at(this->y).length()) {
unsigned long length = this->buffer->linebuffer().at(this->y).length();
long length = this->buffer->linebuffer().at(this->y).length();
this->x = length > 0 ? length - 1 : 0;
}
this->scrollUp();
@ -85,7 +85,7 @@ namespace groove {
return;
}
if (this->x >= this->buffer->linebuffer().at(this->y).length()) {
unsigned long length = this->buffer->linebuffer().at(this->y).length();
long length = this->buffer->linebuffer().at(this->y).length();
this->x = length > 0 ? length - 1 : 0;
}
this->scrollDown();
@ -116,7 +116,7 @@ namespace groove {
}
void input(int c);
void render();
static unsigned long Digits(unsigned long number);
static long Digits(long number);
};
}

@ -14,11 +14,11 @@ namespace groove {
make_pair("\\\".*\\\"", ncurses::Colors::ORANGE),
make_pair("/\\*.*\\*//*", ncurses::Colors::ORANGE),
make_pair("(//.*)", ncurses::Colors::ORANGE),
make_pair("(^#.*)", ncurses::Colors::ORANGE)
make_pair("(#.*<.*>$)", ncurses::Colors::ORANGE)
};
std::unordered_map<int, std::pair<int, ncurses::Colors>> groove::Highlighter::get() {
std::unordered_map<int, std::pair<int, ncurses::Colors>> list;
std::unordered_map<long, std::pair<long, ncurses::Colors>> groove::Highlighter::get() {
std::unordered_map<long, std::pair<long, ncurses::Colors>> list;
for (auto& keyword : Highlighter::list) {
try {

@ -18,7 +18,7 @@ namespace groove {
static std::vector<std::pair<std::regex, ncurses::Colors>> list;
public:
Highlighter(std::string line) : line(line) {}
std::unordered_map<int, std::pair<int, ncurses::Colors>> get();
std::unordered_map<long, std::pair<long, ncurses::Colors>> get();
};
}

@ -28,7 +28,7 @@ namespace groove {
this->editor.clipboard = this->editor.buffer->at(this->editor.y);
this->editor.buffer->remove(this->editor.y);
break;
case 'p':
case 'v':
this->editor.buffer->insert(this->editor.clipboard, this->editor.y);
this->editor.y++;
this->editor.x = this->editor.buffer->at(this->editor.y).size();

@ -9,7 +9,7 @@ namespace groove {
public:
using Mode::Mode;
std::string status() {
return "[E]" + this->status_;
return this->status_;
}
void input(int c);
};

@ -9,7 +9,7 @@ namespace groove {
public:
using Mode::Mode;
std::string status() {
return "[I]" + this->status_;
return " -- INSERT --" + this->status_;
}
void input(int c);
};

Loading…
Cancel
Save