preserve context
This commit is contained in:
parent
6975f098f7
commit
c1d6701699
1 changed files with 28 additions and 21 deletions
|
|
@ -100,34 +100,41 @@ export default class SideBySideRenderer {
|
||||||
left: this.makeHeaderHtml(block.header, file),
|
left: this.makeHeaderHtml(block.header, file),
|
||||||
right: this.makeHeaderHtml(''),
|
right: this.makeHeaderHtml(''),
|
||||||
};
|
};
|
||||||
|
let contextStash: (DiffLineContent & DiffLineContext)[] = []; // if white space are ignored, context should be relevant
|
||||||
|
let processContext = false;
|
||||||
this.applyLineGroupping(block).forEach(([contextLines, oldLines, newLines]) => {
|
this.applyLineGroupping(block).forEach(([contextLines, oldLines, newLines]) => {
|
||||||
if (oldLines.length && newLines.length && !contextLines.length) {
|
if (oldLines.length && newLines.length && !contextLines.length) {
|
||||||
this.applyRematchMatching(oldLines, newLines, matcher).map(([oldLines, newLines]) => {
|
this.applyRematchMatching(oldLines, newLines, matcher).map(([oldLines, newLines]) => {
|
||||||
const { left, right } = this.processChangedLines(file.isCombined, oldLines, newLines);
|
const { left, right } = this.processChangedLines(file.isCombined, oldLines, newLines);
|
||||||
fileHtml.left += left;
|
fileHtml.left += left;
|
||||||
fileHtml.right += right;
|
fileHtml.right += right;
|
||||||
|
if (!left && !right) {
|
||||||
|
contextStash = [];
|
||||||
|
processContext = false;
|
||||||
|
} else processContext = true;
|
||||||
});
|
});
|
||||||
} else if (contextLines.length) {
|
} else if (contextLines.length || contextStash.length) {
|
||||||
contextLines.forEach(line => {
|
if (!processContext) contextStash = contextStash.concat(contextLines);
|
||||||
const { prefix, content } = renderUtils.deconstructLine(line.content, file.isCombined);
|
else
|
||||||
const { left, right } = this.generateLineHtml(
|
contextLines.concat(processContext ? contextStash : []).forEach(line => {
|
||||||
{
|
const { prefix, content } = renderUtils.deconstructLine(line.content, file.isCombined);
|
||||||
type: renderUtils.CSSLineClass.CONTEXT,
|
const { left, right } = this.generateLineHtml(
|
||||||
prefix: prefix,
|
{
|
||||||
content: content,
|
type: renderUtils.CSSLineClass.CONTEXT,
|
||||||
number: line.oldNumber,
|
prefix: prefix,
|
||||||
},
|
content: content,
|
||||||
{
|
number: line.oldNumber,
|
||||||
type: renderUtils.CSSLineClass.CONTEXT,
|
},
|
||||||
prefix: prefix,
|
{
|
||||||
content: content,
|
type: renderUtils.CSSLineClass.CONTEXT,
|
||||||
number: line.newNumber,
|
prefix: prefix,
|
||||||
},
|
content: content,
|
||||||
);
|
number: line.newNumber,
|
||||||
fileHtml.left += left;
|
},
|
||||||
fileHtml.right += right;
|
);
|
||||||
});
|
fileHtml.left += left;
|
||||||
|
fileHtml.right += right;
|
||||||
|
});
|
||||||
} else if (oldLines.length || newLines.length) {
|
} else if (oldLines.length || newLines.length) {
|
||||||
const { left, right } = this.processChangedLines(file.isCombined, oldLines, newLines);
|
const { left, right } = this.processChangedLines(file.isCombined, oldLines, newLines);
|
||||||
fileHtml.left += left;
|
fileHtml.left += left;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue