Add support for dueToMove chunks in gr-diff

These chunks would then be marked differently - with a different
css class - so that it would be possible to distinguish chunks
that were added/removed because of a move operation instead of
an actual intented add/remove.

Change-Id: I9511f838d1634662397deae45042c4e21fd12750
This commit is contained in:
Renan Oliveira
2020-09-17 13:05:51 +02:00
parent 35bc17c78a
commit 221dd255a9
10 changed files with 39 additions and 0 deletions

View File

@@ -41,6 +41,9 @@ export class GrDiffBuilderSideBySide extends GrDiffBuilder {
if (group.dueToRebase) {
sectionEl.classList.add('dueToRebase');
}
if (group.dueToMove) {
sectionEl.classList.add('dueToMove');
}
if (group.ignoredWhitespaceOnly) {
sectionEl.classList.add('ignoredWhitespaceOnly');
}

View File

@@ -40,6 +40,9 @@ export class GrDiffBuilderUnified extends GrDiffBuilder {
if (group.dueToRebase) {
sectionEl.classList.add('dueToRebase');
}
if (group.dueToMove) {
sectionEl.classList.add('dueToMove');
}
if (group.ignoredWhitespaceOnly) {
sectionEl.classList.add('ignoredWhitespaceOnly');
}

View File

@@ -133,6 +133,12 @@ suite('GrDiffBuilderUnified tests', () => {
assert.isTrue(sectionEl.classList.contains('dueToRebase'));
});
test('creates the section with class if dueToMove', () => {
group.dueToMove = true;
const sectionEl = diffBuilder.buildSectionElement(group);
assert.isTrue(sectionEl.classList.contains('dueToMove'));
});
test('creates first the removed and then the added rows', () => {
const sectionEl = diffBuilder.buildSectionElement(group);
const rowEls = sectionEl.querySelectorAll('.diff-row');

View File

@@ -359,6 +359,7 @@ export class GrDiffProcessor extends GestureEventListeners(
const group = new GrDiffGroup(type, lines);
group.keyLocation = !!chunk.keyLocation;
group.dueToRebase = !!chunk.due_to_rebase;
group.dueToMove = !!chunk.due_to_move;
group.ignoredWhitespaceOnly = !!chunk.common;
return group;
}
@@ -676,6 +677,9 @@ export class GrDiffProcessor extends GestureEventListeners(
if (chunk.due_to_rebase) {
subChunk.due_to_rebase = true;
}
if (chunk.due_to_move) {
subChunk.due_to_move = true;
}
return subChunk;
});
}

View File

@@ -875,6 +875,16 @@ suite('gr-diff-processor tests', () => {
}
});
test('_breakdownChunk keeps due_to_move for broken down additions',
() => {
sinon.spy(element, '_breakdown');
const chunk = {b: ['blah', 'blah', 'blah'], due_to_move: true};
const result = element._breakdownChunk(chunk);
for (const subResult of result) {
assert.isTrue(subResult.due_to_move);
}
});
test('_breakdown common case', () => {
const array = 'Lorem ipsum dolor sit amet, suspendisse inceptos'
.split(' ');

View File

@@ -189,6 +189,8 @@ export class GrDiffGroup {
dueToRebase = false;
dueToMove = false;
/**
* True means all changes in this line are whitespace changes that should
* not be highlighted as changed as per the user settings.

View File

@@ -177,6 +177,14 @@ export const htmlTemplate = html`
background-color: var(--light-remove-add-highlight-color);
}
/* dueToMove */
.dueToMove .content.add .contentText {
background-color: var(--light-moved-add-highlight-color);
}
.dueToMove .content.remove .contentText {
background-color: var(--light-remove-add-highlight-color);
}
/* ignoredWhitespaceOnly */
.ignoredWhitespaceOnly .content.add .contentText .intraline,
.delta.total.ignoredWhitespaceOnly .content.add .contentText,

View File

@@ -167,6 +167,7 @@ $_documentContainer.innerHTML = `
--diff-trailing-whitespace-indicator: #ff9ad2;
--light-add-highlight-color: #d8fed8;
--light-rebased-add-highlight-color: #eef;
--light-moved-add-highlight-color: #eef;
--light-remove-add-highlight-color: #fff8dc;
--light-remove-highlight-color: #ffebee;
--coverage-covered: #e0f2f1;

View File

@@ -117,6 +117,7 @@ function getStyleEl() {
--diff-trailing-whitespace-indicator: #ff9ad2;
--light-add-highlight-color: #0f401f;
--light-rebased-add-highlight-color: #487165;
--light-moved-add-highlight-color: #487165;
--light-remove-add-highlight-color: #2f3f2f;
--light-remove-highlight-color: #320404;
--coverage-covered: #112826;

View File

@@ -1123,6 +1123,7 @@ export interface DiffContent {
edit_a?: number[][];
edit_b?: number[][];
due_to_rebase?: boolean;
due_to_move?: boolean;
skip?: string;
common?: string;
keyLocation?: boolean;