@@ -37,17 +37,22 @@ const DiffPrefixAdd = "+" as const;
3737const DiffPrefixDelete = "-" as const ;
3838const DiffPrefixContext = " " as const ;
3939const DiffPrefixNoNewline = "\\" as const ;
40+ // https://github.com/MrWangJustToDo/git-diff-view/issues/41
41+ // some line only have a new line symbol without any other character
42+ const DIffPrefixNewLine = "\n" as const ;
4043
4144type DiffLinePrefix =
4245 | typeof DiffPrefixAdd
4346 | typeof DiffPrefixDelete
4447 | typeof DiffPrefixContext
45- | typeof DiffPrefixNoNewline ;
48+ | typeof DiffPrefixNoNewline
49+ | typeof DIffPrefixNewLine ;
4650const DiffLinePrefixChars : Set < DiffLinePrefix > = new Set ( [
4751 DiffPrefixAdd ,
4852 DiffPrefixDelete ,
4953 DiffPrefixContext ,
5054 DiffPrefixNoNewline ,
55+ DIffPrefixNewLine ,
5156] ) ;
5257
5358interface IDiffHeaderInfo {
@@ -127,6 +132,19 @@ export class DiffParser {
127132
128133 // We've succeeded if there's anything to read in between the
129134 // start and the end
135+ /**
136+ * https://github.com/MrWangJustToDo/git-diff-view/issues/41
137+ * some file content may have multiple line without any character
138+ * such as
139+ * ```
140+ *
141+ *
142+ *
143+ * +
144+ * +
145+ * ```
146+ * this will cause ls === le, but we not in the end of file
147+ */
130148 return this . ls !== this . le ;
131149 }
132150
@@ -139,7 +157,7 @@ export class DiffParser {
139157 if ( header ) {
140158 return this . nextLine ( ) ? this . text . substring ( this . ls , this . le ) : null ;
141159 } else {
142- return this . nextLine ( ) ? this . text . substring ( this . ls + 1 , this . le + 1 ) : null ;
160+ return this . nextLine ( ) ? this . text . substring ( this . ls + 1 , this . le + 1 ) : this . text . length > this . ls ? "\n" : null ;
143161 }
144162 }
145163
@@ -353,7 +371,7 @@ export class DiffParser {
353371 diffLine = new DiffLine ( line , DiffLineType . Add , diffLineNumber , null , rollingDiffAfterCounter ++ ) ;
354372 } else if ( c === DiffPrefixDelete ) {
355373 diffLine = new DiffLine ( line , DiffLineType . Delete , diffLineNumber , rollingDiffBeforeCounter ++ , null ) ;
356- } else if ( c === DiffPrefixContext ) {
374+ } else if ( c === DiffPrefixContext || c === DIffPrefixNewLine ) {
357375 diffLine = new DiffLine (
358376 line ,
359377 DiffLineType . Context ,
0 commit comments