delete key

This commit is contained in:
dylan 2023-05-05 12:10:01 -07:00
parent 2e8923e2e7
commit 99655e663c

View File

@ -50,9 +50,7 @@ const codeTabState = {
const lines = this.code.split("\n"); const lines = this.code.split("\n");
const {focusX, focusY, anchorX, anchorY} = this; const {focusX, focusY, anchorX, anchorY} = this;
const newLines = lines.map((line, i) => { 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)) { if (i >= Math.min(focusY, anchorY) && i <= Math.max(focusY, anchorY)) {
console.log(indentString+line);
return indentString+line; return indentString+line;
} else { } else {
return line; return line;
@ -86,6 +84,16 @@ const codeTabState = {
this.insertText(""); this.insertText("");
} }
}, },
delete() {
const {code, focus} = this;
if (this.isCollapsed()) {
if (focus < code.length) {
this.code = code.slice(0, focus) + code.slice(1+focus);
}
} else {
this.insertText("");
}
},
get code() { get code() {
return getSheet(0); return getSheet(0);
}, },
@ -164,6 +172,9 @@ const update = () => {
if (keyPressed(K.BACKSPACE)) { if (keyPressed(K.BACKSPACE)) {
codeTabState.backspace(); codeTabState.backspace();
} }
if (keyPressed(K.DELETE)) {
codeTabState.delete();
}
if (keyPressed(K.ARROW_RIGHT)) { if (keyPressed(K.ARROW_RIGHT)) {
if (shiftKeyDown()) { if (shiftKeyDown()) {
codeTabState.setFocus(focus+1); codeTabState.setFocus(focus+1);