| ... | @@ -13,6 +13,8 @@ import { |
... | @@ -13,6 +13,8 @@ import { |
|
|
LINES_TO_BE_RENDERED_DIRECTLY,
|
|
LINES_TO_BE_RENDERED_DIRECTLY,
|
|
|
MAX_LINES_TO_BE_RENDERED,
|
|
MAX_LINES_TO_BE_RENDERED,
|
|
|
TREE_TYPE,
|
|
TREE_TYPE,
|
|
|
|
INLINE_DIFF_VIEW_TYPE,
|
|
|
|
PARALLEL_DIFF_VIEW_TYPE,
|
|
|
} from '../constants';
|
|
} from '../constants';
|
|
|
|
|
|
|
|
export function findDiffFile(files, match, matchKey = 'file_hash') {
|
|
export function findDiffFile(files, match, matchKey = 'file_hash') {
|
| ... | @@ -93,8 +95,7 @@ export function getNoteFormData(params) { |
... | @@ -93,8 +95,7 @@ export function getNoteFormData(params) { |
|
|
export const findIndexInInlineLines = (lines, lineNumbers) => {
|
|
export const findIndexInInlineLines = (lines, lineNumbers) => {
|
|
|
const { oldLineNumber, newLineNumber } = lineNumbers;
|
|
const { oldLineNumber, newLineNumber } = lineNumbers;
|
|
|
|
|
|
|
|
return _.findIndex(
|
|
return lines.findIndex(
|
|
|
lines,
|
|
|
|
|
line => line.old_line === oldLineNumber && line.new_line === newLineNumber,
|
|
line => line.old_line === oldLineNumber && line.new_line === newLineNumber,
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
| ... | @@ -102,8 +103,7 @@ export const findIndexInInlineLines = (lines, lineNumbers) => { |
... | @@ -102,8 +103,7 @@ export const findIndexInInlineLines = (lines, lineNumbers) => { |
|
|
export const findIndexInParallelLines = (lines, lineNumbers) => {
|
|
export const findIndexInParallelLines = (lines, lineNumbers) => {
|
|
|
const { oldLineNumber, newLineNumber } = lineNumbers;
|
|
const { oldLineNumber, newLineNumber } = lineNumbers;
|
|
|
|
|
|
|
|
return _.findIndex(
|
|
return lines.findIndex(
|
|
|
lines,
|
|
|
|
|
line =>
|
|
line =>
|
|
|
line.left &&
|
|
line.left &&
|
|
|
line.right &&
|
|
line.right &&
|
| ... | @@ -112,14 +112,33 @@ export const findIndexInParallelLines = (lines, lineNumbers) => { |
... | @@ -112,14 +112,33 @@ export const findIndexInParallelLines = (lines, lineNumbers) => { |
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
const indexGettersByViewType = {
|
|
|
|
[INLINE_DIFF_VIEW_TYPE]: findIndexInInlineLines,
|
|
|
|
[PARALLEL_DIFF_VIEW_TYPE]: findIndexInParallelLines,
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getPreviousLineIndex = (diffViewType, file, lineNumbers) => {
|
|
|
|
const findIndex = indexGettersByViewType[diffViewType];
|
|
|
|
const lines = {
|
|
|
|
[INLINE_DIFF_VIEW_TYPE]: file.highlighted_diff_lines,
|
|
|
|
[PARALLEL_DIFF_VIEW_TYPE]: file.parallel_diff_lines,
|
|
|
|
};
|
|
|
|
|
|
|
|
return findIndex && findIndex(lines[diffViewType], lineNumbers);
|
|
|
|
};
|
|
|
|
|
|
|
export function removeMatchLine(diffFile, lineNumbers, bottom) {
|
|
export function removeMatchLine(diffFile, lineNumbers, bottom) {
|
|
|
const indexForInline = findIndexInInlineLines(diffFile.highlighted_diff_lines, lineNumbers);
|
|
const indexForInline = findIndexInInlineLines(diffFile.highlighted_diff_lines, lineNumbers);
|
|
|
const indexForParallel = findIndexInParallelLines(diffFile.parallel_diff_lines, lineNumbers);
|
|
const indexForParallel = findIndexInParallelLines(diffFile.parallel_diff_lines, lineNumbers);
|
|
|
const factor = bottom ? 1 : -1;
|
|
const factor = bottom ? 1 : -1;
|
|
|
|
|
|
|
|
|
if (indexForInline > -1) {
|
|
|
diffFile.highlighted_diff_lines.splice(indexForInline + factor, 1);
|
|
diffFile.highlighted_diff_lines.splice(indexForInline + factor, 1);
|
|
|
|
}
|
|
|
|
if (indexForParallel > -1) {
|
|
|
diffFile.parallel_diff_lines.splice(indexForParallel + factor, 1);
|
|
diffFile.parallel_diff_lines.splice(indexForParallel + factor, 1);
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function addLineReferences(lines, lineNumbers, bottom, isExpandDown, nextLineNumbers) {
|
|
export function addLineReferences(lines, lineNumbers, bottom, isExpandDown, nextLineNumbers) {
|
|
|
const { oldLineNumber, newLineNumber } = lineNumbers;
|
|
const { oldLineNumber, newLineNumber } = lineNumbers;
|
| ... | @@ -160,8 +179,8 @@ export function addLineReferences(lines, lineNumbers, bottom, isExpandDown, next |
... | @@ -160,8 +179,8 @@ export function addLineReferences(lines, lineNumbers, bottom, isExpandDown, next |
|
|
return linesWithNumbers;
|
|
return linesWithNumbers;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function addContextLines(options) {
|
|
function addParallelContextLines(options) {
|
|
|
const { inlineLines, parallelLines, contextLines, lineNumbers, isExpandDown } = options;
|
|
const { parallelLines, contextLines, lineNumbers, isExpandDown } = options;
|
|
|
const normalizedParallelLines = contextLines.map(line => ({
|
|
const normalizedParallelLines = contextLines.map(line => ({
|
|
|
left: line,
|
|
left: line,
|
|
|
right: line,
|
|
right: line,
|
| ... | @@ -170,17 +189,40 @@ export function addContextLines(options) { |
... | @@ -170,17 +189,40 @@ export function addContextLines(options) { |
|
|
const factor = isExpandDown ? 1 : 0;
|
|
const factor = isExpandDown ? 1 : 0;
|
|
|
|
|
|
|
|
if (!isExpandDown && options.bottom) {
|
|
if (!isExpandDown && options.bottom) {
|
|
|
inlineLines.push(...contextLines);
|
|
|
|
|
parallelLines.push(...normalizedParallelLines);
|
|
parallelLines.push(...normalizedParallelLines);
|
|
|
} else {
|
|
} else {
|
|
|
const inlineIndex = findIndexInInlineLines(inlineLines, lineNumbers);
|
|
|
|
|
const parallelIndex = findIndexInParallelLines(parallelLines, lineNumbers);
|
|
const parallelIndex = findIndexInParallelLines(parallelLines, lineNumbers);
|
|
|
|
|
|
|
|
inlineLines.splice(inlineIndex + factor, 0, ...contextLines);
|
|
|
|
|
parallelLines.splice(parallelIndex + factor, 0, ...normalizedParallelLines);
|
|
parallelLines.splice(parallelIndex + factor, 0, ...normalizedParallelLines);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
function addInlineContextLines(options) {
|
|
|
|
const { inlineLines, contextLines, lineNumbers, isExpandDown } = options;
|
|
|
|
const factor = isExpandDown ? 1 : 0;
|
|
|
|
|
|
|
|
if (!isExpandDown && options.bottom) {
|
|
|
|
inlineLines.push(...contextLines);
|
|
|
|
} else {
|
|
|
|
const inlineIndex = findIndexInInlineLines(inlineLines, lineNumbers);
|
|
|
|
|
|
|
|
inlineLines.splice(inlineIndex + factor, 0, ...contextLines);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function addContextLines(options) {
|
|
|
|
const { diffViewType } = options;
|
|
|
|
const contextLineHandlers = {
|
|
|
|
[INLINE_DIFF_VIEW_TYPE]: addInlineContextLines,
|
|
|
|
[PARALLEL_DIFF_VIEW_TYPE]: addParallelContextLines,
|
|
|
|
};
|
|
|
|
const contextLineHandler = contextLineHandlers[diffViewType];
|
|
|
|
|
|
|
|
if (contextLineHandler) {
|
|
|
|
contextLineHandler(options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Trims the first char of the `richText` property when it's either a space or a diff symbol.
|
|
* Trims the first char of the `richText` property when it's either a space or a diff symbol.
|
|
|
* @param {Object} line
|
|
* @param {Object} line
|
| ... | |
... | |
| ... | | ... | |