beforeEditPositionMapper.ts ×11

Frontier kind: Code frontier

unlabeled · c_701f8acbf255

870 tests · 5859 LOC · 33 files · introduces 0 tests · 68 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
11 ranges68 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
917 ranges5859 lines · 33 files · Browse complete extent
All tests (intent)
870 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 68 introduced LOC across 11 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/beforeEditPositionMapper.ts 68 introduced LOC · 11 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- beforeEditPositionMapper.ts
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,
29 ) {
30 }
32 > toString(): string {
33 return `[${lengthToObj(this.startOffset)}...${lengthToObj(this.endOffset)}) -> ${lengthToObj(this.newLength)}`;
34 }
36 >
37 > export class BeforeEditPositionMapper {
38 > private nextEditIdx = 0;
39 > private deltaOldToNewLineCount = 0;
40 > private deltaOldToNewColumnCount = 0;
41 > private deltaLineIdxInOld = -1;
42 > private readonly edits: readonly TextEditInfoCache[];
43 >
44 > /**
45 > * @param edits Must be sorted by offset in ascending order.
46 > */
47 > constructor(
48 edits: readonly TextEditInfo[],
49 ) {
50 this.edits = edits.map(edit => TextEditInfoCache.from(edit));
51 }
53 > /**
54 > * @param offset Must be equal to or greater than the last offset this method has been called with.
55 > */
56 > getOffsetBeforeChange(offset: Length): Length {
57 this.adjustNextEdit(offset);
58 return this.translateCurToOld(offset);
59 }
61 > /**
62 > * @param offset Must be equal to or greater than the last offset this method has been called with.
63 > * Returns null if there is no edit anymore.
64 > */
65 > getDistanceToNextChange(offset: Length): Length | null {
66 this.adjustNextEdit(offset);
67
74 return lengthDiffNonNegative(offset, nextChangeOffset);
75 }
77 > private translateOldToCur(oldOffsetObj: TextLength): Length {
78 if (oldOffsetObj.lineCount === this.deltaLineIdxInOld) {
79 return toLength(oldOffsetObj.lineCount + this.deltaOldToNewLineCount, oldOffsetObj.columnCount + this.deltaOldToNewColumnCount);
82 }
83 }
85 > private translateCurToOld(newOffset: Length): Length {
86 const offsetObj = lengthToObj(newOffset);
87 if (offsetObj.lineCount - this.deltaOldToNewLineCount === this.deltaLineIdxInOld) {
91 }
92 }
94 > private adjustNextEdit(offset: Length) {
95 while (this.nextEditIdx < this.edits.length) {
96 const nextEdit = this.edits[this.nextEditIdx];
121 }
122 }
124 >
125 > class TextEditInfoCache {
126 > static from(edit: TextEditInfo): TextEditInfoCache {
127 return new TextEditInfoCache(edit.startOffset, edit.endOffset, edit.newLength);
128 }
130 > public readonly endOffsetBeforeObj: TextLength;
131 > public readonly endOffsetAfterObj: TextLength;
132 > public readonly offsetObj: TextLength;
133 >
134 > constructor(
135 startOffset: Length,
136 endOffset: Length,