From 9d97c6b78627994eb140e5943660d6166673168b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 12 Sep 2014 10:55:01 +0200 Subject: 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. --- config.def.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/config.def.h b/config.def.h index b8bbdd5..ad8eb4c 100644 --- 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, }, -- cgit v1.2.3