Fix undo
Avoid incorrect values in the number of undo elements and restore lastln value after an undo operation.
This commit is contained in:
parent
cd9b149c8f
commit
ece6569297
21
ed.c
21
ed.c
|
@ -35,7 +35,7 @@ struct hline {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct undo {
|
struct undo {
|
||||||
int curln;
|
int curln, lastln;
|
||||||
size_t nr, cap;
|
size_t nr, cap;
|
||||||
struct link {
|
struct link {
|
||||||
int to1, from1;
|
int to1, from1;
|
||||||
|
@ -51,7 +51,7 @@ static String lastre;
|
||||||
static int optverbose, optprompt, exstatus, optdiag = 1;
|
static int optverbose, optprompt, exstatus, optdiag = 1;
|
||||||
static int marks['z' - 'a'];
|
static int marks['z' - 'a'];
|
||||||
static int nlines, line1, line2;
|
static int nlines, line1, line2;
|
||||||
static int curln, lastln, ocurln;
|
static int curln, lastln, ocurln, olastln;
|
||||||
static jmp_buf savesp;
|
static jmp_buf savesp;
|
||||||
static char *lasterr;
|
static char *lasterr;
|
||||||
static size_t idxsize, lastidx;
|
static size_t idxsize, lastidx;
|
||||||
|
@ -266,13 +266,14 @@ clearundo(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
relink(int to1, int from1, int from2, int to2)
|
newundo(int from1, int from2)
|
||||||
{
|
{
|
||||||
struct link *p;
|
struct link *p;
|
||||||
|
|
||||||
if (newcmd) {
|
if (newcmd) {
|
||||||
clearundo();
|
clearundo();
|
||||||
udata.curln = ocurln;
|
udata.curln = ocurln;
|
||||||
|
udata.lastln = olastln;
|
||||||
}
|
}
|
||||||
if (udata.nr >= udata.cap) {
|
if (udata.nr >= udata.cap) {
|
||||||
size_t siz = (udata.cap + 10) * sizeof(struct link);
|
size_t siz = (udata.cap + 10) * sizeof(struct link);
|
||||||
|
@ -286,7 +287,16 @@ relink(int to1, int from1, int from2, int to2)
|
||||||
p->to1 = zero[from1].next;
|
p->to1 = zero[from1].next;
|
||||||
p->from2 = from2;
|
p->from2 = from2;
|
||||||
p->to2 = zero[from2].prev;
|
p->to2 = zero[from2].prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* relink: to1 <- from1
|
||||||
|
* from2 -> to2
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
relink(int to1, int from1, int from2, int to2)
|
||||||
|
{
|
||||||
|
newundo(from1, from2);
|
||||||
zero[from1].next = to1;
|
zero[from1].next = to1;
|
||||||
zero[from2].prev = to2;
|
zero[from2].prev = to2;
|
||||||
modflag = 1;
|
modflag = 1;
|
||||||
|
@ -299,7 +309,8 @@ undo(void)
|
||||||
|
|
||||||
if (udata.nr == 0)
|
if (udata.nr == 0)
|
||||||
return;
|
return;
|
||||||
for (p = &udata.vec[udata.nr-1]; udata.nr--; --p) {
|
for (p = &udata.vec[udata.nr-1]; udata.nr > 0; --p) {
|
||||||
|
--udata.nr;
|
||||||
zero[p->from1].next = p->to1;
|
zero[p->from1].next = p->to1;
|
||||||
zero[p->from2].prev = p->to2;
|
zero[p->from2].prev = p->to2;
|
||||||
}
|
}
|
||||||
|
@ -307,6 +318,7 @@ undo(void)
|
||||||
udata.vec = NULL;
|
udata.vec = NULL;
|
||||||
udata.cap = 0;
|
udata.cap = 0;
|
||||||
curln = udata.curln;
|
curln = udata.curln;
|
||||||
|
lastln = udata.lastln;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1395,6 +1407,7 @@ edit(void)
|
||||||
for (;;) {
|
for (;;) {
|
||||||
newcmd = 1;
|
newcmd = 1;
|
||||||
ocurln = curln;
|
ocurln = curln;
|
||||||
|
olastln = lastln;
|
||||||
cmdline.siz = 0;
|
cmdline.siz = 0;
|
||||||
repidx = -1;
|
repidx = -1;
|
||||||
if (optprompt) {
|
if (optprompt) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user