Path: blob/main/src/vs/editor/common/diff/defaultLinesDiffComputer/lineSequence.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { CharCode } from '../../../../base/common/charCode.js';6import { OffsetRange } from '../../core/ranges/offsetRange.js';7import { ISequence } from './algorithms/diffAlgorithm.js';89export class LineSequence implements ISequence {10constructor(11private readonly trimmedHash: number[],12private readonly lines: string[]13) { }1415getElement(offset: number): number {16return this.trimmedHash[offset];17}1819get length(): number {20return this.trimmedHash.length;21}2223getBoundaryScore(length: number): number {24const indentationBefore = length === 0 ? 0 : getIndentation(this.lines[length - 1]);25const indentationAfter = length === this.lines.length ? 0 : getIndentation(this.lines[length]);26return 1000 - (indentationBefore + indentationAfter);27}2829getText(range: OffsetRange): string {30return this.lines.slice(range.start, range.endExclusive).join('\n');31}3233isStronglyEqual(offset1: number, offset2: number): boolean {34return this.lines[offset1] === this.lines[offset2];35}36}3738function getIndentation(str: string): number {39let i = 0;40while (i < str.length && (str.charCodeAt(i) === CharCode.Space || str.charCodeAt(i) === CharCode.Tab)) {41i++;42}43return i;44}454647