Add jumping to specific line
This commit is contained in:
parent
86dad44405
commit
a20cd81dff
1 changed files with 19 additions and 1 deletions
20
main.cpp
20
main.cpp
|
@ -36,6 +36,15 @@ void insert_char(int r, int s, char ch) { file.find(file_offset+r)->text.insert(
|
|||
void remove_char(int r, int s, int len=1) { file.find(file_offset+r)->text.erase(s,len); }
|
||||
void remove_line(int r) { file.remove(file_offset+r); }
|
||||
|
||||
int get_number() {
|
||||
char ch = '0';
|
||||
string s = "";
|
||||
while(ch >= '0' && ch <= '9') {
|
||||
s += ch;
|
||||
ch = getch();
|
||||
}
|
||||
return stoi(s);
|
||||
}
|
||||
|
||||
// Load file to buffer
|
||||
bool load(string filename) {
|
||||
|
@ -88,7 +97,6 @@ string split_line(int r, int s) {
|
|||
}
|
||||
|
||||
|
||||
// TODO skoky a přesuny
|
||||
// TODO kopirování
|
||||
// TODO hledání a nahrazování
|
||||
// TODO undo
|
||||
|
@ -139,6 +147,12 @@ void move_cursor(char ch) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
// Skoky a přesuny
|
||||
void jump(int r) {
|
||||
file_offset = std::min(r, std::max((int)(file.size()-LINES), 0));
|
||||
row = 0;
|
||||
jump_line_end();
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
@ -169,6 +183,10 @@ int main(int argc, char* argv[]) {
|
|||
case 'h': case 'j': case 'k': case 'l':
|
||||
move_cursor(ch);
|
||||
break;
|
||||
case 'g':
|
||||
jump(get_number());
|
||||
print_file();
|
||||
break;
|
||||
case 'd':
|
||||
remove_line(row);
|
||||
print_file(row);
|
||||
|
|
Loading…
Reference in a new issue