undo changes back to a specific state

undolevel <level>

  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
This commit is contained in:
ac-stef
2016-09-16 14:06:26 +02:00
parent 96a028c263
commit 6b15891cfd
+17
View File
@@ -346,6 +346,7 @@ void cursorupdate() // called every frame fr
vector<block *> 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;
}