From 0adfdabffa07e869d7e602971925f8ce91f3b7ab Mon Sep 17 00:00:00 2001
From: dylan <>
Date: Sat, 6 May 2023 12:24:40 -0700
Subject: [PATCH] Draw full text selection

---
 codetab.ts | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/codetab.ts b/codetab.ts
index 0cd0af2..cc14861 100644
--- a/codetab.ts
+++ b/codetab.ts
@@ -373,22 +373,18 @@ const drawCodeField = (code: string, x: number, y: number, w: number, h: number)
 		scrollY,
 		anchor,
 		focus,
+		focusX,
+		focusY,
 	} = state;
-	const {
-		x: focusX,
-		y: focusY,
-	} = indexToGrid(code, focus);
-	const {
-		x: anchorX,
-		y: anchorY,
-	} = indexToGrid(code, anchor);
 	fillRect(x, y, w, h, COLOR.DARKBLUE);
 	if (anchor === focus) {
 		fillRect(x+focusX*fontWidth-scrollX, y+focusY*(fontHeight+1)-scrollY, fontWidth+1, fontHeight+1, COLOR.YELLOW);
 	} else {
-		// TODO: Draw this selection better
-		fillRect(x+anchorX*fontWidth-scrollX, y+anchorY*(fontHeight+1)-scrollY, fontWidth+1, fontHeight+1, COLOR.WHITE);
-		fillRect(x+focusX*fontWidth-scrollX, y+focusY*(fontHeight+1)-scrollY, fontWidth+1, fontHeight+1, COLOR.YELLOW);
+		for (let i = Math.min(anchor, focus); i < Math.max(anchor, focus); i++) {
+			const {x: selX, y: selY} = indexToGrid(code, i);
+			fillRect(x+selX*fontWidth-scrollX, y+selY*(fontHeight+1)-scrollY, fontWidth+1, fontHeight+1, COLOR.WHITE);
+		}
+		// fillRect(x+focusX*fontWidth-scrollX, y+focusY*(fontHeight+1)-scrollY, fontWidth+1, fontHeight+1, COLOR.YELLOW);
 	}
 	const builtins = Object.keys(getContext());
 	const tokens = [...tokenize(code)];