Skip to content

Commit b4864cc

Browse files
shirsho-12heyzec
authored andcommitted
Save editor on reset
1 parent a340f00 commit b4864cc

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/utils/editor.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,31 @@ export class Editor {
197197
this.onChangeCallback = callback;
198198
}
199199

200-
reset(prepend: string, initialCode: string) {
200+
async save() {
201+
this.log(`EXTENSION: Editor's save called`);
202+
if (!this.editor) {
203+
this.log(`EXTENSION: Editor is not defined, cannot save`);
204+
return;
205+
}
206+
const text = this.editor.document.getText();
207+
if (text === "") {
208+
this.log(`EXTENSION: Editor's code is empty, not saving`);
209+
return;
210+
}
211+
await vscode.workspace.fs.writeFile(
212+
vscode.Uri.file(this.editor.document.fileName),
213+
new TextEncoder().encode(text),
214+
);
215+
this.log(`EXTENSION: Editor's code saved successfully`);
216+
//?: Send the code to the frontend - if needed
217+
// const message = Messages.Text(
218+
// this.workspaceLocation,
219+
// text,
220+
// );
221+
// sendToFrontendWrapped(message);
222+
}
223+
224+
async reset(prepend: string, initialCode: string) {
201225
this.log(`EXTENSION: Editor's reset called`);
202226
this.replace(
203227
prepend !== ""
@@ -210,5 +234,7 @@ export class Editor {
210234
: initialCode,
211235
"reset",
212236
);
237+
await this.save();
238+
this.log(`EXTENSION: Editor's code reset successfully`);
213239
}
214240
}

0 commit comments

Comments
 (0)