summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Labrecque <vincent@cvs.openbsd.org>2003-11-29 17:28:41 +0000
committerVincent Labrecque <vincent@cvs.openbsd.org>2003-11-29 17:28:41 +0000
commit4217f0a91228c93db9f3bc76f085106afee8e63d (patch)
tree8d1a42b12dba59907939521cf6e85d17644d6464
parentf840511f6ee9eb5171023282b52f9e26f9304a76 (diff)
save the previous undo position as an offset in the buffer instead of
a line/offset pair
-rw-r--r--usr.bin/mg/def.h4
-rw-r--r--usr.bin/mg/undo.c27
-rw-r--r--usr.bin/mg/window.c4
3 files changed, 16 insertions, 19 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index 44e0cd6d231..c4aff6a7945 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.52 2003/11/09 01:11:14 vincent Exp $ */
+/* $OpenBSD: def.h,v 1.53 2003/11/29 17:28:40 vincent Exp $ */
#include <sys/queue.h>
@@ -202,7 +202,7 @@ typedef struct MGWIN {
char w_force; /* If NZ, forcing row. */
char w_flag; /* Flags. */
LIST_HEAD(, undo_rec) w_undo; /* Undo actions list */
- REGION w_undopos; /* Where we were during the last
+ int w_undopos; /* Where we were during the last
undo action */
struct undo_rec *w_undoptr;
} MGWIN;
diff --git a/usr.bin/mg/undo.c b/usr.bin/mg/undo.c
index a4ea6c6c8f5..5735fa71cd1 100644
--- a/usr.bin/mg/undo.c
+++ b/usr.bin/mg/undo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: undo.c,v 1.22 2003/11/09 01:44:39 vincent Exp $ */
+/* $OpenBSD: undo.c,v 1.23 2003/11/29 17:28:40 vincent Exp $ */
/*
* Copyright (c) 2002 Vincent Labrecque
* All rights reserved.
@@ -222,12 +222,10 @@ undo_add_insert(LINE *lp, int offset, int size)
* We try to reuse the last undo record to `compress' things.
*/
rec = LIST_FIRST(&curwp->w_undo);
- if (rec != NULL) {
- if (rec->type == INSERT) {
- if (rec->pos + rec->region.r_size == pos) {
- rec->region.r_size += reg.r_size;
- return (TRUE);
- }
+ if (rec != NULL && rec->type == INSERT) {
+ if (rec->pos + rec->region.r_size == pos) {
+ rec->region.r_size += reg.r_size;
+ return (TRUE);
}
}
@@ -277,8 +275,7 @@ undo_add_delete(LINE *lp, int offset, int size)
if (rec->type == DELETE) {
if (rec->pos - rec->region.r_size != pos)
undo_add_boundary();
- } else if (rec->type != BOUNDARY)
- undo_add_boundary();
+ }
}
rec = new_undo_record();
rec->pos = pos;
@@ -414,14 +411,14 @@ undo(int f, int n)
struct undo_rec *ptr, *nptr;
int done, rval;
LINE *lp;
- int offset, save;
+ int offset, save, dot;
+
+ dot = find_absolute_dot(curwp->w_dotp, curwp->w_doto);
ptr = curwp->w_undoptr;
/* if we moved, make ptr point back to the top of the list */
- if ((curwp->w_undopos.r_linep != curwp->w_dotp) ||
- (curwp->w_undopos.r_offset != curwp->w_doto) ||
- (ptr == NULL))
+ if (ptr == NULL || curwp->w_undopos != dot)
ptr = LIST_FIRST(&curwp->w_undo);
rval = TRUE;
@@ -507,8 +504,8 @@ undo(int f, int n)
* since we change the dot when undoing....)
*/
curwp->w_undoptr = ptr;
- curwp->w_undopos.r_linep = curwp->w_dotp;
- curwp->w_undopos.r_offset = curwp->w_doto;
+
+ curwp->w_undopos = find_absolute_dot(curwp->w_dotp, curwp->w_doto);
return (rval);
}
diff --git a/usr.bin/mg/window.c b/usr.bin/mg/window.c
index 1d75d054f8c..d4cddce1905 100644
--- a/usr.bin/mg/window.c
+++ b/usr.bin/mg/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.13 2003/10/27 11:21:12 vincent Exp $ */
+/* $OpenBSD: window.c,v 1.14 2003/11/29 17:28:39 vincent Exp $ */
/*
* Window handling.
@@ -26,7 +26,7 @@ new_window(BUFFER *bp)
bp->b_nwnd++;
LIST_INIT(&wp->w_undo);
wp->w_undoptr = NULL;
- memset(&wp->w_undopos, 0, sizeof wp->w_undopos);
+ wp->w_undopos = 0;
return (wp);
}