Simplify printing and fix tabs
This commit is contained in:
parent
99c3e8cc0c
commit
d8981403ac
2 changed files with 26 additions and 21 deletions
40
editor.cpp
40
editor.cpp
|
@ -17,22 +17,18 @@ void Editor::clear_line(count_type r) {
|
||||||
::move(r - file_offset, 0);
|
::move(r - file_offset, 0);
|
||||||
clrtoeol();
|
clrtoeol();
|
||||||
}
|
}
|
||||||
// Print line
|
// Print any text
|
||||||
void Editor::print_line(count_type r) {
|
void Editor::print_text(count_type i, string text) {
|
||||||
clear_line(r);
|
clear_line(i);
|
||||||
::move(r - file_offset, 0);
|
::move(i, 0);
|
||||||
adds(file.get_line(r));
|
adds(text);
|
||||||
}
|
}
|
||||||
// Print file content
|
// Print file content
|
||||||
void Editor::print_file(count_type start) {
|
void Editor::print_file(count_type start) {
|
||||||
auto lines = file.bulk_get_line(start, LINES);
|
auto lines = file.bulk_get_line(start, LINES);
|
||||||
for(count_type i = 0; i < LINES; i++)
|
for(count_type i = 0; i < LINES; i++)
|
||||||
if(i < lines.size()) {
|
if(i < lines.size())
|
||||||
::move(i, 0);
|
print_text(i, lines[i]);
|
||||||
clrtoeol();
|
|
||||||
::move(i, 0);
|
|
||||||
adds(lines[i]);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
clear_line(i);
|
clear_line(i);
|
||||||
}
|
}
|
||||||
|
@ -184,7 +180,7 @@ bool Editor::take_action() {
|
||||||
case 'o':
|
case 'o':
|
||||||
file.insert(file_offset + cur.r, "");
|
file.insert(file_offset + cur.r, "");
|
||||||
jump_line_end();
|
jump_line_end();
|
||||||
print_file(file_offset + cur.r);
|
print_file(file_offset);
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
return false;
|
return false;
|
||||||
|
@ -211,7 +207,7 @@ bool Editor::take_action() {
|
||||||
}
|
}
|
||||||
jump(result.second);
|
jump(result.second);
|
||||||
}
|
}
|
||||||
print_file(file_offset + cur.r);
|
print_file(file_offset);
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
last_find = get_string("to find");
|
last_find = get_string("to find");
|
||||||
|
@ -227,23 +223,26 @@ bool Editor::take_action() {
|
||||||
jump(result.second);
|
jump(result.second);
|
||||||
replace(cur + file_offset, last_find.size(), last_replace);
|
replace(cur + file_offset, last_find.size(), last_replace);
|
||||||
}
|
}
|
||||||
print_file(file_offset + cur.r);
|
print_file(file_offset);
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
selection.paste_selection(cur + file_offset);
|
selection.paste_selection(cur + file_offset);
|
||||||
print_file(file_offset + cur.r);
|
print_file(file_offset);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case INSERT:
|
case INSERT:
|
||||||
|
// TODO remake insert mode for better undo
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
case ESC:
|
case ESC:
|
||||||
mode = NORMAL;
|
mode = NORMAL;
|
||||||
|
// Change current row into current_insert TODO
|
||||||
print_line(file_offset + cur.r);
|
print_line(file_offset + cur.r);
|
||||||
break;
|
break;
|
||||||
case BS:
|
case BS:
|
||||||
|
// Modify current_insert TODO
|
||||||
if(cur.c > 0) {
|
if(cur.c > 0) {
|
||||||
cur.c -= 1;
|
cur.c -= 1;
|
||||||
file.remove(cur + file_offset);
|
file.remove(cur + file_offset);
|
||||||
|
@ -251,17 +250,20 @@ bool Editor::take_action() {
|
||||||
print_line(file_offset + cur.r);
|
print_line(file_offset + cur.r);
|
||||||
break;
|
break;
|
||||||
case ENTER:
|
case ENTER:
|
||||||
|
// Modify current_insert and update TODO
|
||||||
file.split_line(cur + file_offset);
|
file.split_line(cur + file_offset);
|
||||||
print_file(file_offset + cur.r++);
|
print_file(file_offset);
|
||||||
|
cur.r++;
|
||||||
jump_line_end();
|
jump_line_end();
|
||||||
break;
|
break;
|
||||||
case '\t':
|
case '\t':
|
||||||
|
// Modify current_insert TODO
|
||||||
file.insert(cur + file_offset, "\t");
|
file.insert(cur + file_offset, "\t");
|
||||||
cur.c += (cur.c - 1) % TAB_SIZE + 1;
|
cur.c += TAB_SIZE - (cur.c % TAB_SIZE);
|
||||||
print_line(file_offset + cur.r);
|
print_line(file_offset + cur.r);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// TODO remake for better undo
|
// Modify current_insert TODO
|
||||||
file.insert(cur + file_offset, string(1, ch));
|
file.insert(cur + file_offset, string(1, ch));
|
||||||
cur.c += 1;
|
cur.c += 1;
|
||||||
print_line(file_offset + cur.r);
|
print_line(file_offset + cur.r);
|
||||||
|
@ -286,7 +288,7 @@ bool Editor::take_action() {
|
||||||
selection.remove_selection(cur + file_offset);
|
selection.remove_selection(cur + file_offset);
|
||||||
if(file_offset + cur.r >= file.size())
|
if(file_offset + cur.r >= file.size())
|
||||||
jump(cur + file_offset);
|
jump(cur + file_offset);
|
||||||
print_file();
|
print_file(file_offset);
|
||||||
mode = NORMAL;
|
mode = NORMAL;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -96,15 +96,17 @@ class Editor{
|
||||||
string filename;
|
string filename;
|
||||||
Treap file;
|
Treap file;
|
||||||
|
|
||||||
// Selection
|
// Editation steps
|
||||||
string last_find, last_replace;
|
string last_find, last_replace;
|
||||||
Selection selection;
|
Selection selection;
|
||||||
|
string current_insert;
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
// Printing
|
// Printing
|
||||||
void clear_line(count_type r);
|
void clear_line(count_type r);
|
||||||
void print_line(count_type r);
|
void print_text(count_type i, string text);
|
||||||
|
void print_line(count_type r) { print_text(r - file_offset, file.get_line(r)); }
|
||||||
|
|
||||||
// User input
|
// User input
|
||||||
void print_input(string text);
|
void print_input(string text);
|
||||||
|
@ -134,6 +136,7 @@ public:
|
||||||
file = _file;
|
file = _file;
|
||||||
|
|
||||||
selection = Selection(&file);
|
selection = Selection(&file);
|
||||||
|
current_insert = "";
|
||||||
}
|
}
|
||||||
void print_file(count_type start = 0);
|
void print_file(count_type start = 0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue