fixed some casts

development
Michael Ochmann 8 years ago
parent ba56dfc489
commit 5c7f5856ef
  1. 12
      src/Buffer.hpp
  2. 24
      src/Editor.cpp
  3. 21
      src/Editor.hpp

@ -20,7 +20,7 @@ namespace groove {
return this->lines;
}
void insert(std::string str, int line) {
void insert(std::string str, unsigned long line) {
this->lines.insert(this->lines.begin() + line, str);
this->removeTabs(this->lines.at(line));
}
@ -29,23 +29,23 @@ namespace groove {
this->removeTabs(line);
this->lines.emplace_back(line);
}
void insert(int after) {
void insert(unsigned long after) {
this->lines.insert(this->lines.begin() + after + 1, "");
}
void remove(int line) {
void remove(unsigned long line) {
this->lines.erase(this->lines.begin() + line);
}
void remove(int line, int car) {
void remove(unsigned long line, int car) {
this->lines.at(line).erase(this->lines.at(line).begin() + car);
}
void deleteChar(int line, int car) {
void deleteChar(unsigned long line, int car) {
this->lines.at(line).erase(this->lines.at(line).begin() + car);
}
std::string& at(int line) {
std::string& at(unsigned long line) {
return this->lines.at(line);
}

@ -56,20 +56,20 @@ namespace groove {
void Editor::render() {
int linenumber = 0;
int space = Editor::Digits(this->buffer->linebuffer().size()) + 2;
this->vspace = Editor::Digits(this->buffer->linebuffer().size()) + 2;
clear();
for (int i = 0; i < LINES - 1 + this->offset; i++) {
int ln = static_cast<int>(std::sqrt(std::pow(static_cast<double>(this->y - linenumber), 2)));
unsigned long ln = static_cast<unsigned 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);
clrtoeol();
}
else {
std::string line = /*std::to_string(i) + " | " +*/ this->buffer->at(i);
std::string line = this->buffer->at(i);
Highlighter highlighter(line);
std::unordered_map<int, std::pair<int, ncurses::Colors>> hilist = highlighter.get();
int x = space;
int x = this->vspace;
int found = -1;
int len = -1;
std::string label = std::string(x - Editor::Digits(ln) - 1, ' ');
@ -80,14 +80,14 @@ namespace groove {
if (linenumber != this->y)
attroff(A_REVERSE);
for (auto& car : line) {
if (hilist.find(x - space) != hilist.end()) {
found = x - space;
len = hilist.at(x - space).first;
if (hilist.find(x - this->vspace) != hilist.end()) {
found = x - this->vspace;
len = hilist.at(x - this->vspace).first;
}
if (found >= 0 && len >= 0) {
if (x - space >= found && x - space <= found + len - 1)
if (x - this->vspace >= found && x - this->vspace <= found + len - 1)
attron(COLOR_PAIR(hilist.at(found).second));
else if (x - space > found && x - space >= found + len) {
else if (x - this->vspace > found && x - this->vspace >= found + len) {
attron(COLOR_PAIR(ncurses::Colors::MAIN));
found = -1;
len = -1;
@ -103,7 +103,7 @@ namespace groove {
linenumber++;
}
this->status();
move(this->y - this->offset, this->x + space);
move(static_cast<int>(this->y - this->offset), static_cast<int>(this->x + this->vspace));
}
void Editor::status() {
@ -119,8 +119,8 @@ namespace groove {
attroff(COLOR_PAIR(ncurses::Colors::STATUSBAR));
}
int Editor::Digits(int number) {
return number > 0 ? (int) log10 ((double) number) + 1 : 1;
unsigned long Editor::Digits(unsigned long number) {
return number > 0 ? static_cast<unsigned long>(log10 ((double) number) + 1) : 1;
}
}

@ -25,8 +25,9 @@ namespace groove {
friend class modes::Quit;
friend class modes::Save;
private:
int x, y;
unsigned long x, y;
int offset;
unsigned long vspace;
char lastChar = 0;
std::unique_ptr<Buffer> buffer;
Mode mode_;
@ -48,10 +49,22 @@ namespace groove {
void left() {
if (this->x - 1 >= 0)
this->x--;
else {
if (this->y - 1 >= 0) {
this->y--;
this->x = this->buffer->at(this->y).length();
}
}
}
void right() {
if (this->x + 1 <= COLS && this->x + 1 <= this->buffer->linebuffer().at(this->y).length())
this->x++;
else {
if (this->y + 1 <= this->buffer->size()) {
this->y++;
this->x = this->buffer->at(this->y).size();
}
}
}
void up() {
if (this->y - 1 >= 0)
@ -60,7 +73,7 @@ namespace groove {
return;
}
if (this->x >= this->buffer->linebuffer().at(this->y).length()) {
int length = static_cast<int>(this->buffer->linebuffer().at(this->y).length());
unsigned long length = this->buffer->linebuffer().at(this->y).length();
this->x = length > 0 ? length - 1 : 0;
}
this->scrollUp();
@ -72,7 +85,7 @@ namespace groove {
return;
}
if (this->x >= this->buffer->linebuffer().at(this->y).length()) {
int length = this->buffer->linebuffer().at(this->y).length();
unsigned long length = this->buffer->linebuffer().at(this->y).length();
this->x = length > 0 ? length - 1 : 0;
}
this->scrollDown();
@ -103,7 +116,7 @@ namespace groove {
}
void input(int c);
void render();
static int Digits(int number);
static unsigned long Digits(unsigned long number);
};
}
Loading…
Cancel
Save