2018-06-27 21:20:41 +00:00
|
|
|
<script>
|
2018-09-20 08:21:17 +00:00
|
|
|
import { mapActions } from 'vuex';
|
2018-06-27 21:20:41 +00:00
|
|
|
import $ from 'jquery';
|
|
|
|
import DiffTableCell from './diff_table_cell.vue';
|
|
|
|
import {
|
|
|
|
NEW_LINE_TYPE,
|
|
|
|
OLD_LINE_TYPE,
|
2018-11-07 21:57:26 +00:00
|
|
|
CONTEXT_LINE_TYPE,
|
|
|
|
CONTEXT_LINE_CLASS_NAME,
|
2018-06-27 21:20:41 +00:00
|
|
|
OLD_NO_NEW_LINE_TYPE,
|
|
|
|
PARALLEL_DIFF_VIEW_TYPE,
|
|
|
|
NEW_NO_NEW_LINE_TYPE,
|
2018-08-06 21:13:34 +00:00
|
|
|
EMPTY_CELL_TYPE,
|
2018-06-27 21:20:41 +00:00
|
|
|
} from '../constants';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
DiffTableCell,
|
|
|
|
},
|
|
|
|
props: {
|
2018-07-17 15:47:02 +00:00
|
|
|
fileHash: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
contextLinesPath: {
|
|
|
|
type: String,
|
2018-06-27 21:20:41 +00:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
line: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
isBottom: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isLeftHover: false,
|
|
|
|
isRightHover: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2018-11-07 21:57:26 +00:00
|
|
|
isContextLine() {
|
|
|
|
return this.line.left && this.line.left.type === CONTEXT_LINE_TYPE;
|
|
|
|
},
|
2018-06-27 21:20:41 +00:00
|
|
|
classNameMap() {
|
|
|
|
return {
|
2018-11-07 21:57:26 +00:00
|
|
|
[CONTEXT_LINE_CLASS_NAME]: this.isContextLine,
|
2018-08-06 21:13:34 +00:00
|
|
|
[PARALLEL_DIFF_VIEW_TYPE]: true,
|
2018-06-27 21:20:41 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
parallelViewLeftLineType() {
|
2018-08-06 21:13:34 +00:00
|
|
|
if (this.line.right && this.line.right.type === NEW_NO_NEW_LINE_TYPE) {
|
2018-06-27 21:20:41 +00:00
|
|
|
return OLD_NO_NEW_LINE_TYPE;
|
|
|
|
}
|
|
|
|
|
2018-08-06 21:13:34 +00:00
|
|
|
return this.line.left ? this.line.left.type : EMPTY_CELL_TYPE;
|
2018-06-27 21:20:41 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.newLineType = NEW_LINE_TYPE;
|
|
|
|
this.oldLineType = OLD_LINE_TYPE;
|
2018-07-03 23:18:27 +00:00
|
|
|
this.parallelDiffViewType = PARALLEL_DIFF_VIEW_TYPE;
|
2018-06-27 21:20:41 +00:00
|
|
|
},
|
2018-09-20 08:21:17 +00:00
|
|
|
mounted() {
|
|
|
|
this.scrollToLineIfNeededParallel(this.line);
|
|
|
|
},
|
2018-06-27 21:20:41 +00:00
|
|
|
methods: {
|
2018-09-20 08:21:17 +00:00
|
|
|
...mapActions('diffs', ['scrollToLineIfNeededParallel']),
|
2018-06-27 21:20:41 +00:00
|
|
|
handleMouseMove(e) {
|
|
|
|
const isHover = e.type === 'mouseover';
|
2018-07-03 23:18:27 +00:00
|
|
|
const hoveringCell = e.target.closest('td');
|
|
|
|
const allCellsInHoveringRow = Array.from(e.currentTarget.children);
|
|
|
|
const hoverIndex = allCellsInHoveringRow.indexOf(hoveringCell);
|
2018-06-27 21:20:41 +00:00
|
|
|
|
2018-07-03 23:18:27 +00:00
|
|
|
if (hoverIndex >= 2) {
|
|
|
|
this.isRightHover = isHover;
|
2018-06-27 21:20:41 +00:00
|
|
|
} else {
|
2018-07-03 23:18:27 +00:00
|
|
|
this.isLeftHover = isHover;
|
2018-06-27 21:20:41 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// Prevent text selecting on both sides of parallel diff view
|
|
|
|
// Backport of the same code from legacy diff notes.
|
|
|
|
handleParallelLineMouseDown(e) {
|
|
|
|
const line = $(e.currentTarget);
|
|
|
|
const table = line.closest('table');
|
|
|
|
|
|
|
|
table.removeClass('left-side-selected right-side-selected');
|
|
|
|
const [lineClass] = ['left-side', 'right-side'].filter(name => line.hasClass(name));
|
|
|
|
|
|
|
|
if (lineClass) {
|
|
|
|
table.addClass(`${lineClass}-selected`);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<tr
|
|
|
|
:class="classNameMap"
|
|
|
|
class="line_holder"
|
|
|
|
@mouseover="handleMouseMove"
|
|
|
|
@mouseout="handleMouseMove"
|
|
|
|
>
|
2018-08-06 21:13:34 +00:00
|
|
|
<template v-if="line.left">
|
|
|
|
<diff-table-cell
|
|
|
|
:file-hash="fileHash"
|
|
|
|
:context-lines-path="contextLinesPath"
|
|
|
|
:line="line.left"
|
|
|
|
:line-type="oldLineType"
|
|
|
|
:is-bottom="isBottom"
|
|
|
|
:is-hover="isLeftHover"
|
|
|
|
:show-comment-button="true"
|
|
|
|
:diff-view-type="parallelDiffViewType"
|
|
|
|
line-position="left"
|
|
|
|
class="diff-line-num old_line"
|
|
|
|
/>
|
|
|
|
<td
|
|
|
|
:id="line.left.lineCode"
|
|
|
|
:class="parallelViewLeftLineType"
|
|
|
|
class="line_content parallel left-side"
|
|
|
|
@mousedown.native="handleParallelLineMouseDown"
|
|
|
|
v-html="line.left.richText"
|
|
|
|
>
|
|
|
|
</td>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<td class="diff-line-num old_line empty-cell"></td>
|
|
|
|
<td class="line_content parallel left-side empty-cell"></td>
|
|
|
|
</template>
|
|
|
|
<template v-if="line.right">
|
|
|
|
<diff-table-cell
|
|
|
|
:file-hash="fileHash"
|
|
|
|
:context-lines-path="contextLinesPath"
|
|
|
|
:line="line.right"
|
|
|
|
:line-type="newLineType"
|
|
|
|
:is-bottom="isBottom"
|
|
|
|
:is-hover="isRightHover"
|
|
|
|
:show-comment-button="true"
|
|
|
|
:diff-view-type="parallelDiffViewType"
|
|
|
|
line-position="right"
|
|
|
|
class="diff-line-num new_line"
|
|
|
|
/>
|
|
|
|
<td
|
|
|
|
:id="line.right.lineCode"
|
|
|
|
:class="line.right.type"
|
|
|
|
class="line_content parallel right-side"
|
|
|
|
@mousedown.native="handleParallelLineMouseDown"
|
|
|
|
v-html="line.right.richText"
|
|
|
|
>
|
|
|
|
</td>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<td class="diff-line-num old_line empty-cell"></td>
|
|
|
|
<td class="line_content parallel right-side empty-cell"></td>
|
|
|
|
</template>
|
2018-06-27 21:20:41 +00:00
|
|
|
</tr>
|
|
|
|
</template>
|