Make enter play nicer with indentation

This commit is contained in:
dylan
2023-05-06 11:45:59 -07:00
parent 3ad23f3a91
commit 550f1b44b2
2 changed files with 14 additions and 2 deletions

View File

@ -163,6 +163,18 @@ const state = {
this.scrollX = focusX*fw-128+fw;
}
},
currentIndentation() {
const lines = this.code.slice(0, this.focus).split("\n");
const line = lines[lines.length-1];
const match = line.match(/^\s*/);
if (!match) {
return "";
}
console.log(lines);
console.log(line);
console.log(match);
return match[0];
},
get code() {
return getCodeSheet(0);
},
@ -401,7 +413,7 @@ const update = async () => {
if (keyPressed(K.ENTER)) {
// TODO: Make this play nicely with indentation
state.insertText("\n");
state.insertText("\n"+state.currentIndentation());
state.scrollToCursor();
}
if (keyPressed(K.TAB)) {