summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2023-01-16 10:48:09 -0700
committercflip <cflip@cflip.net>2023-01-16 10:48:09 -0700
commit617db1d87703e929390a3ea04d189a25c4aaa026 (patch)
treea768632f80a8c5b4d9b1192eaa553c4cb2505278
parent24232e191a16015509b444fcee771b2f0cb1478b (diff)
Implement some more commands from vim
-rw-r--r--editor.c13
-rw-r--r--editor.h3
-rw-r--r--input.c14
3 files changed, 30 insertions, 0 deletions
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;