more tweaks
diff --git a/src/cmd/acme/acme.c b/src/cmd/acme/acme.c
index 6df7374..9c3156e 100644
--- a/src/cmd/acme/acme.c
+++ b/src/cmd/acme/acme.c
@@ -287,6 +287,7 @@
 	w->body.file->mod = FALSE;
 	w->dirty = FALSE;
 	winsettag(w);
+	winresize(w, w->r, FALSE, TRUE);
 	textscrdraw(&w->body);
 	textsetselect(&w->tag, w->tag.file->b.nc, w->tag.file->b.nc);
 }
diff --git a/src/cmd/acme/dat.h b/src/cmd/acme/dat.h
index 8ac265c..d443888 100644
--- a/src/cmd/acme/dat.h
+++ b/src/cmd/acme/dat.h
@@ -192,6 +192,7 @@
 	int		ncachealloc;
 	Rune	*cache;
 	int	nofill;
+	int	needundo;
 };
 
 uint		textbacknl(Text*, uint, uint);
diff --git a/src/cmd/acme/text.c b/src/cmd/acme/text.c
index adde0dd..0e08910 100644
--- a/src/cmd/acme/text.c
+++ b/src/cmd/acme/text.c
@@ -859,6 +859,16 @@
 			u->cq0 = t->q0;
 		else if(t->q0 != u->cq0+u->ncache)
 			error("text.type cq1");
+		/*
+		 * Change the tag before we add to ncache,
+		 * so that if the window body is resized the
+		 * commit will not find anything in ncache.
+		 */
+		if(u->what==Body && u->ncache == 0){
+			u->needundo = TRUE;
+			winsettag(t->w);
+			u->needundo = FALSE;
+		}
 		textinsert(u, t->q0, rp, nr, FALSE);
 		if(u != t)
 			textsetselect(u, u->q0, u->q1);
diff --git a/src/cmd/acme/wind.c b/src/cmd/acme/wind.c
index 762fb9d..2b0369d 100644
--- a/src/cmd/acme/wind.c
+++ b/src/cmd/acme/wind.c
@@ -124,7 +124,7 @@
 int
 winresize(Window *w, Rectangle r, int safe, int keepextra)
 {
-	int y, mouseintag;
+	int oy, y, mouseintag, tagresized;
 	Image *b;
 	Point p;
 	Rectangle br, r1;
@@ -141,7 +141,7 @@
 	r1.max.y = min(r.max.y, r1.min.y + w->taglines*font->height);
 	y = r1.max.y;
 	mouseintag = ptinrect(mouse->xy, w->tag.all);
-	if(1 || !safe || !w->tagsafe || !eqrect(w->tag.all, r1)){
+	if(!safe || !w->tagsafe || !eqrect(w->tag.all, r1)){
 
 		w->taglines = wintaglines(w, r);
 		w->tagsafe = TRUE;
@@ -151,8 +151,10 @@
 	r1 = r;
 	r1.max.y = min(r.max.y, r1.min.y + w->taglines*font->height);
 	y = r1.max.y;
+	tagresized = 0;
 	if(1 || !safe || !eqrect(w->tag.all, r1)){
-if(0) fprint(2, "resize tag %R => %R", w->tag.all, r1);
+		tagresized = 1;
+if(0) fprint(2, "resize tag %R => %R\n", w->tag.all, r1);
 		textresize(&w->tag, r1, TRUE);
 if(0) fprint(2, "=> %R (%R)\n", w->tag.all, w->tag.fr.r);
 		y = w->tag.fr.r.max.y;
@@ -175,7 +177,9 @@
 	
 	r1 = r;
 	r1.min.y = y;
-	if(1 || !safe || !eqrect(w->body.all, r1)){
+	if(tagresized || !safe || !eqrect(w->body.all, r1)){
+		oy = y;
+if(0) fprint(2, "resizing body; safe=%d all=%R r1=%R\n", safe, w->body.all, r1);
 		if(y+1+w->body.fr.font->height <= r.max.y){	/* room for one line */
 			r1.min.y = y;
 			r1.max.y = y+1;
@@ -187,11 +191,12 @@
 			r1.min.y = y;
 			r1.max.y = y;
 		}
-if(0) fprint(2, "resize body %R => %R", w->body.all, r1);
+if(0) fprint(2, "resizing body; new r=%R; r1=%R\n", r, r1);
 		w->r = r;
 		w->r.max.y = textresize(&w->body, r1, keepextra);
-if(0) fprint(2, " => %R (%R; %R)\n", w->body.all, w->body.fr.r, w->r);
+if(0) fprint(2, "after textresize: body.all=%R\n", w->body.all);
 		textscrdraw(&w->body);
+		w->body.all.min.y = oy;
 	}
 	w->maxlines = min(w->body.fr.nlines, max(w->maxlines, w->body.fr.maxlines));
 	return w->r.max.y;
@@ -446,7 +451,7 @@
 	runemove(new+i, Ldelsnarf, 10);
 	i += 10;
 	if(w->filemenu){
-		if(w->body.file->delta.nc>0 || w->body.ncache){
+		if(w->body.needundo || w->body.file->delta.nc>0 || w->body.ncache){
 			runemove(new+i, Lundo, 5);
 			i += 5;
 		}
@@ -523,8 +528,10 @@
 	br.max.x = br.min.x + Dx(b->r);
 	br.max.y = br.min.y + Dy(b->r);
 	draw(screen, br, b, nil, b->r.min);
-	if(resize)
+	if(resize){
+		w->tagsafe = 0;
 		winresize(w, w->r, TRUE, TRUE);
+	}
 }
 
 void