Commit c821d7d5 authored by Phil Hughes's avatar Phil Hughes

Fixes suggestions with new line characters not working

Fixes a bug where new lines in the suggestions content
would insert a new line instead of the new line character.

Changelog: fixed

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/333351
parent 93d73652
...@@ -232,7 +232,7 @@ export function insertMarkdownText({ ...@@ -232,7 +232,7 @@ export function insertMarkdownText({
.join('\n'); .join('\n');
} }
} else if (tag.indexOf(textPlaceholder) > -1) { } else if (tag.indexOf(textPlaceholder) > -1) {
textToInsert = tag.replace(textPlaceholder, () => selected.replace(/\\n/g, '\n')); textToInsert = tag.replace(textPlaceholder, () => selected);
} else { } else {
textToInsert = String(startChar) + tag + selected + (wrap ? tag : ''); textToInsert = String(startChar) + tag + selected + (wrap ? tag : '');
} }
......
...@@ -70,6 +70,25 @@ describe('init markdown', () => { ...@@ -70,6 +70,25 @@ describe('init markdown', () => {
expect(textArea.value).toContain('# Does not parse the `$` currently.'); expect(textArea.value).toContain('# Does not parse the `$` currently.');
}); });
it('inserts a new line correctly', () => {
const initialValue = '';
textArea.value = initialValue;
textArea.selectionStart = 0;
textArea.selectionEnd = 0;
insertMarkdownText({
textArea,
text: textArea.value,
tag: '```suggestion:-0+0\n{text}\n```',
blockTag: true,
selected: '# Does not parse the \\n currently.',
wrap: false,
});
expect(textArea.value).toContain('# Does not parse the \\n currently.');
});
it('inserts the tag on a new line if the current one is not empty', () => { it('inserts the tag on a new line if the current one is not empty', () => {
const initialValue = 'some text'; const initialValue = 'some text';
......
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