ref: 15cc6b688b0c510976fc0bb802dcbcc8f1b043c5
parent: 802df8d23433934b946358c215585ed01ef8586e
author: phil9 <[email protected]>
date: Wed Dec 29 07:18:40 EST 2021
make undo keep track of modification state modification state is now properly reflected when performing undo/redo.
--- a/a.h
+++ b/a.h
@@ -31,6 +31,7 @@
int index;
uchar value;
uchar newvalue;
+ int modified;
};
int canundo(void);
@@ -37,7 +38,7 @@
void undo(Undo*);
int canredo(void);
void redo(Undo*);
-void pushundo(int, int, uchar, uchar);
+void pushundo(int, int, uchar, uchar, int);
void patchundo(uchar);
/* COLORS */
--- a/undo.c
+++ b/undo.c
@@ -21,6 +21,7 @@
undo->index = ustack[ucur].index;
undo->value = ustack[ucur].value;
undo->newvalue = ustack[ucur].newvalue;
+ undo->modified = ustack[ucur].modified;
ucur -= 1;
}
@@ -38,10 +39,11 @@
undo->index = ustack[ucur].index;
undo->value = ustack[ucur].value;
undo->newvalue = ustack[ucur].newvalue;
+ undo->modified = ustack[ucur].modified;
}
void
-pushundo(int action, int index, uchar value, uchar newvalue)
+pushundo(int action, int index, uchar value, uchar newvalue, int modified)
{
if(ucur == Stacksize - 1)
return;
@@ -51,6 +53,7 @@
ustack[ucur].index = index;
ustack[ucur].value = value;
ustack[ucur].newvalue = newvalue;
+ ustack[ucur].modified = modified;
}
void
--- a/vexed.c
+++ b/vexed.c
@@ -74,7 +74,7 @@
break;
}
sel = u.index;
- modified = 1;
+ modified = u.modified;
blines = buf.count / 16;
redraw();
}
@@ -134,7 +134,7 @@
void
xdelete(void)
{
- pushundo(Udelete, sel, buf.data[sel], 0);
+ pushundo(Udelete, sel, buf.data[sel], 0, modified);
if(delete(&buf, sel) < 0)
sysfatal("delete: %r");
if(sel == buf.count)
@@ -147,7 +147,7 @@
void
xinsert(void)
{
- pushundo(Uinsert, sel, 0, 0);
+ pushundo(Uinsert, sel, 0, 0, modified);
if(insert(&buf, sel) < 0)
sysfatal("insert: %r");
modified = 1;
@@ -158,7 +158,7 @@
void
xappend(void)
{
- pushundo(Uappend, sel, 0, 0);
+ pushundo(Uappend, sel, 0, 0, modified);
if(append(&buf, sel) < 0)
sysfatal("append: %r");
sel += 1;
@@ -529,7 +529,7 @@
lastv = -1;
}else{
lastv = hexval(k);
- pushundo(Uset, sel, buf.data[sel], lastv);
+ pushundo(Uset, sel, buf.data[sel], lastv, modified);
buf.data[sel] = lastv;
}
modified = 1;