Added an option to flip lines upwards/downwards.

This commit is contained in:
GrenderG
2017-04-09 20:15:19 +02:00
parent afa775fa16
commit d48f31f4ef
2 changed files with 23 additions and 2 deletions
+2
View File
@@ -35,6 +35,8 @@ If you are planning to use special characters like (á, é, í, ó, ú, ¡, ¿,
Ctrl-Q : Exit
Ctrl-F : Search text (ESC, arrows and enter to interact once searching)
Ctrl-S : Save
Ctrl-E : Flip line upwards
Ctrl-D : Flip line downwards
```
## Current supported languages
+21 -2
View File
@@ -865,6 +865,15 @@ void editorFreeRow(editor_row* row) {
free(row -> highlight);
}
// -1 down, 1 up
void editorFlipRow(int dir) {
editor_row c_row = ec.row[ec.cursor_y];
ec.row[ec.cursor_y] = ec.row[ec.cursor_y - dir];
ec.row[ec.cursor_y - dir] = c_row;
ec.cursor_y -= dir;
ec.dirty++;
}
void editorDelRow(int at) {
if (at < 0 || at >= ec.num_rows)
return;
@@ -1485,6 +1494,14 @@ void editorProcessKeypress() {
case CTRL_KEY('s'):
editorSave();
break;
case CTRL_KEY('e'):
if (ec.cursor_y > 0)
editorFlipRow(1);
break;
case CTRL_KEY('d'):
if (ec.cursor_y < ec.num_rows - 1)
editorFlipRow(-1);
break;
case ARROW_UP:
case ARROW_DOWN:
case ARROW_LEFT:
@@ -1564,7 +1581,9 @@ void printHelp() {
printf("Keybinding\t\tAction\n\n");
printf("Ctrl-Q \t\tExit\n");
printf("Ctrl-S \t\tSave\n");
printf("Ctrl-F \t\tSearch (Esc, enter and arrows to interact once searching)\n");
printf("Ctrl-F \t\tSearch. Esc, enter and arrows to interact once searching\n");
printf("Ctrl-E \t\tFlip line upwards\n");
printf("Ctrl-D \t\tFlip line downwards\n");
printf("\n\nOPTIONS\n-------\n\n");
printf("Option \t\tAction\n\n");
@@ -1609,4 +1628,4 @@ int main(int argc, char* argv[]) {
}
return 0;
}
}