summaryrefslogtreecommitdiff
path: root/input.c
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2023-01-31 12:30:50 -0700
committercflip <cflip@cflip.net>2023-01-31 12:30:50 -0700
commit16b949aa3147e3aaadb6888f574f6424d4c2d8f3 (patch)
treefa0dc9e332eb319e58186d334cfb843a2ee9ff2a /input.c
parent757efb85045408e2601da0f53547941a40d2e960 (diff)
Add a function to handle changing the editor mode
This way any extra stuff such as clearing the command line buffer or setting the flag to ignore the extra first key can be automatically set.
Diffstat (limited to 'input.c')
-rw-r--r--input.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/input.c b/input.c
index 36670e2..3167a91 100644
--- a/input.c
+++ b/input.c
@@ -33,7 +33,7 @@ void editor_process_keypress(struct editor_state *editor, SDL_Keysym *keysym)
editor_insert_char(editor, '\t');
if (keysym->sym == SDLK_ESCAPE)
- editor->mode = EDITOR_MODE_NORMAL;
+ editor_set_mode(editor, EDITOR_MODE_NORMAL);
return;
}
@@ -45,7 +45,7 @@ void editor_process_keypress(struct editor_state *editor, SDL_Keysym *keysym)
editor_run_command(editor);
if (keysym->sym == SDLK_ESCAPE)
- editor->mode = EDITOR_MODE_NORMAL;
+ editor_set_mode(editor, EDITOR_MODE_NORMAL);
return;
}
@@ -85,30 +85,28 @@ void editor_process_keypress(struct editor_state *editor, SDL_Keysym *keysym)
editor_delete_char(editor);
break;
case SDLK_i:
- editor->mode = EDITOR_MODE_INSERT;
- editor->pressed_insert_key = 1;
+ editor_set_mode(editor, EDITOR_MODE_INSERT);
break;
case SDLK_l:
if (keysym->mod & KMOD_SHIFT)
editor_move_end(editor);
else
editor_move_right(editor);
- editor->mode = EDITOR_MODE_INSERT;
- editor->pressed_insert_key = 1;
+ editor_set_mode(editor, 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;
- editor->pressed_insert_key = 1;
+ editor_set_mode(editor, EDITOR_MODE_INSERT);
break;
case SDLK_SLASH:
editor_find(editor);
break;
case SDLK_SEMICOLON:
- editor->mode = EDITOR_MODE_COMMAND;
+ if (keysym->mod & KMOD_SHIFT)
+ editor_set_mode(editor, EDITOR_MODE_COMMAND);
break;
}
}