textModel.ts ×10

Frontier kind: Code frontier

unlabeled · c_3fe0266787ba

351 tests · 40620 LOC · 238 files · introduces 0 tests · 104 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
18 ranges104 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
4925 ranges40620 lines · 238 files · Browse complete extent
All tests (intent)
351 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.

3 files ranked by introduced lines: 104 introduced LOC across 18 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/model/textModel.ts 54 introduced LOC · 10 ranges

Open complete file

1294
1295 private _validateEditOperation(rawOperation: model.IIdentifiedSingleEditOperation): model.ValidAnnotatedEditOperation {
1296 > if (rawOperation instanceof model.ValidAnnotatedEditOperation) { textModel.ts
1297 return rawOperation;
1298 }
1299 > textModel.ts
1300 > const validatedRange = this.validateRange(rawOperation.range);
1301 >
1302 > // Normalize edit when replacement text ends with lone CR
1303 > // and the range ends right before a CRLF in the buffer.
1304 > // We strip the trailing CR from the replacement text.
1305 > let opText = rawOperation.text;
1306 > if (opText) {
1307 const endsWithLoneCR = (
1308 opText.length > 0 && opText.charCodeAt(opText.length - 1) === CharCode.CarriageReturn
1315 }
1316 }
1317 > textModel.ts
1318 > return new model.ValidAnnotatedEditOperation(
1319 > rawOperation.identifier || null,
1320 > validatedRange,
1321 > opText,
1322 > rawOperation.forceMoveMarkers || false,
1323 > rawOperation.isAutoWhitespaceEdit || false,
1324 > rawOperation._isTracked || false
1325 > );
1326 > }
1327
1328 private _validateEditOperations(rawOperations: readonly model.IIdentifiedSingleEditOperation[]): model.ValidAnnotatedEditOperation[] {
1329 > const result: model.ValidAnnotatedEditOperation[] = []; textModel.ts
1330 > for (let i = 0, len = rawOperations.length; i < len; i++) {
1331 > result[i] = this._validateEditOperation(rawOperations[i]);
1332 > }
1333 > return result;
1334 > }
1335
1336 public edit(edit: TextEdit, options?: { reason?: TextModelEditSource }): void {
1489 public applyEdits(operations: readonly model.IIdentifiedSingleEditOperation[], computeUndoEdits: true, reason: TextModelEditSource): model.IValidEditOperation[];
1490 public applyEdits(rawOperations: readonly model.IIdentifiedSingleEditOperation[], computeUndoEdits?: boolean, reason?: TextModelEditSource): void | model.IValidEditOperation[] {
1491 > try { textModel.ts
1492 > this._onDidChangeDecorations.beginDeferredEmit();
1493 > this._eventEmitter.beginDeferredEmit();
1494 > const operations = this._validateEditOperations(rawOperations);
1495 >
1496 > return this._doApplyEdits(operations, computeUndoEdits ?? false, reason ?? EditSources.applyEdits());
1497 > } finally {
1498 > this._eventEmitter.endDeferredEmit();
1499 > this._onDidChangeDecorations.endDeferredEmit();
1500 > }
1501 > }
1502
1503 private _doApplyEdits(rawOperations: model.ValidAnnotatedEditOperation[], computeUndoEdits: boolean, reason: TextModelEditSource, resultingSelection: Selection[] | null = null): void | model.IValidEditOperation[] {
1504 > textModel.ts
1505 > const oldLineCount = this._buffer.getLineCount();
1506 > const result = this._buffer.applyEdits(rawOperations, this._options.trimAutoWhitespace, computeUndoEdits);
1507 > const newLineCount = this._buffer.getLineCount();
1508 >
1509 > const contentChanges = result.changes;
1510 > this._trimAutoWhitespaceLines = result.trimAutoWhitespaceLineNumbers;
1511 >
1512 > if (contentChanges.length !== 0) {
1513 // We do a first pass to update decorations
1514 // because we want to read decorations in the second pass
1599 }
1600
1601 > return (result.reverseEdits === null ? undefined : result.reverseEdits); textModel.ts
1602 > }
1603
1604 public undo(): void | Promise<void> {
2715
2716 public beginDeferredEmit(): void {
2717 > this._deferredCnt++; textModel.ts
2718 > }
2719
2720 public endDeferredEmit(resultingSelection: Selection[] | null = null): void {
2721 > this._deferredCnt--; textModel.ts
2722 > if (this._deferredCnt === 0) {
2723 > if (this._deferredEvent !== null) {
2724 this._deferredEvent.rawContentChangedEvent.resultingSelection = resultingSelection;
2725 const e = this._deferredEvent;
2727 this._emitter.fire(e);
2728 }
2729 > } textModel.ts
2730 > }
2731
2732 public fire(e: InternalModelContentChangeEvent): void {
src/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer.ts 43 introduced LOC · 7 ranges

Open complete file

242
243 public applyEdits(rawOperations: ValidAnnotatedEditOperation[], recordTrimAutoWhitespace: boolean, computeUndoEdits: boolean): ApplyEditsResult {
244 > let mightContainRTL = this._mightContainRTL; pieceTreeTextBuffer.ts
245 > let mightContainUnusualLineTerminators = this._mightContainUnusualLineTerminators;
246 > let mightContainNonBasicASCII = this._mightContainNonBasicASCII;
247 > let canReduceOperations = true;
248 >
249 > let operations: IValidatedEditOperation[] = [];
250 > for (let i = 0; i < rawOperations.length; i++) {
251 > const op = rawOperations[i];
252 > if (canReduceOperations && op._isTracked) {
253 canReduceOperations = false;
254 }
255 > const validatedRange = op.range; pieceTreeTextBuffer.ts
256 > if (op.text) {
257 let textMightContainNonBasicASCII = true;
258 if (!mightContainNonBasicASCII) {
269 }
270 }
272 > let validText = '';
273 > let eolCount = 0;
274 > let firstLineLength = 0;
275 > let lastLineLength = 0;
276 > if (op.text) {
277 let strEOL: StringEOL;
278 [eolCount, firstLineLength, lastLineLength, strEOL] = countEOL(op.text);
286 }
287 }
289 > operations[i] = {
290 > sortIndex: i,
291 > identifier: op.identifier || null,
292 > range: validatedRange,
293 > rangeOffset: this.getOffsetAt(validatedRange.startLineNumber, validatedRange.startColumn),
294 > rangeLength: this.getValueLengthInRange(validatedRange),
295 > text: validText,
296 > eolCount: eolCount,
297 > firstLineLength: firstLineLength,
298 > lastLineLength: lastLineLength,
299 > forceMoveMarkers: Boolean(op.forceMoveMarkers),
300 > isAutoWhitespaceEdit: op.isAutoWhitespaceEdit || false
301 > };
302 > }
303 >
304 > // Sort operations ascending
305 > operations.sort(PieceTreeTextBuffer._sortOpsAscending);
306 >
307 > let hasTouchingRanges = false;
308 > for (let i = 0, count = operations.length - 1; i < count; i++) {
309 const rangeEnd = operations[i].range.getEndPosition();
310 const nextRangeStart = operations[i + 1].range.getStartPosition();
324
325 // Delta encode operations
326 > const reverseRanges = (computeUndoEdits || recordTrimAutoWhitespace ? PieceTreeTextBuffer._getInverseEditRanges(operations) : []); pieceTreeTextBuffer.ts
327 > const newTrimAutoWhitespaceCandidates: { lineNumber: number; oldContent: string }[] = [];
328 > if (recordTrimAutoWhitespace) {
329 for (let i = 0; i < operations.length; i++) {
330 const op = operations[i];
382
383 let trimAutoWhitespaceLineNumbers: number[] | null = null;
384 > if (recordTrimAutoWhitespace && newTrimAutoWhitespaceCandidates.length > 0) { pieceTreeTextBuffer.ts
385 // sort line numbers auto whitespace removal candidates for next edit descending
386 newTrimAutoWhitespaceCandidates.sort((a, b) => b.lineNumber - a.lineNumber);
src/vs/editor/common/model.ts 7 introduced LOC · 1 range

Open complete file

1508 export class ValidAnnotatedEditOperation implements IIdentifiedSingleEditOperation {
1509 constructor(
1510 > public readonly identifier: ISingleEditOperationIdentifier | null, model.ts
1511 > public readonly range: Range,
1512 > public readonly text: string | null,
1513 > public readonly forceMoveMarkers: boolean,
1514 > public readonly isAutoWhitespaceEdit: boolean,
1515 > public readonly _isTracked: boolean,
1516 > ) { }
1517 }
1518