From 6b15891cfdd85a5f4c9c5df9ae7a8789fc98e9aa Mon Sep 17 00:00:00 2001 From: ac-stef Date: Thu, 15 Sep 2016 19:02:20 +0200 Subject: [PATCH] undo changes back to a specific state undolevel Returns the number of undo steps that can be undone. If argument "level" is given, as many steps are undone, until "level" steps remain. Example, during editing: echo (undolevel) prints number of previous editing steps, for example "55" ... do some editing ... undolevel 55 undoes all changes to restore the previous state (if that state is still in memory... keep in mind, undo-space is limited, see "undomegs" parameter) Unless memory limits delete states, undolevel commands can be undone with "redo". DOCREF undolevel --- source/src/editing.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/src/editing.cpp b/source/src/editing.cpp index 69ff2d30..0357e267 100644 --- a/source/src/editing.cpp +++ b/source/src/editing.cpp @@ -346,6 +346,7 @@ void cursorupdate() // called every frame fr vector undos, redos; // unlimited undo VAR(undomegs, 0, 5, 50); // bounded by n megs +int undolevel = 0; void pruneundos(int maxremain) // bound memory { @@ -376,6 +377,7 @@ void makeundo(block &sel) undos.add(blockcopy(sel)); pruneundos(undomegs<<20); unsavededits++; + undolevel++; } void restoreposition(short p[]) @@ -428,6 +430,7 @@ void editundo() EDITMP; if(undos.empty()) { conoutf("nothing more to undo"); return; } block *p = undos.pop(); + undolevel--; redos.add(blockcopy(*p)); if(editmetakeydown) restoreposition(*p); blockpaste(*p); @@ -436,12 +439,25 @@ void editundo() } COMMANDN(undo, editundo, ""); +void gotoundolevel(char *lev) +{ + if(*lev && isdigit(*lev)) + { + EDITMP; + int n = ATOI(lev); + while(undolevel > n && undos.length() > 0) editundo(); + } + intret(undolevel); +} +COMMANDN(undolevel, gotoundolevel, "s"); + void editredo() { EDITMP; if(redos.empty()) { conoutf("nothing more to redo"); return; } block *p = redos.pop(); undos.add(blockcopy(*p)); + undolevel++; if(editmetakeydown) restoreposition(*p); blockpaste(*p); freeblock(p); @@ -1180,5 +1196,6 @@ void reseteditor() // reset only stuff that would cause trouble editing the next { loopk(3) curedittex[k] = -1; pruneundos(0); + undolevel = 0; pinnedclosestent = false; }