16
17
export function computeMovedLines(
19
>
originalLines: string[],
20
>
modifiedLines: string[],
21
>
hashedOriginalLines: number[],
22
>
hashedModifiedLines: number[],
23
>
timeout: ITimeout
24
>
): LineRangeMapping[] {
25
>
let { moves, excludedChanges } = computeMovesFromSimpleDeletionsToSimpleInsertions(changes, originalLines, modifiedLines, timeout);
26
>
27
>
if (!timeout.isValid()) { return []; }
28
>
29
>
const filteredChanges = changes.filter(c => !excludedChanges.has(c));
30
>
const unchangedMoves = computeUnchangedMoves(filteredChanges, hashedOriginalLines, hashedModifiedLines, originalLines, modifiedLines, timeout);
31
>
pushMany(moves, unchangedMoves);
32
>
33
>
moves = joinCloseConsecutiveMoves(moves);
34
>
// Ignore too short moves
35
>
moves = moves.filter(current => {
36
const lines = current.original.toOffsetRange().slice(originalLines).map(l => l.trim());
37
const originalText = lines.join('\n');
38
return originalText.length >= 15 && countWhere(lines, l => l.length >= 2) >= 2;
40
>
moves = removeMovesInSameDiff(changes, moves);
41
>
42
>
return moves;
43
>
}
44
45
function countWhere<T>(arr: T[], predicate: (t: T) => boolean): number {