2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { Range } from '../../../core/range.js';
7
>
import { Length, lengthAdd, lengthDiffNonNegative, lengthLessThanEqual, lengthOfString, lengthToObj, positionToLength, toLength } from './length.js';
8
>
import { TextLength } from '../../../core/text/textLength.js';
9
>
import { IModelContentChange } from '../../mirrorTextModel.js';
10
>
11
>
export class TextEditInfo {
12
>
public static fromModelContentChanges(changes: IModelContentChange[]): TextEditInfo[] {
13
>
// Must be sorted in ascending order
14
>
const edits = changes.map(c => {
15
>
const range = Range.lift(c.range);
16
>
return new TextEditInfo(
17
>
positionToLength(range.getStartPosition()),
18
>
positionToLength(range.getEndPosition()),
19
>
lengthOfString(c.text)
20
>
);
21
>
}).reverse();
22
>
return edits;
23
>
}
24
>
25
>
constructor(
26
public readonly startOffset: Length,
27
public readonly endOffset: Length,