diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2016-11-09 03:19:22 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2016-11-09 03:19:22 +0100 |
commit | 0213e99aaf6eba303fd459183dd14a4a11cc5b07 (patch) | |
tree | 9cf382b3ac1922520f9934cf47887430d99bc023 /src/nvim/undo.c | |
parent | bd33f1165b95e9f8f0d20ae3a941ee55906107ee (diff) | |
parent | aa0e09d251610f9b17f0bf96a4f3485032c36e0f (diff) | |
download | rneovim-0213e99aaf6eba303fd459183dd14a4a11cc5b07.tar.gz rneovim-0213e99aaf6eba303fd459183dd14a4a11cc5b07.tar.bz2 rneovim-0213e99aaf6eba303fd459183dd14a4a11cc5b07.zip |
Merge #5561 'inccommand'
Initial work by:
Robin Elrharbi-Fleury (Robinhola)
Audrey Rayé (Adrey06)
Philémon Hullot (DesbyP)
Aymeric Collange (aym7)
Clément Guyomard (Clement0)
Major revisions by:
KillTheMule
Björn Linse <bjorn.linse@gmail.com>
Justin M. Keyes <justinkz@gmail.com>
Diffstat (limited to 'src/nvim/undo.c')
-rw-r--r-- | src/nvim/undo.c | 86 |
1 files changed, 63 insertions, 23 deletions
diff --git a/src/nvim/undo.c b/src/nvim/undo.c index d80aaf443a..2f4317980a 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -1669,7 +1669,7 @@ void u_undo(int count) undo_undoes = TRUE; else undo_undoes = !undo_undoes; - u_doit(count); + u_doit(count, false); } /* @@ -1678,15 +1678,56 @@ void u_undo(int count) */ void u_redo(int count) { - if (vim_strchr(p_cpo, CPO_UNDO) == NULL) - undo_undoes = FALSE; - u_doit(count); + if (vim_strchr(p_cpo, CPO_UNDO) == NULL) { + undo_undoes = false; + } + + u_doit(count, false); } -/* - * Undo or redo, depending on 'undo_undoes', 'count' times. - */ -static void u_doit(int startcount) +/// undo, and remove the undo branch from the undo tree. +bool u_undo_and_forget(int count) +{ + if (curbuf->b_u_synced == false) { + u_sync(true); + count = 1; + } + undo_undoes = true; + u_doit(count, true); + + if (curbuf->b_u_curhead == NULL) { + // nothing was undone. + return false; + } + + // Delete the current redo header + // set the redo header to the next alternative branch (if any) + // otherwise we will be in the leaf state + u_header_T *to_forget = curbuf->b_u_curhead; + curbuf->b_u_newhead = to_forget->uh_next.ptr; + curbuf->b_u_curhead = to_forget->uh_alt_next.ptr; + if (curbuf->b_u_curhead) { + to_forget->uh_alt_next.ptr = NULL; + curbuf->b_u_curhead->uh_alt_prev.ptr = to_forget->uh_alt_prev.ptr; + curbuf->b_u_seq_cur = curbuf->b_u_curhead->uh_seq-1; + } else if (curbuf->b_u_newhead) { + curbuf->b_u_seq_cur = curbuf->b_u_newhead->uh_seq; + } + if (to_forget->uh_alt_prev.ptr) { + to_forget->uh_alt_prev.ptr->uh_alt_next.ptr = curbuf->b_u_curhead; + } + if (curbuf->b_u_newhead) { + curbuf->b_u_newhead->uh_prev.ptr = curbuf->b_u_curhead; + } + if (curbuf->b_u_seq_last == to_forget->uh_seq) { + curbuf->b_u_seq_last--; + } + u_freebranch(curbuf, to_forget, NULL); + return true; +} + +/// Undo or redo, depending on `undo_undoes`, `count` times. +static void u_doit(int startcount, bool quiet) { int count = startcount; @@ -1722,7 +1763,7 @@ static void u_doit(int startcount) break; } - u_undoredo(TRUE); + u_undoredo(true); } else { if (curbuf->b_u_curhead == NULL || get_undolevel() <= 0) { beep_flush(); /* nothing to redo */ @@ -1742,7 +1783,7 @@ static void u_doit(int startcount) curbuf->b_u_curhead = curbuf->b_u_curhead->uh_prev.ptr; } } - u_undo_end(undo_undoes, FALSE); + u_undo_end(undo_undoes, false, quiet); } /* @@ -2055,7 +2096,7 @@ void undo_time(long step, int sec, int file, int absolute) } } } - u_undo_end(did_undo, absolute); + u_undo_end(did_undo, absolute, false); } /* @@ -2299,16 +2340,13 @@ static void u_undoredo(int undo) #endif } -/* - * If we deleted or added lines, report the number of less/more lines. - * Otherwise, report the number of changes (this may be incorrect - * in some cases, but it's better than nothing). - */ -static void -u_undo_end ( - int did_undo, /* just did an undo */ - int absolute /* used ":undo N" */ -) +/// If we deleted or added lines, report the number of less/more lines. +/// Otherwise, report the number of changes (this may be incorrect +/// in some cases, but it's better than nothing). +static void u_undo_end( + int did_undo, ///< just did an undo + int absolute, ///< used ":undo N" + bool quiet) { char *msgstr; u_header_T *uhp; @@ -2317,9 +2355,11 @@ u_undo_end ( if ((fdo_flags & FDO_UNDO) && KeyTyped) foldOpenCursor(); - if (global_busy /* no messages now, wait until global is finished */ - || !messaging()) /* 'lazyredraw' set, don't do messages now */ + if (quiet + || global_busy // no messages until global is finished + || !messaging()) { // 'lazyredraw' set, don't do messages now return; + } if (curbuf->b_ml.ml_flags & ML_EMPTY) --u_newcount; |