Page MenuHomeSoftware Heritage

D4727.diff
No OneTemporary

D4727.diff

diff --git a/cypress/integration/revision-diff.spec.js b/cypress/integration/revision-diff.spec.js
--- a/cypress/integration/revision-diff.spec.js
+++ b/cypress/integration/revision-diff.spec.js
@@ -153,11 +153,14 @@
if (lnNumber === start || lnNumber === end) {
inHighlightedRange = true;
}
+ const backgroundColor = $(line).css('background-color');
const mixBlendMode = $(line).css('mix-blend-mode');
if (inHighlightedRange && parseInt(lnNumber)) {
assert.equal(mixBlendMode, 'multiply');
+ assert.notEqual(backgroundColor, 'rgba(0, 0, 0, 0)');
} else {
assert.equal(mixBlendMode, 'normal');
+ assert.equal(backgroundColor, 'rgba(0, 0, 0, 0)');
}
if (lnNumber === end) {
inHighlightedRange = false;
@@ -351,20 +354,26 @@
}
if (fromLn) {
+ const fromBackgroundColor = $(fromLn).css('background-color');
const fromMixBlendMode = $(fromLn).css('mix-blend-mode');
if (inHighlightedRange && fromLnNumber) {
assert.equal(fromMixBlendMode, 'multiply');
+ assert.notEqual(fromBackgroundColor, 'rgba(0, 0, 0, 0)');
} else {
assert.equal(fromMixBlendMode, 'normal');
+ assert.equal(fromBackgroundColor, 'rgba(0, 0, 0, 0)');
}
}
if (toLn) {
+ const toBackgroundColor = $(toLn).css('background-color');
const toMixBlendMode = $(toLn).css('mix-blend-mode');
if (inHighlightedRange && toLnNumber) {
assert.equal(toMixBlendMode, 'multiply');
+ assert.notEqual(toBackgroundColor, 'rgba(0, 0, 0, 0)');
} else {
assert.equal(toMixBlendMode, 'normal');
+ assert.equal(toBackgroundColor, 'rgba(0, 0, 0, 0)');
}
}
@@ -464,4 +473,20 @@
splitDiffHighlightingTest(diffId, endLines, startLines);
});
+
+ it('should highlight diff lines properly when a content is browsed in the Files tab', function() {
+ const url = this.Urls.browse_revision(revision) + `?origin=${origin}&path=README.md`;
+ cy.visit(url);
+ cy.get('a[data-toggle="tab"]')
+ .contains('Changes')
+ .click();
+ const diffHighlightingData = diffsHighlightingData['unified'];
+ const diffId = diffHighlightingData.diffId;
+ let startLines = diffHighlightingData.startLines;
+ let endLines = diffHighlightingData.endLines;
+
+ unifiedDiffHighlightingTest(diffId, startLines, endLines);
+
+ });
+
});
diff --git a/swh/web/assets/src/bundles/revision/diff-utils.js b/swh/web/assets/src/bundles/revision/diff-utils.js
--- a/swh/web/assets/src/bundles/revision/diff-utils.js
+++ b/swh/web/assets/src/bundles/revision/diff-utils.js
@@ -191,7 +191,8 @@
$('.hljs-ln-numbers[data-line-number]').css('color', '#aaa');
$('.hljs-ln-numbers[data-line-number]').css('font-weight', 'initial');
if (currentTabName === 'Changes' && window.location.hash !== changesUrlFragment) {
- window.location.hash = changesUrlFragment;
+ window.history.replaceState('', document.title,
+ window.location.pathname + window.location.search + changesUrlFragment);
}
}
@@ -736,6 +737,11 @@
// click callback for highlighting diff lines
$('body').click(evt => {
+
+ if (currentTabName !== 'Changes') {
+ return;
+ }
+
if (evt.target.classList.contains('hljs-ln-n')) {
const diffId = $(evt.target).closest('code').prop('id');
diff --git a/swh/web/assets/src/bundles/webapp/code-highlighting.js b/swh/web/assets/src/bundles/webapp/code-highlighting.js
--- a/swh/web/assets/src/bundles/webapp/code-highlighting.js
+++ b/swh/web/assets/src/bundles/webapp/code-highlighting.js
@@ -43,6 +43,9 @@
let lines = [];
let linesRegexp = new RegExp(/L(\d+)/g);
let line = linesRegexp.exec(window.location.hash);
+ if (line === null) {
+ return;
+ }
while (line) {
lines.push(parseInt(line[1]));
line = linesRegexp.exec(window.location.hash);
@@ -76,7 +79,7 @@
// click handler to dynamically highlight line(s)
// when the user clicks on a line number (lines range
// can also be highlighted while holding the shift key)
- $('body').click(evt => {
+ $('.swh-content').click(evt => {
if (evt.target.classList.contains('hljs-ln-n')) {
let line = parseInt($(evt.target).data('line-number'));
if (evt.shiftKey && firstHighlightedLine && line > firstHighlightedLine) {

File Metadata

Mime Type
text/plain
Expires
Dec 21 2024, 3:02 PM (11 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3222083

Event Timeline