shithub: pplay

Download patch

ref: 0ba7c95fb2a11cdecd7ddda8fa4cda791ae34d36
parent: 9a942b244c8a066bd511acfc86c04881844876d0
author: qwx <qwx@sciops.net>
date: Sun Jan 29 17:06:56 EST 2023

explicitely set insertion range or position

this ensures one can overwrite a range
instead of inserting at cursor
it's a hack; ranges should be generalized instead

--- a/chunk.c
+++ b/chunk.c
@@ -19,9 +19,9 @@
 
 	d = va_arg(fmt->args, Dot*);
 	if(d == nil)
-		return fmtstrcpy(fmt, "[??:??:??]");
-	return fmtprint(fmt, "[from=%08zux cur=%08zux to=%08zux]",
-		d->from, d->pos, d->to);
+		return fmtstrcpy(fmt, "[??:??:??:??]");
+	return fmtprint(fmt, "[from=%08zux cur=%08zux at=%08zux to=%08zux]",
+		d->from, d->pos, d->at, d->to);
 }
 
 int
@@ -269,6 +269,7 @@
 		dot.to = n;
 	if(dot.pos < dot.from || dot.pos > dot.to)
 		dot.pos = dot.from;
+	dot.at = -1ULL;
 	dprint(nil, "final %Δ\n", &dot);
 	totalsz = n;
 }
@@ -307,6 +308,7 @@
 		dot->to = c2p(norris->left) + norris->left->len;
 	else
 		dot->to = c2p(right);
+	dot->at = -1ULL;
 }
 
 void
--- a/cmd.c
+++ b/cmd.c
@@ -40,6 +40,7 @@
 	dot.to = to;
 	if(dot.pos < from || dot.pos >= to)
 		dot.pos = from;
+	dot.at = -1ULL;
 }
 
 int
@@ -50,6 +51,8 @@
 		return -1;
 	}
 	dot.pos = off;
+	if(dot.from == 0 && dot.to == totalsz)
+		dot.at = off;
 	return 0;
 }
 
@@ -129,15 +132,21 @@
 		fprint(2, "insert: nothing to paste\n");
 		return -1;
 	}
+	if(dot.at == -1ULL){
+		fprint(2, "insert: nowhere to paste\n");
+		return -1;
+	}
+	assert(dot.at <= dot.to);
 	dprint(nil, "cmd/insert %Δ\n", &dot);
 	dprint(c, "buffered\n");
-	pushop(OPins, dot.pos, dot.pos+chunklen(c)-1, nil);
-	if((left = insertat(dot.pos, c)) == nil){
+	pushop(OPins, dot.at, dot.at+chunklen(c)-1, nil);
+	if((left = insertat(dot.at, c)) == nil){
 		fprint(2, "insert: %r\n");
 		return -1;
 	}
 	setdot(&dot, nil);
 	dot.pos = c2p(left->right);
+	dot.at = -1ULL;
 	dprint(nil, "end\n");
 	return 1;
 }
@@ -150,10 +159,10 @@
 		return -1;
 	}
 	c = clone(c, c->left);
-	if(dot.from == 0 && dot.to == totalsz)
-		return insert(s, c);
-	else
+	if(dot.from > 0 || dot.to < totalsz)
 		return replace(s, c);
+	else
+		return insert(s, c);
 }
 
 static void
--- a/dat.h
+++ b/dat.h
@@ -21,6 +21,7 @@
 extern struct Dot{
 	usize pos;
 	usize from;
+	usize at;
 	usize to;
 };
 extern Dot dot;
--- a/draw.c
+++ b/draw.c
@@ -12,6 +12,7 @@
 	Cbg,
 	Csamp,
 	Cline,
+	Cins,
 	Cloop,
 	Cchunk,
 	Ctext,
@@ -181,6 +182,10 @@
 		seprint(s, s+sizeof s, " ↺ %τ - %τ", dot.from, dot.to);
 		p = string(screen, p, col[Cloop], ZP, font, s);
 	}
+	if(dot.at != -1ULL){
+		seprint(s, s+sizeof s, " ‡ %τ", dot.at);
+		p = string(screen, p, col[Cins], ZP, font, s);
+	}
 }
 
 static void
@@ -191,6 +196,7 @@
 		drawchunks();
 	drawpos(dot.from, col[Cloop]);
 	drawpos(dot.to, col[Cloop]);
+	drawpos(dot.at, col[Cins]);
 }
 
 void
@@ -372,6 +378,7 @@
 	col[Csamp] = eallocimage(Rect(0,0,1,1), 1, fuckit ? 0x555555FF : 0x2A2A2AFF);
 	col[Ctext] = eallocimage(Rect(0,0,1,1), 1, fuckit ? DBlack : 0xBBBBBBFF);
 	col[Cline] = eallocimage(Rect(0,0,1,1), 1, fuckit ? DPaleyellow: 0xEEA000FF);
+	col[Cins] = eallocimage(Rect(0,0,1,1), 1, fuckit ? DPaleblue: 0x509A9AFF);
 	col[Cloop] = eallocimage(Rect(0,0,1,1), 1, fuckit ? DPurpleblue: 0x8888CCFF);
 	col[Cchunk] = eallocimage(Rect(0,0,1,1), 1, 0xEE0000FF);
 	if((drawc = chancreate(sizeof(ulong), 4)) == nil)