From 757efb85045408e2601da0f53547941a40d2e960 Mon Sep 17 00:00:00 2001 From: cflip Date: Tue, 31 Jan 2023 10:46:21 -0700 Subject: Start implementing editor commands This first step allows you to press the semicolon key to enter command mode, where you can type into a command line. Currently, pressing enter when in command mode will clear the command line but since there are no commands implemented it doesn't matter what you type in there. --- window.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'window.c') diff --git a/window.c b/window.c index 9518d69..cb041e5 100644 --- a/window.c +++ b/window.c @@ -52,17 +52,7 @@ int window_handle_event(struct editor_state *editor) editor_process_keypress(editor, &e.key.keysym); break; case SDL_TEXTINPUT: - if (editor->mode == EDITOR_MODE_NORMAL) - break; - /* - * Ignore the first letter after entering insert mode, because it - * usually is just 'i'. - */ - if (editor->pressed_insert_key) { - editor->pressed_insert_key = 0; - break; - } - editor_insert_char(editor, *e.text.text); + input_process_textinput(editor, e.text.text); break; case SDL_WINDOWEVENT: if (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { @@ -164,9 +154,17 @@ void window_redraw(struct editor_state *editor) editor_scroll(editor); draw_editor(editor); + int cursor_x = (editor->cursor_display_x - editor->col_offset); + int cursor_y = (editor->cursor_y - editor->line_offset); + + if (editor->mode == EDITOR_MODE_COMMAND) { + cursor_x = editor->cmdline.length; + cursor_y = editor->screen_rows + 1; + } + SDL_Rect cursor_rect; - cursor_rect.x = (editor->cursor_display_x - editor->col_offset) * font.width; - cursor_rect.y = (editor->cursor_y - editor->line_offset) * font.height; + cursor_rect.x = cursor_x * font.width; + cursor_rect.y = cursor_y * font.height; cursor_rect.w = font.width; cursor_rect.h = font.height; -- cgit v1.2.3