Commit e6f1209e authored by Phil Hughes's avatar Phil Hughes

Fixes diff sugestions removing dashes from diff

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/55634
parent c20f0564
...@@ -89,7 +89,6 @@ export default { ...@@ -89,7 +89,6 @@ export default {
return this.referencedUsers.length >= referencedUsersThreshold; return this.referencedUsers.length >= referencedUsersThreshold;
}, },
lineContent() { lineContent() {
const FIRST_CHAR_REGEX = /^(\+|-)/;
const [firstSuggestion] = this.suggestions; const [firstSuggestion] = this.suggestions;
if (firstSuggestion) { if (firstSuggestion) {
return firstSuggestion.from_content; return firstSuggestion.from_content;
...@@ -99,7 +98,7 @@ export default { ...@@ -99,7 +98,7 @@ export default {
const { rich_text: richText, text } = this.line; const { rich_text: richText, text } = this.line;
if (text) { if (text) {
return text.replace(FIRST_CHAR_REGEX, ''); return text;
} }
return _.unescape(stripHtml(richText).replace(/\n/g, '')); return _.unescape(stripHtml(richText).replace(/\n/g, ''));
......
...@@ -82,13 +82,12 @@ export default { ...@@ -82,13 +82,12 @@ export default {
// extracts the suggested lines from the markdown // extracts the suggested lines from the markdown
// calculates a line number for each line // calculates a line number for each line
const FIRST_CHAR_REGEX = /^(\+|-)/;
const newLines = suggestionEl.querySelectorAll('.line'); const newLines = suggestionEl.querySelectorAll('.line');
const fromLine = this.suggestions.length ? this.suggestions[0].from_line : this.fromLine; const fromLine = this.suggestions.length ? this.suggestions[0].from_line : this.fromLine;
const lines = []; const lines = [];
newLines.forEach((line, i) => { newLines.forEach((line, i) => {
const content = `${line.innerText.replace(FIRST_CHAR_REGEX, '')}\n`; const content = `${line.innerText}\n`;
const lineNumber = fromLine + i; const lineNumber = fromLine + i;
lines.push({ content, lineNumber }); lines.push({ content, lineNumber });
}); });
......
---
title: Fixed diff suggestions removing dashes
merge_request:
author:
type: fixed
...@@ -29,7 +29,7 @@ const generateLine = content => { ...@@ -29,7 +29,7 @@ const generateLine = content => {
const generateMockLines = () => { const generateMockLines = () => {
const line1 = generateLine('Line 1'); const line1 = generateLine('Line 1');
const line2 = generateLine('Line 2'); const line2 = generateLine('Line 2');
const line3 = generateLine('Line 3'); const line3 = generateLine('- Line 3');
const container = document.createElement('div'); const container = document.createElement('div');
container.appendChild(line1); container.appendChild(line1);
...@@ -80,7 +80,7 @@ describe('Suggestion component', () => { ...@@ -80,7 +80,7 @@ describe('Suggestion component', () => {
const expectedReturn = [ const expectedReturn = [
{ content: 'Line 1\n', lineNumber: 1 }, { content: 'Line 1\n', lineNumber: 1 },
{ content: 'Line 2\n', lineNumber: 2 }, { content: 'Line 2\n', lineNumber: 2 },
{ content: 'Line 3\n', lineNumber: 3 }, { content: '- Line 3\n', lineNumber: 3 },
]; ];
expect(vm.extractNewLines(generateMockLines())).toEqual(expectedReturn); expect(vm.extractNewLines(generateMockLines())).toEqual(expectedReturn);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment