shithub: orca

Download patch

ref: 5fbdddcb81fff06be473bddc64748ac0fb86edba
parent: b1ebc6412e1b0e40fc4ee2f6c3c67428a3e1480f
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Feb 13 18:56:03 EST 2020

plan9: handle grid resizing and make field snap to grid when resizing

--- a/plan9.c
+++ b/plan9.c
@@ -450,6 +450,22 @@
 	}
 }
 
+static int
+snaplow(int n, int gridn)
+{
+	n--;
+	n -= (n % gridn) > 0 ? (n % gridn) : gridn;
+	return MAX(1, n+1);
+}
+
+static int
+snaphigh(int n, int gridn)
+{
+	n += gridn;
+	n -= n % gridn - 1;
+	return n;
+}
+
 static void
 screensize(int *w, int *h)
 {
@@ -717,17 +733,29 @@
 			case 0x16: /* C-v */
 				selpaste();
 				break;
+			case '[':
+				gridw = MAX(4, gridw-1);
+				break;
+			case ']':
+				gridw = MIN(16, gridw+1);
+				break;
+			case '{':
+				gridh = MAX(4, gridh-1);
+				break;
+			case '}':
+				gridh = MIN(16, gridh+1);
+				break;
 			case '(':
-				w = MAX(1, w-gridw);
+				w = snaplow(w, gridw);
 				break;
 			case ')':
-				w += gridw;
+				w = snaphigh(w, gridw);
 				break;
 			case '_':
-				h = MAX(1, h-gridh);
+				h = snaplow(h, gridh);
 				break;
 			case '+':
-				h += gridh;
+				h = snaphigh(h, gridh);
 				break;
 			case '>':
 				bpm++;