added kinda multiline comment support

development
Michael Ochmann 8 years ago
parent c2e922344d
commit 2e039c3f4d
  1. 9
      src/Editor.cpp
  2. 1
      src/Editor.hpp
  3. 7
      src/modes/Edit.cpp

@ -9,7 +9,7 @@ namespace groove {
Editor::Editor(std::string filename) : x(0), y(0), Editor::Editor(std::string filename) : x(0), y(0),
buffer(std::make_unique<Buffer>()), mode_(Mode::EDIT), buffer(std::make_unique<Buffer>()), mode_(Mode::EDIT),
filename(filename), offset(0), voffset(0), lineMode(LineMode::RELATIVE), filename(filename), offset(0), voffset(0), lineMode(LineMode::RELATIVE),
history(History()) { history(History()), inComment(false) {
this->modes.emplace(Mode::INSERT, std::make_unique<modes::Insert>(*this)); this->modes.emplace(Mode::INSERT, std::make_unique<modes::Insert>(*this));
this->modes.emplace(Mode::EDIT, std::make_unique<modes::Edit>(*this)); this->modes.emplace(Mode::EDIT, std::make_unique<modes::Edit>(*this));
this->modes.emplace(Mode::QUIT, std::make_unique<modes::Quit>(*this)); this->modes.emplace(Mode::QUIT, std::make_unique<modes::Quit>(*this));
@ -95,6 +95,10 @@ namespace groove {
} }
for (auto& car : line) { for (auto& car : line) {
if (car == '*' && this->lastChar == '/')
this->inComment = true;
if (car == '/' && this->lastChar == '*')
this->inComment = false;
if (hilist.find(x - this->vspace) != hilist.end()) { if (hilist.find(x - this->vspace) != hilist.end()) {
found = x - this->vspace; found = x - this->vspace;
len = hilist.at(x - this->vspace).first; len = hilist.at(x - this->vspace).first;
@ -108,8 +112,11 @@ namespace groove {
len = -1; len = -1;
} }
} }
if (inComment)
attron(COLOR_PAIR(ncurses::Colors::ORANGE));
mvaddch(i - this->offset, x , car); mvaddch(i - this->offset, x , car);
attron(COLOR_PAIR(ncurses::Colors::MAIN)); attron(COLOR_PAIR(ncurses::Colors::MAIN));
this->lastChar = car;
x++; x++;
} }
//mvprintw(i - this->offset, 0, line.c_str()); //mvprintw(i - this->offset, 0, line.c_str());

@ -38,6 +38,7 @@ namespace groove {
int offset; int offset;
int voffset; int voffset;
long vspace; long vspace;
bool inComment;
char lastChar = 0; char lastChar = 0;
History history; History history;
LineMode lineMode; LineMode lineMode;

@ -89,6 +89,13 @@ namespace groove {
break; break;
case 'r': case 'r':
this->editor.history.redo(); this->editor.history.redo();
break;
case '^':
this->editor.x = 0;
break;
case '$':
this->editor.x = this->editor.buffer->at(this->editor.y).size();
break;
} }
} }
} }

Loading…
Cancel
Save