shithub: orca

Download patch

ref: e97ec5a63c8bde0ae93289e128bca6a1583fa654
parent: 91d13854e587eae5f4928a042055cb471fc091a5
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Feb 12 19:05:52 EST 2020

plan9: sliding mode

--- a/plan9.c
+++ b/plan9.c
@@ -40,6 +40,8 @@
 static Oevent_list events;
 static char filename[256];
 static Channel *cchan;
+static Field copyfield;
+static int altdown;
 
 static char *menu3i[] = {
 	"load",
@@ -241,7 +243,7 @@
 
 	/* insert/append mode */
 	p.y += font->height;
-	len = runesprint(linebuf, "%s", insert ? "insert" : "append");
+	len = runesprint(linebuf, "%s", altdown ? "slide " : (insert ? "insert" : "append"));
 	runestring(screen, p, display->white, ZP, font, linebuf);
 
 	/* bpm */
@@ -310,6 +312,34 @@
 }
 
 static void
+selmove(int x, int y)
+{
+	int i;
+
+	field_resize_raw(&copyfield, selh, selw);
+	gbuffer_copy_subrect(
+		field.buffer,
+		copyfield.buffer,
+		field.height, field.width,
+		copyfield.height, copyfield.width,
+		cury, curx, 0, 0,
+		selh, selw
+	);
+
+	for (i = cury; i < cury+selh; i++)
+		memset(&field.buffer[curx + field.width*i], '.', selw);
+
+	gbuffer_copy_subrect(
+		copyfield.buffer,
+		field.buffer,
+		copyfield.height, copyfield.width,
+		field.height, field.width,
+		0, 0, cury+y, curx+x,
+		selh, selw
+	);
+}
+
+static void
 screensize(int *w, int *h)
 {
 	*w = (Dx(screen->r) - 2*Txtoff) / charw;
@@ -391,13 +421,12 @@
 threadmain(int argc, char **argv)
 {
 	Mousectl *mctl;
-	Field copyfield;
 	Key key;
 	Keyboardctl kctl;
 	Mouse m;
 	char tmp[256];
 	Channel *kchan;
-	int oldw, oldh, w, h, n, shiftdown, altdown;
+	int oldw, oldh, w, h, n, shiftdown;
 	Alt a[] = {
 		{ nil, &m, CHANRCV },
 		{ nil, nil, CHANRCV },
@@ -427,7 +456,7 @@
 	a[0].c = mctl->c;
 	a[1].c = mctl->resizec;
 	a[2].c = kchan;
-	a[3].c = chancreate(sizeof(ulong), 0); /* FIXME should it be buffered instead? */
+	a[3].c = chancreate(sizeof(ulong), 0);
 	a[4].c = cchan;
 
 	curbg = allocimage(display, Rect(0, 0, 1, 1), RGBA32, 1, setalpha(DYellow, 128));
@@ -503,29 +532,41 @@
 			case Kup:
 				if (shiftdown)
 					selh = MAX(1, selh-1);
-				else if (!altdown)
+				else {
+					if (altdown)
+						selmove(0, -1);
 					cury = MAX(0, cury-1);
+				}
 				break;
 			case '\n': /* C-j */
 			case Kdown:
 				if (shiftdown)
 					selh++;
-				else if (!altdown)
+				else {
+					if (altdown)
+						selmove(0, 1);
 					cury = MIN(h-1, cury+1);
+				}
 				break;
 			case Kbs: /* C-h */
 			case Kleft:
 				if (shiftdown)
 					selw = MAX(1, selw-1);
-				else if (!altdown)
+				else {
+					if (altdown)
+						selmove(-1, 0);
 					curx = MAX(0, curx-1);
+				}
 				break;
 			case 0x0c: /* C-l */
 			case Kright:
 				if (shiftdown)
 					selw++;
-				else if (!altdown)
+				else {
+					if (altdown)
+						selmove(1, 0);
 					curx = MIN(w-1, curx+1);
+				}
 				break;
 			case Khome:
 				curx = 0;