diff options
author | Douwe Maan <douwe@selenight.nl> | 2019-01-22 13:35:28 +0100 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2019-01-22 17:00:16 +0100 |
commit | 03df54b226f63a05ee2229b9f7f1f3e90383430a (patch) | |
tree | 80d6ac7c25481460947d3bf6f6fa18eee8237da4 /app/assets/javascripts/notes/stores | |
parent | ed1da730202bf3178c43b3467635853733b799c1 (diff) | |
download | gitlab-ce-03df54b226f63a05ee2229b9f7f1f3e90383430a.tar.gz |
Trim first char of diff line text on diff discussions
Before, diff file `higlighted_diff_lines`/`parallel_diff_lines` and
diff discussion `truncated_diff_lines` were inconsistent: `text` and
`rich_text` on the latter included the leading +/-/<space> character,
like on the backend, while the former had no `text` and its `rich_text`
had dropped this char.
This resulted in a bug when the suggestions feature expected these diff
line objects to be identical in format and thus interchangeable, which
was not the case.
Diffstat (limited to 'app/assets/javascripts/notes/stores')
-rw-r--r-- | app/assets/javascripts/notes/stores/mutations.js | 7 | ||||
-rw-r--r-- | app/assets/javascripts/notes/stores/utils.js | 4 |
2 files changed, 9 insertions, 2 deletions
diff --git a/app/assets/javascripts/notes/stores/mutations.js b/app/assets/javascripts/notes/stores/mutations.js index 8992454be2e..33d39ad2ec9 100644 --- a/app/assets/javascripts/notes/stores/mutations.js +++ b/app/assets/javascripts/notes/stores/mutations.js @@ -105,7 +105,10 @@ export default { if (discussion.diff_file) { diffData.file_hash = discussion.diff_file.file_hash; - diffData.truncated_diff_lines = discussion.truncated_diff_lines || []; + + diffData.truncated_diff_lines = utils.prepareDiffLines( + discussion.truncated_diff_lines || [], + ); } // To support legacy notes, should be very rare case. @@ -243,7 +246,7 @@ export default { [types.SET_DISCUSSION_DIFF_LINES](state, { discussionId, diffLines }) { const discussion = utils.findNoteObjectById(state.discussions, discussionId); - discussion.truncated_diff_lines = diffLines; + discussion.truncated_diff_lines = utils.prepareDiffLines(diffLines); }, [types.DISABLE_COMMENTS](state, value) { diff --git a/app/assets/javascripts/notes/stores/utils.js b/app/assets/javascripts/notes/stores/utils.js index dd57539e4d8..4b0feb0f94d 100644 --- a/app/assets/javascripts/notes/stores/utils.js +++ b/app/assets/javascripts/notes/stores/utils.js @@ -1,4 +1,5 @@ import AjaxCache from '~/lib/utils/ajax_cache'; +import { trimFirstCharOfLineContent } from '~/diffs/store/utils'; const REGEX_QUICK_ACTIONS = /^\/\w+.*$/gm; @@ -28,3 +29,6 @@ export const getQuickActionText = note => { export const hasQuickActions = note => REGEX_QUICK_ACTIONS.test(note); export const stripQuickActions = note => note.replace(REGEX_QUICK_ACTIONS, '').trim(); + +export const prepareDiffLines = diffLines => + diffLines.map(line => ({ ...trimFirstCharOfLineContent(line) })); |