@@ -10,8 +10,8 @@ import {
1010 Disposable ,
1111} from "vscode" ;
1212import { treeViewController } from "../controller/TreeViewController" ;
13+ import { remarkDao } from "../dao/remarkDao" ;
1314import { RemarkComment } from "../model/Model" ;
14- import { getRemakeName } from "../utils/SystemUtils" ;
1515
1616class RemarkService implements Disposable {
1717 private _remarkComment ;
@@ -44,7 +44,7 @@ class RemarkService implements Disposable {
4444 } ;
4545 }
4646
47- public startRemark ( document : TextDocument ) {
47+ public async startRemark ( document : TextDocument ) {
4848 let docInfo = this . getQidByDocument ( document ) ;
4949 if ( docInfo [ "qid" ] == undefined ) {
5050 return ;
@@ -54,12 +54,17 @@ class RemarkService implements Disposable {
5454 this . _qid_map_thread . get ( docInfo [ "qid" ] ) ?. dispose ( ) ;
5555 this . _qid_map_thread . delete ( docInfo [ "qid" ] ) ;
5656 }
57+ let oldRemark = await this . getOldThreadRemarkByQid ( docInfo [ "qid" ] ) ;
5758 for ( let i : number = 0 ; i < document . lineCount ; i ++ ) {
5859 const lineContent : string = document . lineAt ( i ) . text ;
5960 if ( lineContent . indexOf ( "@lc code=start" ) >= 0 ) {
60- let newRemark = this . _remarkComment . createCommentThread ( document . uri , new Range ( i - 1 , 0 , i - 1 , 0 ) , [ ] ) ;
61- newRemark . contextValue = `qid:${ docInfo [ "qid" ] } ` ;
62- newRemark . label = `${ docInfo [ "fid" ] } 题` ;
61+ let newRemark = this . _remarkComment . createCommentThread ( document . uri , new Range ( i - 1 , 0 , i - 1 , 0 ) , oldRemark ) ;
62+ newRemark . comments . forEach ( ( element ) => {
63+ element . parent = newRemark ;
64+ } ) ;
65+
66+ newRemark . contextValue = `qid=${ docInfo [ "qid" ] } ` ;
67+ newRemark . label = `${ docInfo [ "fid" ] } ` ;
6368 newRemark . collapsibleState = CommentThreadCollapsibleState . Expanded ;
6469 this . _qid_map_thread . set ( docInfo [ "qid" ] , newRemark ) ;
6570 break ;
@@ -76,16 +81,12 @@ class RemarkService implements Disposable {
7681 }
7782
7883 public remarkDeleteNoteComment ( comment : RemarkComment ) {
79- let thread = comment . parent ;
80- if ( ! thread ) {
84+ if ( ! comment . parent ) {
8185 return ;
8286 }
8387
84- thread . comments = thread . comments . filter ( ( cmt ) => ( cmt as RemarkComment ) . id !== comment . id ) ;
85-
86- // if (thread.comments.length === 0) {
87- // thread.dispose();
88- // }
88+ comment . parent . comments = comment . parent . comments . filter ( ( cmt ) => ( cmt as RemarkComment ) . id !== comment . id ) ;
89+ this . saveThreadRemark ( comment . parent ) ;
8990 }
9091
9192 public remarkCancelsaveNote ( comment : RemarkComment ) {
@@ -100,19 +101,10 @@ class RemarkService implements Disposable {
100101
101102 return cmt ;
102103 } ) ;
104+ this . saveThreadRemark ( comment . parent ) ;
103105 }
104106 public remarkSaveNote ( comment : RemarkComment ) {
105- if ( ! comment . parent ) {
106- return ;
107- }
108-
109- comment . parent . comments = comment . parent . comments . map ( ( cmt ) => {
110- if ( ( cmt as RemarkComment ) . id === comment . id ) {
111- cmt . mode = CommentMode . Preview ;
112- }
113-
114- return cmt ;
115- } ) ;
107+ this . remarkCancelsaveNote ( comment ) ;
116108 }
117109 public remarkEditNote ( comment : RemarkComment ) {
118110 if ( ! comment . parent ) {
@@ -126,12 +118,49 @@ class RemarkService implements Disposable {
126118
127119 return cmt ;
128120 } ) ;
121+
122+ this . saveThreadRemark ( comment . parent ) ;
129123 }
130124
131125 public replyNote ( reply : CommentReply ) {
132126 let thread = reply . thread ;
133- let newComment = new RemarkComment ( reply . text , CommentMode . Preview , { name : getRemakeName ( ) } , thread , "canDelete" ) ;
127+ let newComment = new RemarkComment ( reply . text , thread ) ;
134128 thread . comments = [ ...thread . comments , newComment ] ;
129+ this . saveThreadRemark ( thread ) ;
130+ }
131+
132+ public saveThreadRemark ( thread ) {
133+ const params : URLSearchParams = new URLSearchParams ( thread . contextValue ) ;
134+ let qid = params . get ( "qid" ) ;
135+ if ( ! qid ) {
136+ return ;
137+ }
138+ let data : Array < any > = [ ] ;
139+ thread . comments . forEach ( ( element ) => {
140+ data . push ( element . getDbData ( ) ) ;
141+ } ) ;
142+ let remarkData = { } ;
143+ remarkData [ "data" ] = data ;
144+ remarkDao . setInfoByQid ( qid , remarkData ) ;
145+ }
146+ public async getOldThreadRemarkByQid ( qid : string , thread ?) {
147+ let remarkData = await remarkDao . getInfoByQid ( qid ) ;
148+ let remarkDataBody = remarkData [ "data" ] || [ ] ;
149+ let OldRemark : Array < any > = [ ] ;
150+ remarkDataBody . forEach ( ( element ) => {
151+ OldRemark . push ( RemarkComment . getObjByDbData ( element , thread ) ) ;
152+ } ) ;
153+ return OldRemark ;
154+ }
155+
156+ public remarkClose ( thread ) {
157+ const params : URLSearchParams = new URLSearchParams ( thread . contextValue ) ;
158+ let qid = params . get ( "qid" ) ;
159+ if ( ! qid ) {
160+ return ;
161+ }
162+
163+ this . _qid_map_thread . get ( qid ) ?. dispose ( ) ;
135164 }
136165
137166 public dispose ( ) : void { }
0 commit comments