Skip to content

Commit b251264

Browse files
committed
Use a Marker instead of a Point to track delayed patch location
1 parent 7eab119 commit b251264

3 files changed

Lines changed: 18 additions & 27 deletions

File tree

‎lib/models/patch/builder.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,16 @@ function singleDiffFilePatch(diff, layeredBuffer, opts) {
121121
EXPANDED;
122122

123123
if (renderStatus === TOO_LARGE) {
124-
const insertPoint = new Point(layeredBuffer.buffer.getLastRow(), 0);
124+
const insertRow = layeredBuffer.buffer.getLastRow();
125+
const patchMarker = layeredBuffer.layers.patch.markPosition(
126+
[insertRow, 0],
127+
{invalidate: 'never', exclusive: false},
128+
);
125129

126130
return FilePatch.createDelayedFilePatch(
127-
oldFile, newFile, insertPoint, TOO_LARGE,
131+
oldFile, newFile, patchMarker, TOO_LARGE,
128132
() => {
129-
const [hunks, patchMarker] = buildHunks(diff, layeredBuffer, insertPoint.row);
133+
const [hunks] = buildHunks(diff, layeredBuffer, insertRow, patchMarker);
130134
return new Patch({status: diff.status, hunks, marker: patchMarker, buffer: layeredBuffer.buffer});
131135
},
132136
);

‎lib/models/patch/file-patch.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export default class FilePatch {
99
return new this(nullFile, nullFile, Patch.createNull());
1010
}
1111

12-
static createDelayedFilePatch(oldFile, newFile, position, renderStatus, parseFn) {
13-
return new this(oldFile, newFile, Patch.createDelayedPatch(position, renderStatus, parseFn));
12+
static createDelayedFilePatch(oldFile, newFile, marker, renderStatus, parseFn) {
13+
return new this(oldFile, newFile, Patch.createDelayedPatch(marker, renderStatus, parseFn));
1414
}
1515

1616
constructor(oldFile, newFile, patch) {
@@ -120,7 +120,7 @@ export default class FilePatch {
120120
}
121121

122122
triggerDelayedRender() {
123-
const nextPatch = this.patch.parseFn();
123+
const nextPatch = this.patch.parseFn(this.patch);
124124
if (nextPatch !== this.patch) {
125125
this.patch = nextPatch;
126126
this.didChangeRenderStatus();

‎lib/models/patch/patch.js‎

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,22 @@ export default class Patch {
1414
return new NullPatch();
1515
}
1616

17-
static createDelayedPatch(position, renderStatus, parseFn) {
18-
return new DelayedPatch(position, renderStatus, parseFn);
17+
static createDelayedPatch(marker, renderStatus, parseFn) {
18+
return new this({status: null, hunks: [], marker, renderStatus, parseFn});
1919
}
2020

21-
constructor({status, hunks, marker, renderStatus}) {
21+
constructor({status, hunks, marker, renderStatus, parseFn}) {
2222
this.status = status;
2323
this.hunks = hunks;
2424
this.marker = marker;
2525
this.renderStatus = renderStatus || EXPANDED;
2626

2727
this.changedLineCount = this.getHunks().reduce((acc, hunk) => acc + hunk.changedLineCount(), 0);
28+
29+
if (parseFn) {
30+
// Override the prototype's method
31+
this.parseFn = parseFn;
32+
}
2833
}
2934

3035
getStatus() {
@@ -392,24 +397,6 @@ class NullPatch {
392397
}
393398
}
394399

395-
// TODO: it prob shouldn't extend NullPatch
396-
class DelayedPatch extends NullPatch {
397-
constructor(position, renderStatus, parseFn) {
398-
super();
399-
this.position = position;
400-
this.renderStatus = renderStatus;
401-
this.parseFn = parseFn;
402-
}
403-
404-
getStartRange() {
405-
return new Range(this.position, this.position);
406-
}
407-
408-
getRenderStatus() {
409-
return this.renderStatus;
410-
}
411-
}
412-
413400
class BufferBuilder {
414401
constructor(original, originalBaseOffset, nextLayeredBuffer) {
415402
this.originalBuffer = original;

0 commit comments

Comments
 (0)