diff options
author | Phil Hughes <me@iamphill.com> | 2017-05-18 09:39:29 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-05-18 09:39:29 +0000 |
commit | 010e1dacaba3e7626d9066b470402262e7bbb54b (patch) | |
tree | ba173732bfb2daa5d8809afeb89ed7298390fe8c /app | |
parent | 994532683d4321d920e27b87ef31da61159426ed (diff) | |
parent | f21a31559031c283cbc9cf99a11e98fa519ca0e5 (diff) | |
download | gitlab-ce-010e1dacaba3e7626d9066b470402262e7bbb54b.tar.gz |
Merge branch '32449-fix-note-comparison-trailing-newline-edge-case' into 'master'
Fix note flicker with note you can't edit and trailing new line edge case
Closes #32449
See merge request !11472
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/notes.js | 42 | ||||
-rw-r--r-- | app/views/shared/notes/_edit.html.haml | 2 | ||||
-rw-r--r-- | app/views/shared/notes/_note.html.haml | 2 |
3 files changed, 24 insertions, 22 deletions
diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index 766d71974d5..e960f1e8018 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -307,7 +307,7 @@ const normalizeNewlines = function(str) { } const $note = $notesList.find(`#note_${noteEntity.id}`); - if (this.isNewNote(noteEntity)) { + if (Notes.isNewNote(noteEntity, this.note_ids)) { this.note_ids.push(noteEntity.id); const $newNote = Notes.animateAppendNote(noteEntity.html, $notesList); @@ -320,7 +320,7 @@ const normalizeNewlines = function(str) { return this.updateNotesCount(1); } // The server can send the same update multiple times so we need to make sure to only update once per actual update. - else if (this.isUpdatedNote(noteEntity, $note)) { + else if (Notes.isUpdatedNote(noteEntity, $note)) { const isEditing = $note.hasClass('is-editing'); const initialContent = normalizeNewlines( $note.find('.original-note-content').text().trim() @@ -348,23 +348,6 @@ const normalizeNewlines = function(str) { } }; - /* - Check if note does not exists on page - */ - - Notes.prototype.isNewNote = function(noteEntity) { - return $.inArray(noteEntity.id, this.note_ids) === -1; - }; - - Notes.prototype.isUpdatedNote = function(noteEntity, $note) { - // There can be CRLF vs LF mismatches if we don't sanitize and compare the same way - const sanitizedNoteNote = normalizeNewlines(noteEntity.note); - const currentNoteText = normalizeNewlines( - $note.find('.original-note-content').text().trim() - ); - return sanitizedNoteNote !== currentNoteText; - }; - Notes.prototype.isParallelView = function() { return Cookies.get('diff_view') === 'parallel'; }; @@ -377,7 +360,7 @@ const normalizeNewlines = function(str) { Notes.prototype.renderDiscussionNote = function(noteEntity, $form) { var discussionContainer, form, row, lineType, diffAvatarContainer; - if (!this.isNewNote(noteEntity)) { + if (!Notes.isNewNote(noteEntity, this.note_ids)) { return; } this.note_ids.push(noteEntity.id); @@ -1138,6 +1121,25 @@ const normalizeNewlines = function(str) { return $form; }; + /** + * Check if note does not exists on page + */ + Notes.isNewNote = function(noteEntity, noteIds) { + return $.inArray(noteEntity.id, noteIds) === -1; + }; + + /** + * Check if $note already contains the `noteEntity` content + */ + Notes.isUpdatedNote = function(noteEntity, $note) { + // There can be CRLF vs LF mismatches if we don't sanitize and compare the same way + const sanitizedNoteEntityText = normalizeNewlines(noteEntity.note.trim()); + const currentNoteText = normalizeNewlines( + $note.find('.original-note-content').text().trim() + ); + return sanitizedNoteEntityText !== currentNoteText; + }; + Notes.checkMergeRequestStatus = function() { if (gl.utils.getPagePath(1) === 'merge_requests') { gl.mrWidget.checkStatus(); diff --git a/app/views/shared/notes/_edit.html.haml b/app/views/shared/notes/_edit.html.haml index 4a020865828..f4b3aac29b4 100644 --- a/app/views/shared/notes/_edit.html.haml +++ b/app/views/shared/notes/_edit.html.haml @@ -1,3 +1 @@ -.original-note-content.hidden{ data: { post_url: note_url(note), target_id: note.noteable.id, target_type: note.noteable.class.name.underscore } } - #{note.note} %textarea.hidden.js-task-list-field.original-task-list{ data: {update_url: note_url(note) } }= note.note diff --git a/app/views/shared/notes/_note.html.haml b/app/views/shared/notes/_note.html.haml index 87aae793966..53d0e837aa0 100644 --- a/app/views/shared/notes/_note.html.haml +++ b/app/views/shared/notes/_note.html.haml @@ -43,6 +43,8 @@ .note-text.md = note.redacted_note_html = edited_time_ago_with_tooltip(note, placement: 'bottom', html_class: 'note_edited_ago') + .original-note-content.hidden{ data: { post_url: note_url(note), target_id: note.noteable.id, target_type: note.noteable.class.name.underscore } } + #{note.note} - if note_editable = render 'shared/notes/edit', note: note .note-awards |