@@ -2,7 +2,6 @@ import { type DiffFile, type DiffLine, checkDiffLineIncludeChange, type File } f
22import { NewLineSymbol } from "@git-diff-view/utils" ;
33import { Box , Text } from "ink" ;
44import * as React from "react" ;
5- import { memo } from "react" ;
65
76import {
87 diffAddLineNumber ,
@@ -161,171 +160,155 @@ const DiffUnifiedNewLine = ({
161160 ) ;
162161} ;
163162
164- const _DiffUnifiedLine = memo (
165- ( {
166- index,
167- width,
168- theme,
169- columns,
170- diffFile,
171- lineNumber,
172- enableHighlight,
173- } : {
174- index : number ;
175- width : number ;
176- theme : "light" | "dark" ;
177- columns : number ;
178- diffFile : DiffFile ;
179- lineNumber : number ;
180- enableHighlight : boolean ;
181- } ) => {
182- const unifiedLine = diffFile . getUnifiedLine ( index ) ;
163+ const InternalDiffUnifiedLine = ( {
164+ index,
165+ width,
166+ theme,
167+ columns,
168+ diffFile,
169+ lineNumber,
170+ enableHighlight,
171+ } : {
172+ index : number ;
173+ width : number ;
174+ theme : "light" | "dark" ;
175+ columns : number ;
176+ diffFile : DiffFile ;
177+ lineNumber : number ;
178+ enableHighlight : boolean ;
179+ } ) => {
180+ const unifiedLine = diffFile . getUnifiedLine ( index ) ;
183181
184- const hasDiff = unifiedLine . diff ;
182+ const hasDiff = unifiedLine . diff ;
185183
186- const hasChange = checkDiffLineIncludeChange ( unifiedLine . diff ) ;
184+ const hasChange = checkDiffLineIncludeChange ( unifiedLine . diff ) ;
187185
188- const rawLine = unifiedLine . value || "" ;
186+ const rawLine = unifiedLine . value || "" ;
189187
190- const diffLine = unifiedLine . diff ;
188+ const diffLine = unifiedLine . diff ;
191189
192- const newLineNumber = unifiedLine . newLineNumber ;
190+ const newLineNumber = unifiedLine . newLineNumber ;
193191
194- const oldLinenumber = unifiedLine . oldLineNumber ;
192+ const oldLinenumber = unifiedLine . oldLineNumber ;
195193
196- const syntaxLine = newLineNumber
197- ? diffFile . getNewSyntaxLine ( newLineNumber )
198- : oldLinenumber
199- ? diffFile . getOldSyntaxLine ( oldLinenumber )
200- : undefined ;
194+ const syntaxLine = newLineNumber
195+ ? diffFile . getNewSyntaxLine ( newLineNumber )
196+ : oldLinenumber
197+ ? diffFile . getOldSyntaxLine ( oldLinenumber )
198+ : undefined ;
201199
202- const plainLine = newLineNumber
203- ? diffFile . getNewPlainLine ( newLineNumber )
204- : oldLinenumber
205- ? diffFile . getOldPlainLine ( oldLinenumber )
206- : undefined ;
200+ const plainLine = newLineNumber
201+ ? diffFile . getNewPlainLine ( newLineNumber )
202+ : oldLinenumber
203+ ? diffFile . getOldPlainLine ( oldLinenumber )
204+ : undefined ;
207205
208- const contentWidth = columns - ( width + 1 ) * 2 ;
206+ const contentWidth = columns - ( width + 1 ) * 2 ;
209207
210- let row = getCurrentLineRow ( { content : rawLine , width : contentWidth } ) ;
208+ let row = getCurrentLineRow ( { content : rawLine , width : contentWidth } ) ;
211209
212- row = diffLine ?. changes ?. hasLineChange && diffLine . changes . newLineSymbol === NewLineSymbol . NEWLINE ? row + 1 : row ;
210+ row = diffLine ?. changes ?. hasLineChange && diffLine . changes . newLineSymbol === NewLineSymbol . NEWLINE ? row + 1 : row ;
213211
214- const color = hasDiff
215- ? theme === "light"
216- ? diffPlainLineNumberColor . light
217- : diffPlainLineNumberColor . dark
218- : theme === "light"
219- ? diffExpandLineNumberColor . light
220- : diffExpandLineNumberColor . dark ;
212+ const color = hasDiff
213+ ? theme === "light"
214+ ? diffPlainLineNumberColor . light
215+ : diffPlainLineNumberColor . dark
216+ : theme === "light"
217+ ? diffExpandLineNumberColor . light
218+ : diffExpandLineNumberColor . dark ;
221219
222- const bg = hasDiff
223- ? theme === "light"
224- ? diffPlainLineNumber . light
225- : diffPlainLineNumber . dark
226- : theme === "light"
227- ? diffExpandLineNumber . light
228- : diffExpandLineNumber . dark ;
220+ const bg = hasDiff
221+ ? theme === "light"
222+ ? diffPlainLineNumber . light
223+ : diffPlainLineNumber . dark
224+ : theme === "light"
225+ ? diffExpandLineNumber . light
226+ : diffExpandLineNumber . dark ;
229227
230- if ( hasChange ) {
231- if ( unifiedLine . oldLineNumber ) {
232- return (
233- < DiffUnifiedOldLine
234- theme = { theme }
235- width = { width }
236- height = { row }
237- columns = { columns }
238- rawLine = { rawLine }
239- diffFile = { diffFile }
240- index = { lineNumber }
241- diffLine = { diffLine }
242- plainLine = { plainLine }
243- syntaxLine = { syntaxLine }
244- contentWidth = { contentWidth }
245- enableHighlight = { enableHighlight }
246- lineNumber = { unifiedLine . oldLineNumber }
247- />
248- ) ;
249- } else {
250- return (
251- < DiffUnifiedNewLine
252- theme = { theme }
253- width = { width }
254- height = { row }
255- columns = { columns }
256- rawLine = { rawLine }
257- index = { lineNumber }
258- diffLine = { diffLine }
259- diffFile = { diffFile }
260- plainLine = { plainLine }
261- syntaxLine = { syntaxLine }
262- contentWidth = { contentWidth }
263- enableHighlight = { enableHighlight }
264- lineNumber = { unifiedLine . newLineNumber ! }
265- />
266- ) ;
267- }
228+ if ( hasChange ) {
229+ if ( unifiedLine . oldLineNumber ) {
230+ return (
231+ < DiffUnifiedOldLine
232+ theme = { theme }
233+ width = { width }
234+ height = { row }
235+ columns = { columns }
236+ rawLine = { rawLine }
237+ diffFile = { diffFile }
238+ index = { lineNumber }
239+ diffLine = { diffLine }
240+ plainLine = { plainLine }
241+ syntaxLine = { syntaxLine }
242+ contentWidth = { contentWidth }
243+ enableHighlight = { enableHighlight }
244+ lineNumber = { unifiedLine . oldLineNumber }
245+ />
246+ ) ;
268247 } else {
269248 return (
270- < Box data-line = { lineNumber } data-state = { unifiedLine . diff ? "diff" : "plain" } height = { row } width = { columns } >
271- < Box width = { width * 2 + 2 } flexShrink = { 0 } >
272- < Box width = { width } justifyContent = "flex-end" >
273- < Text
274- dimColor
275- wrap = "wrap"
276- color = { color }
277- backgroundColor = { bg }
278- data-line-old-num = { unifiedLine . oldLineNumber }
279- >
280- { unifiedLine . oldLineNumber
281- . toString ( )
282- . padStart ( width )
283- . padEnd ( width * row ) }
284- </ Text >
285- </ Box >
286- < Box width = { 1 } >
287- < Text backgroundColor = { bg } wrap = "wrap" >
288- { " " . padEnd ( row ) }
289- </ Text >
290- </ Box >
291- < Box width = { width } justifyContent = "flex-end" >
292- < Text
293- dimColor
294- wrap = "wrap"
295- color = { color }
296- backgroundColor = { bg }
297- data-line-new-num = { unifiedLine . newLineNumber }
298- >
299- { unifiedLine . newLineNumber
300- . toString ( )
301- . padStart ( width )
302- . padEnd ( width * row ) }
303- </ Text >
304- </ Box >
305- < Box width = { 1 } >
306- < Text backgroundColor = { bg } wrap = "wrap" >
307- { " " . padEnd ( row ) }
308- </ Text >
309- </ Box >
310- </ Box >
311- < DiffContent
312- theme = { theme }
313- height = { row }
314- rawLine = { rawLine }
315- diffFile = { diffFile }
316- diffLine = { diffLine }
317- width = { contentWidth }
318- plainLine = { plainLine }
319- syntaxLine = { syntaxLine }
320- enableHighlight = { enableHighlight }
321- />
322- </ Box >
249+ < DiffUnifiedNewLine
250+ theme = { theme }
251+ width = { width }
252+ height = { row }
253+ columns = { columns }
254+ rawLine = { rawLine }
255+ index = { lineNumber }
256+ diffLine = { diffLine }
257+ diffFile = { diffFile }
258+ plainLine = { plainLine }
259+ syntaxLine = { syntaxLine }
260+ contentWidth = { contentWidth }
261+ enableHighlight = { enableHighlight }
262+ lineNumber = { unifiedLine . newLineNumber ! }
263+ />
323264 ) ;
324265 }
266+ } else {
267+ return (
268+ < Box data-line = { lineNumber } data-state = { unifiedLine . diff ? "diff" : "plain" } height = { row } width = { columns } >
269+ < Box width = { width * 2 + 2 } flexShrink = { 0 } >
270+ < Box width = { width } justifyContent = "flex-end" >
271+ < Text dimColor wrap = "wrap" color = { color } backgroundColor = { bg } data-line-old-num = { unifiedLine . oldLineNumber } >
272+ { unifiedLine . oldLineNumber
273+ . toString ( )
274+ . padStart ( width )
275+ . padEnd ( width * row ) }
276+ </ Text >
277+ </ Box >
278+ < Box width = { 1 } >
279+ < Text backgroundColor = { bg } wrap = "wrap" >
280+ { " " . padEnd ( row ) }
281+ </ Text >
282+ </ Box >
283+ < Box width = { width } justifyContent = "flex-end" >
284+ < Text dimColor wrap = "wrap" color = { color } backgroundColor = { bg } data-line-new-num = { unifiedLine . newLineNumber } >
285+ { unifiedLine . newLineNumber
286+ . toString ( )
287+ . padStart ( width )
288+ . padEnd ( width * row ) }
289+ </ Text >
290+ </ Box >
291+ < Box width = { 1 } >
292+ < Text backgroundColor = { bg } wrap = "wrap" >
293+ { " " . padEnd ( row ) }
294+ </ Text >
295+ </ Box >
296+ </ Box >
297+ < DiffContent
298+ theme = { theme }
299+ height = { row }
300+ rawLine = { rawLine }
301+ diffFile = { diffFile }
302+ diffLine = { diffLine }
303+ width = { contentWidth }
304+ plainLine = { plainLine }
305+ syntaxLine = { syntaxLine }
306+ enableHighlight = { enableHighlight }
307+ />
308+ </ Box >
309+ ) ;
325310 }
326- ) ;
327-
328- _DiffUnifiedLine . displayName = "_DiffUnifiedLine" ;
311+ } ;
329312
330313export const DiffUnifiedContentLine = ( {
331314 index,
@@ -349,7 +332,7 @@ export const DiffUnifiedContentLine = ({
349332 if ( unifiedLine ?. isHidden ) return null ;
350333
351334 return (
352- < _DiffUnifiedLine
335+ < InternalDiffUnifiedLine
353336 index = { index }
354337 width = { width }
355338 theme = { theme }
0 commit comments