forked from LeetCode-OpenSource/vscode-leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleetCodeSubmissionProvider.ts
56 lines (47 loc) · 1.79 KB
/
leetCodeSubmissionProvider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) jdneo. All rights reserved.
// Licensed under the MIT license.
import { ViewColumn } from "vscode";
import { openKeybindingsEditor, promptHintMessage } from "../utils/uiUtils";
import { ILeetCodeWebviewOption, LeetCodeWebview } from "./LeetCodeWebview";
import { markdownEngine } from "./markdownEngine";
class LeetCodeSubmissionProvider extends LeetCodeWebview {
protected readonly viewType: string = "leetcode.submission";
private result: string;
public show(result: string): void {
this.result = result;
this.showWebviewInternal();
this.showKeybindingsHint();
}
protected getWebviewOption(): ILeetCodeWebviewOption {
return {
title: "Submission",
viewColumn: ViewColumn.Two,
};
}
protected getWebviewContent(): string {
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
${markdownEngine.getStyles()}
</head>
<body>
<pre><code>${this.result.trim()}</code></pre>
</body>
</html>`;
}
protected onDidDisposeWebview(): void {
super.onDidDisposeWebview();
delete this.result;
}
private async showKeybindingsHint(): Promise<void> {
await promptHintMessage(
"hint.commandShortcut",
'You can customize shortcut key bindings in File > Preferences > Keyboard Shortcuts with query "leetcode".',
"Open Keybindings",
(): Promise<any> => openKeybindingsEditor("leetcode solution"),
);
}
}
export const leetCodeSubmissionProvider: LeetCodeSubmissionProvider = new LeetCodeSubmissionProvider();