diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-01-18 12:08:25 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-01-18 15:00:49 +0100 |
| commit | 5117997a12a602a0380d22f7c641bf0305d175b7 (patch) | |
| tree | 69e39aa150a9c2e37537c2a73fb7b9359af2cea7 /vis-modes.c | |
| parent | 87d81f090d83c5e3aa6866e34575e55a23241b37 (diff) | |
| download | vis-5117997a12a602a0380d22f7c641bf0305d175b7.tar.gz vis-5117997a12a602a0380d22f7c641bf0305d175b7.tar.xz | |
vis: unify insert/replace mode leave handler
Diffstat (limited to 'vis-modes.c')
| -rw-r--r-- | vis-modes.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/vis-modes.c b/vis-modes.c index c3ade9f..1b9a4f4 100644 --- a/vis-modes.c +++ b/vis-modes.c @@ -135,6 +135,14 @@ bool vis_window_mode_map(Win *win, enum VisMode id, bool force, const char *key, /** mode switching event handlers */ +static void vis_mode_normal_enter(Vis *vis, Mode *old) { + if (old != mode_get(vis, VIS_MODE_INSERT) && old != mode_get(vis, VIS_MODE_REPLACE)) + return; + /* make sure we can recover the current state after an editing operation */ + vis_file_snapshot(vis, vis->win->file); + macro_operator_stop(vis); +} + static void vis_mode_operator_input(Vis *vis, const char *str, size_t len) { /* invalid operator */ vis_cancel(vis); @@ -187,14 +195,6 @@ static void vis_mode_insert_enter(Vis *vis, Mode *old) { } } -static void vis_mode_insert_leave(Vis *vis, Mode *new) { - if (new == mode_get(vis, VIS_MODE_NORMAL)) { - /* make sure we can recover the current state after an editing operation */ - vis_file_snapshot(vis, vis->win->file); - macro_operator_stop(vis); - } -} - static void vis_mode_insert_idle(Vis *vis) { vis_file_snapshot(vis, vis->win->file); } @@ -217,14 +217,6 @@ static void vis_mode_replace_enter(Vis *vis, Mode *old) { } } -static void vis_mode_replace_leave(Vis *vis, Mode *new) { - if (new == mode_get(vis, VIS_MODE_NORMAL)) { - /* make sure we can recover the current state after an editing operation */ - vis_file_snapshot(vis, vis->win->file); - macro_operator_stop(vis); - } -} - static void vis_mode_replace_input(Vis *vis, const char *str, size_t len) { vis_replace_key(vis, str, len); } @@ -240,6 +232,7 @@ Mode vis_modes[] = { .id = VIS_MODE_NORMAL, .name = "NORMAL", .help = "", + .enter = vis_mode_normal_enter, }, [VIS_MODE_VISUAL] = { .id = VIS_MODE_VISUAL, @@ -266,7 +259,6 @@ Mode vis_modes[] = { .status = "INSERT", .help = "", .enter = vis_mode_insert_enter, - .leave = vis_mode_insert_leave, .input = vis_mode_insert_input, .idle = vis_mode_insert_idle, .idle_timeout = 3, @@ -278,7 +270,6 @@ Mode vis_modes[] = { .status = "REPLACE", .help = "", .enter = vis_mode_replace_enter, - .leave = vis_mode_replace_leave, .input = vis_mode_replace_input, .idle = vis_mode_insert_idle, .idle_timeout = 3, |
