mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-18 09:45:36 -05:00
Fixes issues with changes showing wrong diff
Refactors diff parsing
This commit is contained in:
@@ -6,35 +6,26 @@ export interface GitDiffLine {
|
||||
state: 'added' | 'removed' | 'unchanged';
|
||||
}
|
||||
|
||||
export interface GitDiffChunkLine extends GitDiffLine {
|
||||
previous?: (GitDiffLine | undefined)[];
|
||||
}
|
||||
|
||||
export class GitDiffChunk {
|
||||
|
||||
private _chunk: string | undefined;
|
||||
private _current: (GitDiffLine | undefined)[] | undefined;
|
||||
private _previous: (GitDiffLine | undefined)[] | undefined;
|
||||
private _lines: GitDiffChunkLine[] | undefined;
|
||||
|
||||
constructor(chunk: string, public currentPosition: { start: number, end: number }, public previousPosition: { start: number, end: number }) {
|
||||
this._chunk = chunk;
|
||||
}
|
||||
|
||||
get current(): (GitDiffLine | undefined)[] {
|
||||
if (this._chunk !== undefined) {
|
||||
this.parseChunk();
|
||||
get lines(): GitDiffChunkLine[] {
|
||||
if (this._lines === undefined) {
|
||||
this._lines = GitDiffParser.parseChunk(this._chunk!);
|
||||
this._chunk = undefined;
|
||||
}
|
||||
|
||||
return this._current!;
|
||||
}
|
||||
|
||||
get previous(): (GitDiffLine | undefined)[] {
|
||||
if (this._chunk !== undefined) {
|
||||
this.parseChunk();
|
||||
}
|
||||
|
||||
return this._previous!;
|
||||
}
|
||||
|
||||
private parseChunk() {
|
||||
[this._current, this._previous] = GitDiffParser.parseChunk(this._chunk!);
|
||||
this._chunk = undefined;
|
||||
return this._lines;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user