Skip to content
Permalink
Browse files

redo for the editor

an undo for undos :)
  • Loading branch information...
ac-stef committed Feb 16, 2014
1 parent 859df26 commit aaf01e8b2addc0c5f6bf8671b497f177e36ada04
Showing with 23 additions and 4 deletions.
  1. +1 −0 config/resetbinds.cfg
  2. +22 −4 source/src/editing.cpp
@@ -94,6 +94,7 @@ bind P [ editheight 2 1 ]
bind Q []
editbind Q [ domodifier 1 ]
bind R reload
editbind R redo
bind S backward
bind T saycommand // or even "saycommand >"
bind U []
@@ -289,16 +289,22 @@ void cursorupdate() // called every frame fr
glLineWidth(1);
}

vector<block *> undos; // unlimited undo
vector<block *> undos, redos; // unlimited undo
VAR(undomegs, 0, 5, 50); // bounded by n megs

void pruneundos(int maxremain) // bound memory
{
int t = 0;
int u = 0, r = 0;
maxremain /= sizeof(sqr);
loopvrev(undos)
{
t += undos[i]->xs*undos[i]->ys*sizeof(sqr);
if(t>maxremain) delete[] (uchar *)undos.remove(i);
u += undos[i]->xs * undos[i]->ys;
if(u > maxremain) delete[] (uchar *)undos.remove(i);
}
loopvrev(redos)
{
r += redos[i]->xs * redos[i]->ys;
if(r > maxremain) delete[] (uchar *)redos.remove(i);
}
}

@@ -313,6 +319,17 @@ void editundo()
EDITMP;
if(undos.empty()) { conoutf("nothing more to undo"); return; }
block *p = undos.pop();
redos.add(blockcopy(*p));
blockpaste(*p);
freeblock(p);
}

void editredo()
{
EDITMP;
if(redos.empty()) { conoutf("nothing more to redo"); return; }
block *p = redos.pop();
undos.add(blockcopy(*p));
blockpaste(*p);
freeblock(p);
}
@@ -782,6 +799,7 @@ COMMAND(arch, "i");
COMMANDF(slope, "ii", (int *xd, int *yd) { slope(*xd, *yd); });
COMMANDF(vdelta, "i", (int *d) { setvdelta(*d); });
COMMANDN(undo, editundo, "");
COMMANDN(redo, editredo, "");
COMMAND(copy, "");
COMMAND(paste, "");
COMMANDF(edittex, "ii", (int *type, int *dir) { edittex(*type, *dir); });

0 comments on commit aaf01e8

Please sign in to comment.
You can’t perform that action at this time.