Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 41136a6

Browse files
author
annthurium
committed
add isDiffRowOffsetIndexEmpty for better readability
1 parent 6a7ba5d commit 41136a6

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ export default class MultiFilePatch {
196196
return Range.fromObject([[selectionRow, 0], [selectionRow, Infinity]]);
197197
}
198198

199+
isDiffRowOffsetIndexEmpty(filePatchPath) {
200+
const diffRowOffsetIndex = this.diffRowOffsetIndices.get(filePatchPath);
201+
return diffRowOffsetIndex.index.size === 0;
202+
}
199203
populateDiffRowOffsetIndices(filePatch) {
200204
let diffRow = 1;
201205
const index = new RBTree((a, b) => a.diffRow - b.diffRow);
@@ -337,10 +341,9 @@ export default class MultiFilePatch {
337341
this.hunksByMarker.set(hunk.getMarker(), hunk);
338342
}
339343

340-
const diffRowOffsetIndex = this.diffRowOffsetIndices.get(filePatch.getPath());
341344
// if the patch was initially collapsed, we need to calculate
342345
// the diffRowOffsetIndices to calculate comment position.
343-
if (diffRowOffsetIndex.index.size === 0) {
346+
if (this.isDiffRowOffsetIndexEmpty(filePatch.getPath())) {
344347
this.populateDiffRowOffsetIndices(filePatch);
345348
}
346349
}

test/models/patch/multi-file-patch.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,10 +791,10 @@ describe('MultiFilePatch', function() {
791791
fp.renderStatus(TOO_LARGE);
792792
})
793793
.build();
794-
assert.strictEqual(multiFilePatch.diffRowOffsetIndices.get('1.txt').index.size, 0);
794+
assert.isTrue(multiFilePatch.isDiffRowOffsetIndexEmpty('1.txt'));
795795
const [fp] = multiFilePatch.getFilePatches();
796796
multiFilePatch.expandFilePatch(fp);
797-
assert.strictEqual(multiFilePatch.diffRowOffsetIndices.get('1.txt').index.size, 3);
797+
assert.isFalse(multiFilePatch.isDiffRowOffsetIndexEmpty('1.txt'));
798798
assert.strictEqual(multiFilePatch.getBufferRowForDiffPosition('1.txt', 11), 9);
799799
});
800800

0 commit comments

Comments
 (0)