vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit b0c98573f0cf56c8e32df54d502ed305cb002032
parent 82b2acc2076384348c0168b6bb0919542568b374
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Fri, 12 Sep 2014 10:55:01 +0200

Take snapshot when leaving insert/replace mode

Make sure we are able to restore text to whatever state was when
we left insert / replace mode after an editing operation.

Diffstat:
Mconfig.def.h | 12++++++++++++
1 file changed, 12 insertions(+), 0 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -453,6 +453,11 @@ static KeyBinding vis_insert_mode[] = { { /* empty last element, array terminator */ }, }; +static void vis_mode_insert_leave(Mode *old) { + /* make sure we can recover the current state after an editing operation */ + text_snapshot(vis->win->text); +} + static void vis_insert_idle(void) { text_snapshot(vis->win->text); } @@ -466,6 +471,11 @@ static KeyBinding vis_replace[] = { { /* empty last element, array terminator */ }, }; +static void vis_mode_replace_leave(Mode *old) { + /* make sure we can recover the current state after an editing operation */ + text_snapshot(vis->win->text); +} + static void vis_replace_input(const char *str, size_t len) { editor_replace_key(vis, str, len); } @@ -603,6 +613,7 @@ static Mode vis_modes[] = { .name = "INSERT", .parent = &vis_modes[VIS_MODE_INSERT_REGISTER], .bindings = vis_insert_mode, + .leave = vis_mode_insert_leave, .input = vis_insert_input, .idle = vis_insert_idle, }, @@ -610,6 +621,7 @@ static Mode vis_modes[] = { .name = "REPLACE", .parent = &vis_modes[VIS_MODE_INSERT], .bindings = vis_replace, + .leave = vis_mode_replace_leave, .input = vis_replace_input, .idle = vis_insert_idle, },