Skip to content

Commit 81cd646

Browse files
committed
Fix: reset button functionality
1 parent b1af460 commit 81cd646

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/utils/editor.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,19 @@ export class Editor {
199199
) {
200200
this.onChangeCallback = callback;
201201
}
202+
203+
reset(prepend: string, initialCode: string) {
204+
this.log(`EXTENSION: Editor's reset called`);
205+
this.replace(
206+
prepend !== ""
207+
? [
208+
"// PREPEND -- DO NOT EDIT",
209+
prepend,
210+
"// END PREPEND",
211+
initialCode,
212+
].join("\n")
213+
: initialCode,
214+
"reset",
215+
);
216+
}
202217
}

src/utils/messageHandler.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ export class MessageHandler {
110110
sendToFrontend(this.panel, msg);
111111
break;
112112
}
113-
113+
case MessageTypeNames.ResetEditor:
114+
if (this.activeEditor) {
115+
this.activeEditor.reset("", message.initialCode);
116+
this.panel?.reveal(vscode.ViewColumn.Two);
117+
}
118+
break;
114119
case MessageTypeNames.NewEditor:
115120
this.activeEditor = await Editor.create(
116121
message.workspaceLocation,

src/utils/messages.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ const Messages = createMessages({
4848
EvalEditor: (workspaceLocation: VscWorkspaceLocation) => ({
4949
workspaceLocation: workspaceLocation,
5050
}),
51+
ResetEditor: (
52+
workspaceLocation: VscWorkspaceLocation,
53+
initialCode: string,
54+
) => ({
55+
workspaceLocation,
56+
initialCode,
57+
}),
5158
NotifyAssessmentsOverview: (
5259
assessmentOverviews: VscAssessmentOverview[],
5360
courseId: number,

0 commit comments

Comments
 (0)