1
1
import { FC , useEffect , useMemo , useRef , useState } from "react" ;
2
- import { DiffEditor , Editor } from "@monaco-editor/react" ;
2
+ import { Editor } from "@monaco-editor/react" ;
3
3
4
4
// import * as monaco from "monaco-editor";
5
5
import {
@@ -14,21 +14,20 @@ const { useToken } = theme;
14
14
const FileCoverageDetail : FC < {
15
15
fileContent : string ;
16
16
fileCodeChange : number [ ] ;
17
- fileCodeChangeContent : string ;
18
17
fileCoverage : any ;
19
- } > = ( { fileContent, fileCoverage, fileCodeChange, fileCodeChangeContent } ) => {
18
+ } > = ( { fileContent, fileCoverage, fileCodeChange } ) => {
20
19
const { token } = useToken ( ) ;
21
20
const { lines } = coreFn ( fileCoverage , fileContent ) ;
22
21
23
22
const linesState = useMemo ( ( ) => {
24
23
return lines . map ( ( line , index ) => {
25
24
return {
26
25
lineNumber : index + 1 ,
27
- change : false ,
26
+ change : fileCodeChange . includes ( index + 1 ) ,
28
27
hit : line . executionNumber ,
29
28
} ;
30
29
} ) ;
31
- } , [ lines ] ) ;
30
+ } , [ lines , fileCodeChange ] ) ;
32
31
33
32
const lineNumbersMinChars = useMemo ( ( ) => {
34
33
const maxHit = Math . max ( ...linesState . map ( ( line ) => line . hit ) ) ;
@@ -63,20 +62,7 @@ const FileCoverageDetail: FC<{
63
62
}
64
63
useEffect ( ( ) => {
65
64
if ( editor ) {
66
- let needDeltaDecorationsEditor = null ;
67
-
68
- if ( fileCodeChangeContent ) {
69
- const originalEditor = editor . getOriginalEditor ( ) ;
70
- originalEditor . updateOptions ( {
71
- lineNumbers : false ,
72
- } ) ;
73
- const modifiedEditor = editor . getModifiedEditor ( ) ;
74
- needDeltaDecorationsEditor = modifiedEditor ;
75
- } else {
76
- needDeltaDecorationsEditor = editor ;
77
- }
78
-
79
- needDeltaDecorationsEditor ?. deltaDecorations ?.(
65
+ editor ?. deltaDecorations ?.(
80
66
[ ] , // oldDecorations 每次清空上次标记的
81
67
decorations . map (
82
68
( { inlineClassName, startLine, startCol, endLine, endCol } ) => ( {
@@ -105,70 +91,36 @@ const FileCoverageDetail: FC<{
105
91
// border: "1px solid " + token.colorBorder,
106
92
} }
107
93
>
108
- { fileCodeChangeContent ? (
109
- < DiffEditor
110
- original = { fileCodeChangeContent }
111
- modified = { fileContent }
112
- // theme={"vs-dark"}
113
- height = { "calc(100vh - 200px)" }
114
- // height={`${18 * (lineCount + 1)}px`}
115
- language = { "javascript" }
116
- onMount = { handleEditorDidMount }
117
- options = { {
118
- lineHeight : 18 ,
119
- lineNumbers : ( lineNumber ) => {
120
- return lineNumbers (
121
- lineNumber ,
122
- linesState ,
123
- token . colorBgBase === "#000" ,
124
- ) ;
125
- } ,
126
- lineNumbersMinChars : lineNumbersMinChars ,
127
- readOnly : true ,
128
- folding : false ,
129
- minimap : { enabled : false } ,
130
- scrollBeyondLastLine : false ,
131
- showUnused : false ,
132
- fontSize : 12 ,
133
- fontFamily : "IBMPlexMono" ,
134
- scrollbar : {
135
- // handleMouseWheel: false,
136
- } ,
137
- contextmenu : false ,
138
- } }
139
- />
140
- ) : (
141
- < Editor
142
- value = { fileContent }
143
- theme = { token . colorBgBase === "#000" ? "nightOwl" : "vs" }
144
- height = { "calc(100vh - 200px)" }
145
- // height={`${18 * (lineCount + 1)}px`}
146
- language = { "javascript" }
147
- onMount = { handleEditorDidMount }
148
- options = { {
149
- lineHeight : 18 ,
150
- lineNumbers : ( lineNumber ) => {
151
- return lineNumbers (
152
- lineNumber ,
153
- linesState ,
154
- token . colorBgBase === "#000" ,
155
- ) ;
156
- } ,
157
- lineNumbersMinChars : lineNumbersMinChars ,
158
- readOnly : true ,
159
- folding : false ,
160
- minimap : { enabled : false } ,
161
- scrollBeyondLastLine : false ,
162
- showUnused : false ,
163
- fontSize : 12 ,
164
- fontFamily : "IBMPlexMono" ,
165
- scrollbar : {
166
- // handleMouseWheel: false,
167
- } ,
168
- contextmenu : false ,
169
- } }
170
- />
171
- ) }
94
+ < Editor
95
+ value = { fileContent }
96
+ theme = { token . colorBgBase === "#000" ? "nightOwl" : "vs" }
97
+ height = { "calc(100vh - 200px)" }
98
+ // height={`${18 * (lineCount + 1)}px`}
99
+ language = { "javascript" }
100
+ onMount = { handleEditorDidMount }
101
+ options = { {
102
+ lineHeight : 18 ,
103
+ lineNumbers : ( lineNumber ) => {
104
+ return lineNumbers (
105
+ lineNumber ,
106
+ linesState ,
107
+ token . colorBgBase === "#000" ,
108
+ ) ;
109
+ } ,
110
+ lineNumbersMinChars : lineNumbersMinChars ,
111
+ readOnly : true ,
112
+ folding : false ,
113
+ minimap : { enabled : false } ,
114
+ scrollBeyondLastLine : false ,
115
+ showUnused : false ,
116
+ fontSize : 12 ,
117
+ fontFamily : "IBMPlexMono" ,
118
+ scrollbar : {
119
+ // handleMouseWheel: false,
120
+ } ,
121
+ contextmenu : false ,
122
+ } }
123
+ />
172
124
</ div >
173
125
) ;
174
126
} ;
0 commit comments