summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/notes/components/multiline_comment_form.vue
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/notes/components/multiline_comment_form.vue')
-rw-r--r--app/assets/javascripts/notes/components/multiline_comment_form.vue45
1 files changed, 39 insertions, 6 deletions
diff --git a/app/assets/javascripts/notes/components/multiline_comment_form.vue b/app/assets/javascripts/notes/components/multiline_comment_form.vue
index 5fba011a153..bb13eb87af7 100644
--- a/app/assets/javascripts/notes/components/multiline_comment_form.vue
+++ b/app/assets/javascripts/notes/components/multiline_comment_form.vue
@@ -1,4 +1,5 @@
<script>
+import { mapActions } from 'vuex';
import { GlFormSelect, GlSprintf } from '@gitlab/ui';
import { getSymbol, getLineClasses } from './multiline_comment_utils';
@@ -21,19 +22,51 @@ export default {
},
data() {
return {
- commentLineStart: {
- lineCode: this.lineRange ? this.lineRange.start_line_code : this.line.line_code,
- type: this.lineRange ? this.lineRange.start_line_type : this.line.type,
- },
+ commentLineStart: {},
+ commentLineEndType: this.lineRange?.end?.line_type || this.line.type,
};
},
+ computed: {
+ lineNumber() {
+ return this.commentLineOptions[this.commentLineOptions.length - 1].text;
+ },
+ },
+ created() {
+ const line = this.lineRange?.start || this.line;
+
+ this.commentLineStart = {
+ line_code: line.line_code,
+ type: line.type,
+ old_line: line.old_line,
+ new_line: line.new_line,
+ };
+ this.highlightSelection();
+ },
+ destroyed() {
+ this.setSelectedCommentPosition();
+ },
methods: {
+ ...mapActions(['setSelectedCommentPosition']),
getSymbol({ type }) {
return getSymbol(type);
},
getLineClasses(line) {
return getLineClasses(line);
},
+ updateCommentLineStart(value) {
+ this.commentLineStart = value;
+ this.$emit('input', value);
+ this.highlightSelection();
+ },
+ highlightSelection() {
+ const { line_code, new_line, old_line, type } = this.line;
+ const updatedLineRange = {
+ start: { ...this.commentLineStart },
+ end: { line_code, new_line, old_line, type },
+ };
+
+ this.setSelectedCommentPosition(updatedLineRange);
+ },
},
};
</script>
@@ -55,12 +88,12 @@ export default {
:options="commentLineOptions"
size="sm"
class="gl-w-auto gl-vertical-align-baseline"
- @change="$emit('input', $event)"
+ @change="updateCommentLineStart"
/>
</template>
<template #end>
<span :class="getLineClasses(line)">
- {{ getSymbol(line) + (line.new_line || line.old_line) }}
+ {{ lineNumber }}
</span>
</template>
</gl-sprintf>