diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js index 122ec138c59..1580bb67d65 100644 --- a/app/assets/javascripts/lib/utils/common_utils.js +++ b/app/assets/javascripts/lib/utils/common_utils.js @@ -162,10 +162,11 @@ gl.utils.scrollToElement = function($el) { var top = $el.offset().top; - gl.mrTabsHeight = gl.mrTabsHeight || $('.merge-request-tabs').height(); + var mrTabsHeight = $('.merge-request-tabs').height() || 0; + var headerHeight = $('.navbar-gitlab').height() || 0; return $('body, html').animate({ - scrollTop: top - (gl.mrTabsHeight) + scrollTop: top - mrTabsHeight - headerHeight }, 200); }; diff --git a/app/assets/javascripts/notes/components/issue_note.vue b/app/assets/javascripts/notes/components/issue_note.vue index f0b0750fdd9..a3203e529ed 100644 --- a/app/assets/javascripts/notes/components/issue_note.vue +++ b/app/assets/javascripts/notes/components/issue_note.vue @@ -1,6 +1,7 @@ @@ -79,7 +82,9 @@ export default { v-if="actionTextHtml" v-html="actionTextHtml" class="system-note-message"> - + diff --git a/app/assets/javascripts/notes/components/issue_notes.vue b/app/assets/javascripts/notes/components/issue_notes.vue index d22253d231d..d7ca0e3f688 100644 --- a/app/assets/javascripts/notes/components/issue_notes.vue +++ b/app/assets/javascripts/notes/components/issue_notes.vue @@ -43,6 +43,19 @@ export default { componentData(note) { return note.individual_note ? note.notes[0] : note; }, + checkLocationHash() { + const hash = gl.utils.getLocationHash(); + const $el = $(`#${hash}`); + + if (hash && $el) { + const isInViewport = gl.utils.isInViewport($el[0]); + this.$store.commit('setTargetNoteHash', hash); + + if (!isInViewport) { + gl.utils.scrollToElement($el); + } + } + }, }, mounted() { const { discussionsPath, notesPath, lastFetchedAt } = this.$el.parentNode.dataset; @@ -50,6 +63,11 @@ export default { this.$store.dispatch('fetchNotes', discussionsPath) .then(() => { this.isLoading = false; + + // Scroll to note if we have hash fragment in the page URL + Vue.nextTick(() => { + this.checkLocationHash(); + }); }) .catch(() => { new Flash('Something went wrong while fetching issue comments. Please try again.'); // eslint-disable-line diff --git a/app/assets/javascripts/notes/components/issue_system_note.vue b/app/assets/javascripts/notes/components/issue_system_note.vue index 220b15675db..0763f44552e 100644 --- a/app/assets/javascripts/notes/components/issue_system_note.vue +++ b/app/assets/javascripts/notes/components/issue_system_note.vue @@ -1,4 +1,5 @@