summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorKjell Wooding <kjell@cvs.openbsd.org>2005-12-20 04:58:11 +0000
committerKjell Wooding <kjell@cvs.openbsd.org>2005-12-20 04:58:11 +0000
commit337f1d9087664d350d7348986d75d2d911e2793b (patch)
tree685849ee14ee757d90140ff43e166aaf34f19f7b /usr.bin
parent832d367131629a882e3b7b49b6e52c98710678df (diff)
Fix broken "Undo of undo" when line is empty. Noticed by theo.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mg/line.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/usr.bin/mg/line.c b/usr.bin/mg/line.c
index 19d293fbc8e..49a718d9c3a 100644
--- a/usr.bin/mg/line.c
+++ b/usr.bin/mg/line.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: line.c,v 1.34 2005/12/13 05:40:33 kjell Exp $ */
+/* $OpenBSD: line.c,v 1.35 2005/12/20 04:58:10 kjell Exp $ */
/* This file is in the public domain. */
@@ -315,17 +315,14 @@ lnewline_at(struct line *lp1, int doto)
struct line *lp2;
int nlen;
struct mgwin *wp;
- int retval = TRUE;
lchange(WFHARD);
- /* avoid unnecessary copying */
+ /* If start of line, allocate a new line instead of copying */
if (doto == 0) {
/* new first part */
- if ((lp2 = lalloc(0)) == NULL) {
- retval = FALSE;
- goto lnl_done;
- }
+ if ((lp2 = lalloc(0)) == NULL)
+ return (FALSE);
lp2->l_bp = lp1->l_bp;
lp1->l_bp->l_fp = lp2;
lp2->l_fp = lp1;
@@ -333,17 +330,18 @@ lnewline_at(struct line *lp1, int doto)
for (wp = wheadp; wp != NULL; wp = wp->w_wndp)
if (wp->w_linep == lp1)
wp->w_linep = lp2;
- goto lnl_done;
+ undo_add_boundary();
+ undo_add_insert(lp2, 0, 1);
+ undo_add_boundary();
+ return (TRUE);
}
/* length of new part */
nlen = llength(lp1) - doto;
/* new second half line */
- if ((lp2 = lalloc(nlen)) == NULL) {
- retval = FALSE;
- goto lnl_done;
- }
+ if ((lp2 = lalloc(nlen)) == NULL)
+ return (FALSE);
if (nlen != 0)
bcopy(&lp1->l_text[doto], &lp2->l_text[0], nlen);
lp1->l_used = doto;
@@ -362,11 +360,10 @@ lnewline_at(struct line *lp1, int doto)
wp->w_marko -= doto;
}
}
-lnl_done:
undo_add_boundary();
undo_add_insert(lp1, llength(lp1), 1);
undo_add_boundary();
- return (retval);
+ return (TRUE);
}
/*