From 11df072b288ee3a2f3d8f813db05af7205862e57 Mon Sep 17 00:00:00 2001 From: cancel Date: Tue, 11 Dec 2018 20:07:17 +0900 Subject: [PATCH] Add escape key going to normal mode if not in normal mode --- README.md | 2 +- tui_main.c | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c8941ce..f1a3f2c 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Run the interactive terminal UI, useful for debugging or observing behavior. Pas - `/`: change into or out of key-trigger mode (for the `!` operator) - `'` (single quote): change into or out of rectangle selection size adjustment mode - `shift+arrow keys`: adjust rectangle selection size (only in some terminals) -- `escape`: deselect (set cursor rectangle selection to 1x1) +- `escape`: return to normal mode, or deselect (set cursor rectangle selection to 1x1) - `[` and `]`: adjust cosmetic grid rulers horizontally - `{` and `}`: adjust cosmetic grid rulers vertically - `(` and `)`: resize grid horizontally diff --git a/tui_main.c b/tui_main.c index 33ef946..1cb0895 100644 --- a/tui_main.c +++ b/tui_main.c @@ -1242,7 +1242,7 @@ typedef enum { App_input_cmd_toggle_play_pause, App_input_cmd_copy, App_input_cmd_paste, - App_input_cmd_deselect, + App_input_cmd_escape, } App_input_cmd; void app_input_cmd(App_state* a, App_input_cmd ev) { @@ -1347,8 +1347,11 @@ void app_input_cmd(App_state* a, App_input_cmd ev) { a->needs_remarking = true; a->is_draw_dirty = true; } break; - case App_input_cmd_deselect: { - if (a->tui_cursor.h != 1 || a->tui_cursor.w != 1) { + case App_input_cmd_escape: { + if (a->input_mode != Tui_input_mode_normal) { + a->input_mode = Tui_input_mode_normal; + a->is_draw_dirty = true; + } else if (a->tui_cursor.h != 1 || a->tui_cursor.w != 1) { a->tui_cursor.h = 1; a->tui_cursor.w = 1; a->is_draw_dirty = true; @@ -1708,7 +1711,7 @@ int main(int argc, char** argv) { stm_laptime(&last_time); break; case 27: // Escape - app_input_cmd(&app_state, App_input_cmd_deselect); + app_input_cmd(&app_state, App_input_cmd_escape); break; // Selection size modification. These may not work in all terminals. (Only