editStack.ts ×15

Frontier kind: Code frontier

unlabeled · c_bf7a364955ea

15 tests · 41563 LOC · 238 files · introduces 0 tests · 79 LOC · 5 files

Introduces — evidence that enters the hierarchy at this concept

Code
23 ranges79 lines · 5 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
5207 ranges41563 lines · 238 files · Browse complete extent
All tests (intent)
15 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.

5 files ranked by introduced lines: 79 introduced LOC across 23 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/model/editStack.ts 51 introduced LOC · 15 ranges

Open complete file

49
50 public append(model: ITextModel, textChanges: TextChange[], afterEOL: EndOfLineSequence, afterVersionId: number, afterCursorState: Selection[] | null): void {
51 > if (textChanges.length > 0) { editStack.ts
52 > this.changes = compressConsecutiveTextChanges(this.changes, textChanges);
53 > }
54 > this.afterEOL = afterEOL;
55 > this.afterVersionId = afterVersionId;
56 > this.afterCursorState = afterCursorState;
57 > }
58
59 private static _writeSelectionsSize(selections: Selection[] | null): number {
157
158 public get resource(): URI {
159 > if (URI.isUri(this.model)) { editStack.ts
160 return this.model;
161 }
162 > return this.model.uri; editStack.ts
163 > }
164
165 constructor(
166 > public readonly label: string, editStack.ts
167 > public readonly code: string,
168 > model: ITextModel,
169 > beforeCursorState: Selection[] | null
170 > ) {
171 > this.model = model;
172 > this._data = SingleModelEditStackData.create(model, beforeCursorState);
173 > }
174
175 public toString(): string {
192
193 public append(model: ITextModel, textChanges: TextChange[], afterEOL: EndOfLineSequence, afterVersionId: number, afterCursorState: Selection[] | null): void {
194 > if (this._data instanceof SingleModelEditStackData) { editStack.ts
195 > this._data.append(model, textChanges, afterEOL, afterVersionId, afterCursorState);
196 > }
197 > }
198
199 public close(): void {
366 export type EditStackElement = SingleModelEditStackElement | MultiModelEditStackElement;
367
368 > function getModelEOL(model: ITextModel): EndOfLineSequence { editStack.ts
369 > const eol = model.getEOL();
370 > if (eol === '\n') {
371 > return EndOfLineSequence.LF;
372 > } else {
373 return EndOfLineSequence.CRLF;
374 }
375 > } editStack.ts
376
377 export function isEditStackElement(element: IResourceUndoRedoElement | IWorkspaceUndoRedoElement | null): element is EditStackElement {
378 > if (!element) { editStack.ts
379 > return false;
380 > }
381 return ((element instanceof SingleModelEditStackElement) || (element instanceof MultiModelEditStackElement));
382 > } editStack.ts
383
384 export class EditStack {
411
412 private _getOrCreateEditStackElement(beforeCursorState: Selection[] | null, group: UndoRedoGroup | undefined): EditStackElement {
413 > const lastElement = this._undoRedoService.getLastElement(this._model.uri); editStack.ts
414 > if (isEditStackElement(lastElement) && lastElement.canAppend(this._model)) {
415 return lastElement;
416 }
417 > const newElement = new SingleModelEditStackElement(nls.localize('edit', "Typing"), 'undoredo.textBufferEdit', this._model, beforeCursorState); editStack.ts
418 > this._undoRedoService.pushElement(newElement, group);
419 > return newElement;
420 > }
421
422 public pushEOL(eol: EndOfLineSequence): void {
427
428 public pushEditOperation(beforeCursorState: Selection[] | null, editOperations: ISingleEditOperation[], cursorStateComputer: ICursorStateComputer | null, group?: UndoRedoGroup, reason: TextModelEditSource = EditSources.unknown({ name: 'pushEditOperation' })): Selection[] | null {
429 > const editStackElement = this._getOrCreateEditStackElement(beforeCursorState, group); editStack.ts
430 > const inverseEditOperations = this._model.applyEdits(editOperations, true, reason);
431 > const afterCursorState = EditStack._computeCursorState(cursorStateComputer, inverseEditOperations);
432 > const textChanges = inverseEditOperations.map((op, index) => ({ index: index, textChange: op.textChange }));
433 > textChanges.sort((a, b) => {
434 if (a.textChange.oldPosition === b.textChange.oldPosition) {
435 return a.index - b.index;
436 }
437 return a.textChange.oldPosition - b.textChange.oldPosition;
438 > }); editStack.ts
439 > editStackElement.append(this._model, textChanges.map(op => op.textChange), getModelEOL(this._model), this._model.getAlternativeVersionId(), afterCursorState);
440 > return afterCursorState;
441 > }
442
443 private static _computeCursorState(cursorStateComputer: ICursorStateComputer | null, inverseEditOperations: IValidEditOperation[]): Selection[] | null {
444 > try { editStack.ts
445 > return cursorStateComputer ? cursorStateComputer(inverseEditOperations) : null;
446 > } catch (e) {
447 onUnexpectedError(e);
448 return null;
449 }
450 > } editStack.ts
451 }
src/vs/editor/common/model/textModel.ts 20 introduced LOC · 5 ranges

Open complete file

759
760 public getAlternativeVersionId(): number {
761 > this._assertNotDisposed(); textModel.ts
762 > return this._alternativeVersionId;
763 > }
764
765 public getInitialUndoRedoSnapshot(): ResourceEditStackSnapshot | null {
1295 private _validateEditOperation(rawOperation: model.IIdentifiedSingleEditOperation): model.ValidAnnotatedEditOperation {
1296 if (rawOperation instanceof model.ValidAnnotatedEditOperation) {
1297 > return rawOperation; textModel.ts
1298 > }
1299
1300 const validatedRange = this.validateRange(rawOperation.range);
1339
1340 public pushEditOperations(beforeCursorState: Selection[] | null, editOperations: model.IIdentifiedSingleEditOperation[], cursorStateComputer: model.ICursorStateComputer | null, group?: UndoRedoGroup, reason?: TextModelEditSource): Selection[] | null {
1341 > try { textModel.ts
1342 > this._onDidChangeDecorations.beginDeferredEmit();
1343 > this._eventEmitter.beginDeferredEmit();
1344 > return this._pushEditOperations(beforeCursorState, this._validateEditOperations(editOperations), cursorStateComputer, group, reason);
1345 > } finally {
1346 > this._eventEmitter.endDeferredEmit();
1347 > this._onDidChangeDecorations.endDeferredEmit();
1348 > }
1349 > }
1350
1351 private _pushEditOperations(beforeCursorState: Selection[] | null, editOperations: model.ValidAnnotatedEditOperation[], cursorStateComputer: model.ICursorStateComputer | null, group?: UndoRedoGroup, reason?: TextModelEditSource): Selection[] | null {
1352 > if (this._options.trimAutoWhitespace && this._trimAutoWhitespaceLines) { textModel.ts
1353 // Go through each saved line number and insert a trim whitespace edit
1354 // if it is safe to do so (no conflicts with other edits).
1433 this._trimAutoWhitespaceLines = null;
1434 }
1435 > if (this._initialUndoRedoSnapshot === null) { textModel.ts
1436 > this._initialUndoRedoSnapshot = this._undoRedoService.createSnapshot(this.uri);
1437 > }
1438 > return this._commandManager.pushEditOperation(beforeCursorState, editOperations, cursorStateComputer, group, reason);
1439 > }
1440
1441 _applyUndo(changes: TextChange[], eol: model.EndOfLineSequence, resultingAlternativeVersionId: number, resultingSelection: Selection[] | null): void {
src/vs/editor/common/textModelEditSource.ts 5 introduced LOC · 1 range

Open complete file

93 export const EditSources = {
94 unknown(data: { name?: string | null }) {
95 > return createEditSource({ textModelEditSource.ts
96 > source: 'unknown',
97 > name: data.name,
98 > } as const);
99 > },
100
101 rename: (oldName: string | undefined, newName: string) => createEditSource({ source: 'rename', $$$oldName: oldName, $$$newName: newName } as const),
src/vs/editor/common/core/textChange.ts 2 introduced LOC · 1 range

Open complete file

99 export function compressConsecutiveTextChanges(prevEdits: TextChange[] | null, currEdits: TextChange[]): TextChange[] {
100 if (prevEdits === null || prevEdits.length === 0) {
101 > return currEdits; textChange.ts
102 > }
103 const compressor = new TextChangeCompressor(prevEdits, currEdits);
104 return compressor.compress();
src/vs/platform/undoRedo/common/undoRedoService.ts 1 introduced LOC · 1 range

Open complete file

641 return editStack.createSnapshot(resource);
642 }
643 > return new ResourceEditStackSnapshot(resource, []); undoRedoService.ts
644 }
645