mirror of
https://github.com/desktop/desktop
synced 2024-09-13 21:31:32 +00:00
Merge pull request #18089 from desktop/fix-select-last-line
Fix diff parser when last line of file has "no newline" marker before the change
This commit is contained in:
commit
c2a964f80d
|
@ -311,7 +311,6 @@ export class DiffParser {
|
|||
let diffLineNumber = linesConsumed
|
||||
while ((c = this.parseLinePrefix(this.peek()))) {
|
||||
const line = this.readLine()
|
||||
diffLineNumber++
|
||||
|
||||
if (!line) {
|
||||
throw new Error('Expected unified diff line but reached end of diff')
|
||||
|
@ -338,6 +337,12 @@ export class DiffParser {
|
|||
continue
|
||||
}
|
||||
|
||||
// We must increase `diffLineNumber` only when we're certain that the line
|
||||
// is not a "no newline" marker. Otherwise, we'll end up with a wrong
|
||||
// `diffLineNumber` for the next line. This could happen if the last line
|
||||
// in the file doesn't have a newline before the change.
|
||||
diffLineNumber++
|
||||
|
||||
let diffLine: DiffLine
|
||||
|
||||
if (c === DiffPrefixAdd) {
|
||||
|
|
|
@ -256,6 +256,7 @@ index 1910281..257cc56 100644
|
|||
expect(lines[i].type).toBe(DiffLineType.Delete)
|
||||
expect(lines[i].oldLineNumber).toBe(1)
|
||||
expect(lines[i].newLineNumber).toBeNull()
|
||||
expect(lines[i].originalLineNumber).toBe(1)
|
||||
expect(lines[i].noTrailingNewLine).toBe(true)
|
||||
i++
|
||||
|
||||
|
@ -263,6 +264,7 @@ index 1910281..257cc56 100644
|
|||
expect(lines[i].type).toBe(DiffLineType.Add)
|
||||
expect(lines[i].oldLineNumber).toBeNull()
|
||||
expect(lines[i].newLineNumber).toBe(1)
|
||||
expect(lines[i].originalLineNumber).toBe(2)
|
||||
expect(lines[i].noTrailingNewLine).toBe(false)
|
||||
i++
|
||||
})
|
||||
|
@ -305,6 +307,7 @@ index 1910281..ba0e162 100644
|
|||
expect(lines[i].type).toBe(DiffLineType.Delete)
|
||||
expect(lines[i].oldLineNumber).toBe(1)
|
||||
expect(lines[i].newLineNumber).toBeNull()
|
||||
expect(lines[i].originalLineNumber).toBe(1)
|
||||
expect(lines[i].noTrailingNewLine).toBe(true)
|
||||
i++
|
||||
|
||||
|
@ -312,6 +315,7 @@ index 1910281..ba0e162 100644
|
|||
expect(lines[i].type).toBe(DiffLineType.Add)
|
||||
expect(lines[i].oldLineNumber).toBeNull()
|
||||
expect(lines[i].newLineNumber).toBe(1)
|
||||
expect(lines[i].originalLineNumber).toBe(2)
|
||||
expect(lines[i].noTrailingNewLine).toBe(true)
|
||||
i++
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue