Keep one state for old and another for the new diff
This commit is contained in:
parent
719b1cde71
commit
73999bb782
1 changed files with 23 additions and 4 deletions
|
|
@ -72,16 +72,35 @@
|
||||||
// collect all the diff files and execute the highlight on their lines
|
// collect all the diff files and execute the highlight on their lines
|
||||||
var $files = $target.find(".d2h-file-wrapper");
|
var $files = $target.find(".d2h-file-wrapper");
|
||||||
$files.map(function(i, file) {
|
$files.map(function(i, file) {
|
||||||
var state;
|
var oldLinesState;
|
||||||
|
var newLinesState;
|
||||||
var $file = $(file);
|
var $file = $(file);
|
||||||
var language = $file.data("lang");
|
var language = $file.data("lang");
|
||||||
|
|
||||||
// collect all the code lines and execute the highlight on them
|
// collect all the code lines and execute the highlight on them
|
||||||
var $codeLines = $file.find(".d2h-code-line-ctn");
|
var $codeLines = $file.find(".d2h-code-line-ctn");
|
||||||
$codeLines.map(function(i, line) {
|
$codeLines.map(function(i, line) {
|
||||||
|
var $line = $(line);
|
||||||
var text = line.textContent;
|
var text = line.textContent;
|
||||||
var result = hljs.getLanguage(language) ? hljs.highlight(language, text, true, state) : hljs.highlightAuto(text);
|
var lineParent = line.parentNode;
|
||||||
state = result.top;
|
|
||||||
|
var lineState;
|
||||||
|
if (lineParent.className.indexOf("d2h-del") !== -1) {
|
||||||
|
lineState = oldLinesState;
|
||||||
|
} else {
|
||||||
|
lineState = newLinesState;
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = hljs.getLanguage(language) ? hljs.highlight(language, text, true, lineState) : hljs.highlightAuto(text);
|
||||||
|
|
||||||
|
if (lineParent.className.indexOf("d2h-del") !== -1) {
|
||||||
|
oldLinesState = result.top;
|
||||||
|
} else if (lineParent.className.indexOf("d2h-ins") !== -1) {
|
||||||
|
newLinesState = result.top;
|
||||||
|
} else {
|
||||||
|
oldLinesState = result.top;
|
||||||
|
newLinesState = result.top;
|
||||||
|
}
|
||||||
|
|
||||||
var originalStream = nodeStream(line);
|
var originalStream = nodeStream(line);
|
||||||
if (originalStream.length) {
|
if (originalStream.length) {
|
||||||
|
|
@ -90,13 +109,13 @@
|
||||||
result.value = mergeStreams(originalStream, nodeStream(resultNode), text);
|
result.value = mergeStreams(originalStream, nodeStream(resultNode), text);
|
||||||
}
|
}
|
||||||
|
|
||||||
var $line = $(line);
|
|
||||||
buildClassName(line.className, result.language)
|
buildClassName(line.className, result.language)
|
||||||
.split(" ")
|
.split(" ")
|
||||||
.map(function(className) {
|
.map(function(className) {
|
||||||
$line.addClass(className);
|
$line.addClass(className);
|
||||||
});
|
});
|
||||||
$line.html(result.value);
|
$line.html(result.value);
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue