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)];