22// Licensed under the MIT license.
33
44import { ViewColumn } from "vscode" ;
5- import { IProblem } from "../shared" ;
65import { leetCodePreviewProvider } from "./leetCodePreviewProvider" ;
76import { ILeetCodeWebviewOption , LeetCodeWebview } from "./LeetCodeWebview" ;
87import { markdownEngine } from "./markdownEngine" ;
98
109class LeetCodeSolutionProvider extends LeetCodeWebview {
1110
1211 protected readonly viewType : string = "leetcode.solution" ;
12+ private problemName : string ;
1313 private solution : Solution ;
1414
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 ) ;
1717 this . showWebviewInternal ( ) ;
1818 }
1919
2020 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 ( ) ) {
2722 return {
2823 title : "Solution" ,
2924 viewColumn : ViewColumn . Two ,
3025 preserveFocus : true ,
3126 } ;
27+ } else {
28+ return {
29+ title : `Solution: ${ this . problemName } ` ,
30+ viewColumn : ViewColumn . One ,
31+ } ;
3232 }
3333 }
3434
@@ -66,17 +66,17 @@ class LeetCodeSolutionProvider extends LeetCodeWebview {
6666 delete this . solution ;
6767 }
6868
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
7072 const solution : Solution = new Solution ( ) ;
7173 // [^] 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 ( [ ^ ] + ) / ) ;
7576 [ solution . lang , raw ] = raw . match ( / \* L a n g : \s + ( .+ ) \n ( [ ^ ] + ) / ) ! . slice ( 1 ) ;
7677 [ solution . author , raw ] = raw . match ( / \* A u t h o r : \s + ( .+ ) \n ( [ ^ ] + ) / ) ! . slice ( 1 ) ;
7778 [ solution . votes , raw ] = raw . match ( / \* V o t e s : \s + ( \d + ) \n \n ( [ ^ ] + ) / ) ! . slice ( 1 ) ;
7879 solution . body = raw ;
79- solution . problem = problem . name ;
8080 return solution ;
8181 }
8282}
@@ -89,7 +89,6 @@ class Solution {
8989 public author : string = "" ;
9090 public votes : string = "" ;
9191 public body : string = "" ; // Markdown supported
92- public problem : string = "" ;
9392}
9493
9594export const leetCodeSolutionProvider : LeetCodeSolutionProvider = new LeetCodeSolutionProvider ( ) ;
0 commit comments