Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/diffs/components/diff_expansion_cell.vue')
-rw-r--r--app/assets/javascripts/diffs/components/diff_expansion_cell.vue24
1 files changed, 19 insertions, 5 deletions
diff --git a/app/assets/javascripts/diffs/components/diff_expansion_cell.vue b/app/assets/javascripts/diffs/components/diff_expansion_cell.vue
index 23fbfc2b74b..4eae2e09c08 100644
--- a/app/assets/javascripts/diffs/components/diff_expansion_cell.vue
+++ b/app/assets/javascripts/diffs/components/diff_expansion_cell.vue
@@ -3,7 +3,7 @@ import { mapState, mapActions } from 'vuex';
import createFlash from '~/flash';
import { s__ } from '~/locale';
import Icon from '~/vue_shared/components/icon.vue';
-import { UNFOLD_COUNT } from '../constants';
+import { UNFOLD_COUNT, INLINE_DIFF_VIEW_TYPE, PARALLEL_DIFF_VIEW_TYPE } from '../constants';
import * as utils from '../store/utils';
import tooltip from '../../vue_shared/directives/tooltip';
@@ -11,6 +11,16 @@ const EXPAND_ALL = 0;
const EXPAND_UP = 1;
const EXPAND_DOWN = 2;
+const lineNumberByViewType = (viewType, diffLine) => {
+ const numberGetters = {
+ [INLINE_DIFF_VIEW_TYPE]: line => line?.new_line,
+ [PARALLEL_DIFF_VIEW_TYPE]: line => (line?.right || line?.left)?.new_line,
+ };
+ const numberGetter = numberGetters[viewType];
+
+ return numberGetter && numberGetter(diffLine);
+};
+
export default {
directives: {
tooltip,
@@ -67,12 +77,16 @@ export default {
...mapActions('diffs', ['loadMoreLines']),
getPrevLineNumber(oldLineNumber, newLineNumber) {
const diffFile = utils.findDiffFile(this.diffFiles, this.fileHash);
- const indexForInline = utils.findIndexInInlineLines(diffFile.highlighted_diff_lines, {
+ const lines = {
+ [INLINE_DIFF_VIEW_TYPE]: diffFile.highlighted_diff_lines,
+ [PARALLEL_DIFF_VIEW_TYPE]: diffFile.parallel_diff_lines,
+ };
+ const index = utils.getPreviousLineIndex(this.diffViewType, diffFile, {
oldLineNumber,
newLineNumber,
});
- const prevLine = diffFile.highlighted_diff_lines[indexForInline - 2];
- return (prevLine && prevLine.new_line) || 0;
+
+ return lineNumberByViewType(this.diffViewType, lines[this.diffViewType][index - 2]) || 0;
},
callLoadMoreLines(
endpoint,
@@ -114,7 +128,7 @@ export default {
this.handleExpandAllLines(expandOptions);
}
},
- handleExpandUpLines(expandOptions = EXPAND_ALL) {
+ handleExpandUpLines(expandOptions) {
const { endpoint, fileHash, view, oldLineNumber, newLineNumber, offset } = expandOptions;
const bottom = this.isBottom;