shithub: jot

Download patch

ref: e34b96039a780995c19333f56bdb7c13e72462e4
parent: 9914a8da911d9fdfefd6b090870bbd385cacae69
author: aap <aap@papnet.eu>
date: Sun Jul 28 11:03:28 EDT 2024

updated text.c

--- a/inc.h
+++ b/inc.h
@@ -15,8 +15,6 @@
 enum {
 	FALSE = 0,
 	TRUE = 1,
-
-	BIG = 3,
 };
 
 #define ALT(c, v, t) (Alt){ c, v, t, nil, nil, 0 }
@@ -79,7 +77,6 @@
 void xpaste(Text *x);
 void xsend(Text *x);
 int xplumb(Text *w, char *src, char *dir, int maxsize);
-void freescrtemps(void);
 
 #define	runemalloc(n)		malloc((n)*sizeof(Rune))
 #define	runerealloc(a, n)	realloc(a, (n)*sizeof(Rune))
--- a/text.c
+++ b/text.c
@@ -111,6 +111,7 @@
 		w->org += n;
 	else if(q0 <= w->org+w->nchars)
 		frinsert(w, r, r+n, q0-w->org);
+	xscrdraw(w);
 	return q0;
 }
 
@@ -271,29 +272,6 @@
  * Scrolling
  */
 
-static Image *scrtmp;
-
-static Image*
-scrtemps(void)
-{
-	int h;
-
-	if(scrtmp == nil){
-		h = BIG*Dy(screen->r);
-		scrtmp = allocimage(display, Rect(0, 0, 32, h), screen->chan, 0, DNofill);
-	}
-	return scrtmp;
-}
-
-void
-freescrtemps(void)
-{
-	if(scrtmp){
-		freeimage(scrtmp);
-		scrtmp = nil;
-	}
-}
-
 static Rectangle
 scrpos(Rectangle r, uint p0, uint p1, uint tot)
 {
@@ -325,27 +303,17 @@
 void
 xscrdraw(Text *w)
 {
-	Rectangle r, r1, r2;
-	Image *b;
+	Rectangle r1, r2;
 
-	b = scrtemps();
-	if(b == nil || w->i == nil)
+	if(w->i == nil)
 		return;
-	r = w->scrollr;
-	r1 = r;
-	r1.min.x = 0;
-	r1.max.x = Dx(r);
+
+	r1 = w->scrollr;
 	r2 = scrpos(r1, w->org, w->org+w->nchars, w->nr);
 	if(!eqrect(r2, w->lastsr)){
 		w->lastsr = r2;
-		/* move r1, r2 to (0,0) to avoid clipping */
-		r2 = rectsubpt(r2, r1.min);
-		r1 = rectsubpt(r1, r1.min);
-		draw(b, r1, w->cols[BORD], nil, ZP);
-		draw(b, r2, w->cols[BACK], nil, ZP);
-		r2.min.x = r2.max.x-1;
-		draw(b, r2, w->cols[BORD], nil, ZP);
-		draw(w->i, r, b, nil, Pt(0, r1.min.y));
+		draw(w->i, r1, w->cols[BORD], nil, ZP);
+		draw(w->i, insetrect(r2,1), w->cols[BACK], nil, ZP);
 	}
 }