Skip to content

Commit c2e3c15

Browse files
committed
Add "Save All" keybind (Fixes #39)
1 parent 13fe0bc commit c2e3c15

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@
201201
"title": "Delete All Testcases",
202202
"category": "Fast Olympic Coding"
203203
},
204+
{
205+
"command": "fastolympiccoding.saveAll",
206+
"title": "Save All Testcases",
207+
"category": "Fast Olympic Coding"
208+
},
204209
{
205210
"command": "fastolympiccoding.stressTest",
206211
"title": "Run Stress Test",
@@ -238,6 +243,11 @@
238243
"key": "ctrl+alt+d",
239244
"when": "view.fastolympiccoding.judge.visible"
240245
},
246+
{
247+
"command": "fastolympiccoding.saveAll",
248+
"key": "ctrl+alt+s",
249+
"when": "view.fastolympiccoding.judge.visible"
250+
},
241251
{
242252
"command": "fastolympiccoding.stressTest",
243253
"key": "ctrl+alt+g",
@@ -285,4 +295,4 @@
285295
"nu-observables": "^0.0.7",
286296
"preact": "^10.26.5"
287297
}
288-
}
298+
}

src/extension.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ function registerCommands(context: vscode.ExtensionContext): void {
102102
),
103103
);
104104

105+
context.subscriptions.push(
106+
vscode.commands.registerTextEditorCommand(
107+
'fastolympiccoding.saveAll',
108+
() => judgeViewProvider.saveAll(),
109+
),
110+
);
111+
105112
context.subscriptions.push(
106113
vscode.commands.registerTextEditorCommand(
107114
'fastolympiccoding.stressTest',

src/views/judge/message.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ export enum WebviewMessageType {
6666
SET = 1,
6767
STDIO = 2,
6868
DELETE = 3,
69-
SHOW = 4,
70-
INITIAL_STATE = 5,
69+
SAVE_ALL = 4,
70+
SHOW = 5,
71+
INITIAL_STATE = 6,
7172
}
7273
export interface INewMessage {
7374
type: WebviewMessageType.NEW;
@@ -89,6 +90,9 @@ export interface IDeleteMessage {
8990
type: WebviewMessageType.DELETE;
9091
id: number;
9192
}
93+
export interface ISaveAllMessage {
94+
type: WebviewMessageType.SAVE_ALL;
95+
}
9296
export interface IShowMessage {
9397
type: WebviewMessageType.SHOW;
9498
visible: boolean;
@@ -102,5 +106,6 @@ export type WebviewMessage =
102106
| ISetMessage
103107
| IStdioMessage
104108
| IDeleteMessage
109+
| ISaveAllMessage
105110
| IShowMessage
106111
| IInitialState;

src/views/judge/provider/JudgeViewProvider.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ export default class extends BaseViewProvider<ProviderMessage, WebviewMessage> {
222222
}
223223
}
224224

225+
saveAll() {
226+
super._postMessage({ type: WebviewMessageType.SAVE_ALL });
227+
}
228+
225229
private _nextTestcase() {
226230
void this._run(this._addTestcase(), true);
227231
}

src/views/judge/webview/App.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ window.addEventListener('message', (msg: MessageEvent<WebviewMessage>) => {
3636
case WebviewMessageType.DELETE:
3737
handleDelete(msg.data);
3838
break;
39+
case WebviewMessageType.SAVE_ALL:
40+
handleSaveAll();
41+
break;
3942
case WebviewMessageType.SHOW:
4043
handleShow(msg.data);
4144
break;
@@ -91,6 +94,24 @@ function handleDelete({ id }: IDeleteMessage) {
9194
testcases.delete(id);
9295
}
9396

97+
function handleSaveAll() {
98+
for (const [id, testcase] of testcases) {
99+
if (testcase.status === Status.EDITING) {
100+
const stdin = testcase.stdin;
101+
const acceptedStdout = testcase.acceptedStdout;
102+
// the extension host will send shortened version of both of these
103+
testcase.stdin = '';
104+
testcase.acceptedStdout = '';
105+
postProviderMessage({
106+
type: ProviderMessageType.SAVE,
107+
id,
108+
stdin,
109+
acceptedStdout,
110+
});
111+
}
112+
}
113+
}
114+
94115
function handleShow({ visible }: IShowMessage) {
95116
show.value = visible;
96117
}

0 commit comments

Comments
 (0)