From 2e8923e2e70dd958648287bc192918b2387eb75f Mon Sep 17 00:00:00 2001 From: dylan <> Date: Fri, 5 May 2023 12:05:02 -0700 Subject: [PATCH] fix selection on tab key --- editmode.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/editmode.ts b/editmode.ts index 904fb1a..460b6a7 100644 --- a/editmode.ts +++ b/editmode.ts @@ -48,7 +48,7 @@ const codeTabState = { }, indent(indentString: string) { const lines = this.code.split("\n"); - const {focusY, anchorY} = this; + const {focusX, focusY, anchorX, anchorY} = this; const newLines = lines.map((line, i) => { console.log(i, Math.min(focusY, anchorY), Math.max(focusY, anchorY)); if (i >= Math.min(focusY, anchorY) && i <= Math.max(focusY, anchorY)) { @@ -59,10 +59,11 @@ const codeTabState = { } }); this.code = newLines.join("\n"); + this.setSelection({x: anchorX+1, y: anchorY}, {x: focusX+1, y: focusY}); }, outdent(outdentRegex: RegExp) { const lines = this.code.split("\n"); - const {focusY, anchorY} = this; + const {focusX, focusY, anchorX, anchorY} = this; const newLines = lines.map((line, i) => { const match = line.match(outdentRegex); if (i >= Math.min(focusY, anchorY) && i <= Math.max(focusY, anchorY) && match) { @@ -72,6 +73,7 @@ const codeTabState = { } }); this.code = newLines.join("\n"); + this.setSelection({x: Math.max(0,anchorX-1), y: anchorY}, {x: Math.max(0,focusX-1), y: focusY}); }, backspace() { const {code, focus} = this;