2
2
// Licensed under the MIT license.
3
3
4
4
import { ViewColumn } from "vscode" ;
5
- import { IProblem } from "../shared" ;
6
5
import { leetCodePreviewProvider } from "./leetCodePreviewProvider" ;
7
6
import { ILeetCodeWebviewOption , LeetCodeWebview } from "./LeetCodeWebview" ;
8
7
import { markdownEngine } from "./markdownEngine" ;
9
8
10
9
class LeetCodeSolutionProvider extends LeetCodeWebview {
11
10
12
11
protected readonly viewType : string = "leetcode.solution" ;
12
+ private problemName : string ;
13
13
private solution : Solution ;
14
14
15
- public show ( solutionString : string , problem : IProblem ) : void {
16
- this . solution = this . parseSolution ( solutionString , problem ) ;
15
+ public show ( solutionString : string ) : void {
16
+ this . solution = this . parseSolution ( solutionString ) ;
17
17
this . showWebviewInternal ( ) ;
18
18
}
19
19
20
20
protected getWebviewOption ( ) : ILeetCodeWebviewOption {
21
- if ( ! leetCodePreviewProvider . isSideMode ( ) ) {
22
- return {
23
- title : `${ this . solution . problem } : Solution` ,
24
- viewColumn : ViewColumn . One ,
25
- } ;
26
- } else {
21
+ if ( leetCodePreviewProvider . isSideMode ( ) ) {
27
22
return {
28
23
title : "Solution" ,
29
24
viewColumn : ViewColumn . Two ,
30
25
preserveFocus : true ,
31
26
} ;
27
+ } else {
28
+ return {
29
+ title : `Solution: ${ this . problemName } ` ,
30
+ viewColumn : ViewColumn . One ,
31
+ } ;
32
32
}
33
33
}
34
34
@@ -66,17 +66,17 @@ class LeetCodeSolutionProvider extends LeetCodeWebview {
66
66
delete this . solution ;
67
67
}
68
68
69
- private parseSolution ( raw : string , problem : IProblem ) : Solution {
69
+ private parseSolution ( raw : string ) : Solution {
70
+ raw = raw . slice ( 1 ) ; // skip first empty line
71
+ [ this . problemName , raw ] = raw . split ( / \n \n ( [ ^ ] + ) / ) ; // parse problem name and skip one line
70
72
const solution : Solution = new Solution ( ) ;
71
73
// [^] matches everything including \n, yet can be replaced by . in ES2018's `m` flag
72
- raw = raw . slice ( 1 ) ; // skip first empty line
73
- [ solution . title , raw ] = raw . split ( / \n \n ( [ ^ ] + ) / ) ; // parse title and skip one line
74
- [ solution . url , raw ] = raw . split ( / \n \n ( [ ^ ] + ) / ) ; // parse url and skip one line
74
+ [ solution . title , raw ] = raw . split ( / \n \n ( [ ^ ] + ) / ) ;
75
+ [ solution . url , raw ] = raw . split ( / \n \n ( [ ^ ] + ) / ) ;
75
76
[ solution . lang , raw ] = raw . match ( / \* L a n g : \s + ( .+ ) \n ( [ ^ ] + ) / ) ! . slice ( 1 ) ;
76
77
[ solution . author , raw ] = raw . match ( / \* A u t h o r : \s + ( .+ ) \n ( [ ^ ] + ) / ) ! . slice ( 1 ) ;
77
78
[ solution . votes , raw ] = raw . match ( / \* V o t e s : \s + ( \d + ) \n \n ( [ ^ ] + ) / ) ! . slice ( 1 ) ;
78
79
solution . body = raw ;
79
- solution . problem = problem . name ;
80
80
return solution ;
81
81
}
82
82
}
@@ -89,7 +89,6 @@ class Solution {
89
89
public author : string = "" ;
90
90
public votes : string = "" ;
91
91
public body : string = "" ; // Markdown supported
92
- public problem : string = "" ;
93
92
}
94
93
95
94
export const leetCodeSolutionProvider : LeetCodeSolutionProvider = new LeetCodeSolutionProvider ( ) ;
0 commit comments