@@ -192,13 +192,17 @@ export const getSyntaxDiffTemplateByFastDiff = ({
192192
193193 const changes = diffLine . diffChanges ;
194194
195+ const _changes = diffLine . _diffChanges ;
196+
195197 if ( ! changes || ! changes . hasLineChange ) return ;
196198
197199 const transform = isTransformEnabled ( ) ? processTransformTemplateContent : defaultTransform ;
198200
199201 let template = "" ;
200202
201- const allRange = changes . range . filter ( ( item ) => item . type !== 0 ) ;
203+ const allRange = changes ?. range ?. filter ( ( item ) => item . type !== 0 ) || [ ] ;
204+
205+ const _allRange = _changes ?. range ?. filter ( ( item ) => item . type !== 0 ) || [ ] ;
202206
203207 let rangeIndex = 0 ;
204208
@@ -209,6 +213,8 @@ export const getSyntaxDiffTemplateByFastDiff = ({
209213
210214 let range = allRange [ rangeIndex ] ;
211215
216+ const noDiff = allRange . length === 0 && _allRange . length === 0 ;
217+
212218 const isLastNode = index === array . length - 1 ;
213219
214220 for ( let i = 0 ; i < node . value . length ; i ++ ) {
@@ -220,9 +226,6 @@ export const getSyntaxDiffTemplateByFastDiff = ({
220226 // before start
221227 if ( index < range . startIndex ) {
222228 template += transform ( value ) ;
223- if ( isEndStr && changes . newLineSymbol ) {
224- template += `<span data-newline-symbol data-diff-highlight style="background-color: var(${ operator === "add" ? addContentHighlightBGName : delContentHighlightBGName } );border-radius: 0.2em;">${ getSymbol ( changes . newLineSymbol ) } </span>` ;
225- }
226229 // start of range
227230 } else if ( index === range . startIndex ) {
228231 // current range all in the same node
@@ -233,9 +236,6 @@ export const getSyntaxDiffTemplateByFastDiff = ({
233236 template += `<span data-diff-highlight style="background-color: var(${ operator === "add" ? addContentHighlightBGName : delContentHighlightBGName } );border-top-left-radius: 0.2em;border-bottom-left-radius: 0.2em;">` ;
234237 }
235238 template += transform ( value ) ;
236- if ( isEndStr && changes . newLineSymbol ) {
237- template += `<span data-newline-symbol>${ getSymbol ( changes . newLineSymbol ) } </span>` ;
238- }
239239 if ( isLastStr ) {
240240 template += `</span>` ;
241241 } else if ( range . startIndex === range . endIndex ) {
@@ -260,9 +260,6 @@ export const getSyntaxDiffTemplateByFastDiff = ({
260260 `<span data-diff-highlight style="background-color: var(${ operator === "add" ? addContentHighlightBGName : delContentHighlightBGName } );">` ;
261261 }
262262 template += transform ( value ) ;
263- if ( isEndStr && changes . newLineSymbol ) {
264- template += `<span data-newline-symbol>${ getSymbol ( changes . newLineSymbol ) } </span>` ;
265- }
266263 if ( isLastStr ) {
267264 template += `</span>` ;
268265 }
@@ -278,16 +275,17 @@ export const getSyntaxDiffTemplateByFastDiff = ({
278275 }
279276 template += transform ( value ) ;
280277 }
281- if ( isEndStr && changes . newLineSymbol ) {
282- template += `<span data-newline-symbol>${ getSymbol ( changes . newLineSymbol ) } </span>` ;
283- }
284278 template += `</span>` ;
285279 rangeIndex ++ ;
286280 range = allRange [ rangeIndex ] ;
287281 // after range
288282 }
289283 } else {
290284 template += transform ( value ) ;
285+ if ( noDiff && isEndStr && changes . newLineSymbol ) {
286+ template += `<span data-diff-highlight style="background-color: var(${ operator === "add" ? addContentHighlightBGName : delContentHighlightBGName } );border-radius: 0.2em;">` ;
287+ template += `<span data-newline-symbol>${ getSymbol ( changes . newLineSymbol ) } </span></span>` ;
288+ }
291289 }
292290 }
293291 template += `</span>` ;
0 commit comments