Fixes issues with changes showing wrong diff

Refactors diff parsing
This commit is contained in:
Eric Amodio
2017-06-24 17:51:47 -04:00
parent ad790b274b
commit 12caa017a9
5 changed files with 86 additions and 77 deletions

View File

@@ -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;
}
}