| tImplement simple sequential key binding - ve - a minimal text editor (work in … | |
| git clone git://src.adamsgaard.dk/ve | |
| Log | |
| Files | |
| Refs | |
| README | |
| LICENSE | |
| --- | |
| commit 46d33db19cc6321705a9c52f7929a2a689d88ebc | |
| parent 73ee9195069d7b78a8b224190eec153bb01831b1 | |
| Author: Anders Damsgaard <[email protected]> | |
| Date: Wed, 7 Aug 2019 23:06:49 +0200 | |
| Implement simple sequential key binding | |
| Diffstat: | |
| M ve.c | 52 +++++++++++++++++------------… | |
| 1 file changed, 29 insertions(+), 23 deletions(-) | |
| --- | |
| diff --git a/ve.c b/ve.c | |
| t@@ -864,23 +864,6 @@ editor_process_keypress() | |
| E.mode = 1; | |
| break; | |
| - case CTRL_KEY('q'): | |
| - if (E.file_changed) { | |
| - editor_set_status_message("error: " | |
| - "file ha… | |
| - "Press C… | |
| - break; | |
| - } else { | |
| - write(STDOUT_FILENO, "\x1b[2J", 4); /*… | |
| - write(STDOUT_FILENO, "\x1b[H", 3); | |
| - exit(0); | |
| - break; | |
| - } | |
| - case CTRL_KEY('x'): | |
| - write(STDOUT_FILENO, "\x1b[2J", 4); /* clear s… | |
| - write(STDOUT_FILENO, "\x1b[H", 3); | |
| - exit(0); | |
| - break; | |
| case 'h': | |
| case 'j': | |
| case 'k': | |
| t@@ -888,8 +871,25 @@ editor_process_keypress() | |
| editor_move_cursor(c); | |
| break; | |
| - case CTRL_KEY('w'): | |
| - file_save(E.filename); | |
| + case ' ': | |
| + c = editor_read_key(); | |
| + switch (c) { | |
| + case 'w': | |
| + file_save(E.filename); | |
| + break; | |
| + case 'q': | |
| + if (E.file_changed) { | |
| + editor_set_status_mess… | |
| + … | |
| + … | |
| + break; | |
| + } else { | |
| + write(STDOUT_FILENO, "… | |
| + write(STDOUT_FILENO, "… | |
| + exit(0); | |
| + break; | |
| + } | |
| + } | |
| break; | |
| case CTRL_KEY('f'): | |
| t@@ -923,8 +923,11 @@ editor_process_keypress() | |
| break; | |
| case 'g': | |
| - E.cursor_x = 0; | |
| - E.cursor_y = 0; | |
| + c = editor_read_key(); | |
| + if (c == 'g') { | |
| + E.cursor_x = 0; | |
| + E.cursor_y = 0; | |
| + } | |
| break; | |
| case 'G': | |
| E.cursor_x = 0; | |
| t@@ -935,8 +938,11 @@ editor_process_keypress() | |
| editor_delete_char_right(); | |
| break; | |
| case 'd': | |
| - editor_row_delete(E.cursor_y); | |
| - editor_move_cursor('h'); | |
| + c = editor_read_key(); | |
| + if (c == 'd') { | |
| + editor_row_delete(E.cursor_y); | |
| + editor_move_cursor('h'); | |
| + } | |
| break; | |
| case 'o': |