Skip to content

Commit ab00692

Browse files
committed
Fixing line diff bug and code folding bug
1 parent 81f91c6 commit ab00692

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/compute-lines.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,16 @@ const computeLineInformation = (
132132
diffIndex: number,
133133
added?: boolean,
134134
removed?: boolean,
135+
evaluateOnlyFirstLine?: boolean,
135136
): LineInformation[] => {
136137
const lines = constructLines(value);
137138

138139
return lines.map((line: string, lineIndex): LineInformation => {
139140
const left: DiffInformation = {};
140141
const right: DiffInformation = {};
141-
if (ignoreDiffIndexes.includes(`${diffIndex}-${lineIndex}`)) {
142-
return { left: {}, right: {}};
142+
if (ignoreDiffIndexes.includes(`${diffIndex}-${lineIndex}`)
143+
|| (evaluateOnlyFirstLine && lineIndex !== 0)) {
144+
return undefined;
143145
}
144146
if (added || removed) {
145147
if (!diffLines.includes(counter)) {
@@ -162,7 +164,7 @@ const computeLineInformation = (
162164
value: rightValue,
163165
lineNumber,
164166
type,
165-
} = getLineInformation(nextDiff.value, diffIndex, true)[lineIndex].right;
167+
} = getLineInformation(nextDiff.value, diffIndex, true, false, true)[0].right;
166168
// When identified as modification, push the next diff to ignore
167169
// list as the next value will be added in this line computation as
168170
// right and left values.
@@ -200,7 +202,7 @@ const computeLineInformation = (
200202

201203
counter += 1;
202204
return { right, left };
203-
});
205+
}).filter(Boolean);
204206
};
205207

206208
diffArray

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiffViewerSt
462462
? this.renderSplitView(line, i)
463463
: this.renderInlineView(line, i);
464464

465-
if (currentPosition === extraLines && skippedLines.length > 1) {
465+
if (currentPosition === extraLines && skippedLines.length > 0) {
466466
const { length } = skippedLines;
467467
skippedLines = [];
468468
return (

test/react-diff-viewer-test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('Testing react diff viewer', (): void => {
3939
newValue={newCode}
4040
/>);
4141

42-
expect(node.find('table > tbody tr').length).toEqual(6);
42+
expect(node.find('table > tbody tr').length).toEqual(7);
4343
});
4444

4545
it('It should render diff lines in inline view', (): void => {

0 commit comments

Comments
 (0)