From 617db1d87703e929390a3ea04d189a25c4aaa026 Mon Sep 17 00:00:00 2001 From: cflip Date: Mon, 16 Jan 2023 10:48:09 -0700 Subject: Implement some more commands from vim --- editor.c | 13 +++++++++++++ editor.h | 3 +++ input.c | 14 ++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/editor.c b/editor.c index 9f51188..016fa2e 100644 --- a/editor.c +++ b/editor.c @@ -140,6 +140,19 @@ void editor_delete_char(struct editor_state* editor) } } +void editor_add_line_above(struct editor_state* editor) +{ + insert_row(editor, editor->cursor_y, "", 0); + editor->cursor_x = 0; +} + +void editor_add_line_below(struct editor_state* editor) +{ + insert_row(editor, editor->cursor_y + 1, "", 0); + editor->cursor_y++; + editor->cursor_x = 0; +} + static void editor_find_callback(struct editor_state* editor, char* query, int key) { static int last_match = -1; diff --git a/editor.h b/editor.h index dc0b354..f38a7d4 100644 --- a/editor.h +++ b/editor.h @@ -40,6 +40,9 @@ void editor_move_down(struct editor_state *); void editor_insert_char(struct editor_state* editor, int c); void editor_insert_newline(struct editor_state* editor); void editor_delete_char(struct editor_state* editor); +void editor_add_line_above(struct editor_state* editor); +void editor_add_line_below(struct editor_state* editor); + void editor_find(struct editor_state* editor); void editor_scroll(struct editor_state* editor); void editor_draw_rows(struct editor_state* editor, struct append_buffer* buffer); diff --git a/input.c b/input.c index 8a9d673..37f4c2e 100644 --- a/input.c +++ b/input.c @@ -62,6 +62,20 @@ void editor_process_keypress(struct editor_state *editor, SDL_Keysym *keysym) case SDLK_i: editor->mode = EDITOR_MODE_INSERT; break; + case SDLK_a: + if (keysym->mod & KMOD_SHIFT) + editor->cursor_x = editor->rows[editor->cursor_y].size; + else + editor_move_right(editor); + editor->mode = EDITOR_MODE_INSERT; + break; + case SDLK_o: + if (keysym->mod & KMOD_SHIFT) + editor_add_line_above(editor); + else + editor_add_line_below(editor); + editor->mode = EDITOR_MODE_INSERT; + break; case SDLK_k: editor_move_up(editor); break; -- cgit v1.2.3