undoRedo.ts ×4

Frontier kind: Code frontier

unlabeled · c_962a280cb49d

866 tests · 5924 LOC · 31 files · introduces 0 tests · 177 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
4 ranges177 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
795 ranges5924 lines · 31 files · Browse complete extent
All tests (intent)
866 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: 177 introduced LOC across 4 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/undoRedo/common/undoRedo.ts 177 introduced LOC · 4 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- undoRedo.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 { IDisposable } from '../../../base/common/lifecycle.js';
7 > import { URI } from '../../../base/common/uri.js';
8 > import { createDecorator } from '../../instantiation/common/instantiation.js';
9 >
10 > export const IUndoRedoService = createDecorator<IUndoRedoService>('undoRedoService');
11 >
12 > export const enum UndoRedoElementType {
13 > Resource,
14 > Workspace
15 > }
16 >
17 > export interface IResourceUndoRedoElement {
18 > readonly type: UndoRedoElementType.Resource;
19 > /**
20 > * The resource impacted by this element.
21 > */
22 > readonly resource: URI;
23 > /**
24 > * A user presentable label. May be localized.
25 > */
26 > readonly label: string;
27 > /**
28 > * A code describing the operation. Will not be localized.
29 > */
30 > readonly code: string;
31 > /**
32 > * Show a message to the user confirming when trying to undo this element
33 > */
34 > readonly confirmBeforeUndo?: boolean;
35 > undo(): Promise<void> | void;
36 > redo(): Promise<void> | void;
37 > }
38 >
39 > export interface IWorkspaceUndoRedoElement {
40 > readonly type: UndoRedoElementType.Workspace;
41 > /**
42 > * The resources impacted by this element.
43 > */
44 > readonly resources: readonly URI[];
45 > /**
46 > * A user presentable label. May be localized.
47 > */
48 > readonly label: string;
49 > /**
50 > * A code describing the operation. Will not be localized.
51 > */
52 > readonly code: string;
53 > /**
54 > * Show a message to the user confirming when trying to undo this element
55 > */
56 > readonly confirmBeforeUndo?: boolean;
57 > undo(): Promise<void> | void;
58 > redo(): Promise<void> | void;
59 >
60 > /**
61 > * If implemented, indicates that this undo/redo element can be split into multiple per resource elements.
62 > */
63 > split?(): IResourceUndoRedoElement[];
64 >
65 > /**
66 > * If implemented, will be invoked before calling `undo()` or `redo()`.
67 > * This is a good place to prepare everything such that the calls to `undo()` or `redo()` are synchronous.
68 > * If a disposable is returned, it will be invoked to clean things up.
69 > */
70 > prepareUndoRedo?(): Promise<IDisposable> | IDisposable | void;
71 > }
72 >
73 > export type IUndoRedoElement = IResourceUndoRedoElement | IWorkspaceUndoRedoElement;
74 >
75 > export interface IPastFutureElements {
76 > past: IUndoRedoElement[];
77 > future: IUndoRedoElement[];
78 > }
79 >
80 > export interface UriComparisonKeyComputer {
81 > getComparisonKey(uri: URI): string;
82 > }
83 >
84 > export class ResourceEditStackSnapshot {
85 > constructor(
86 public readonly resource: URI,
87 public readonly elements: number[]
88 ) { }
89 > } undoRedo.ts
90 >
91 > export class UndoRedoGroup {
92 > private static _ID = 0;
93 >
94 > public readonly id: number;
95 > private order: number;
96 >
97 > constructor() {
98 > this.id = UndoRedoGroup._ID++;
99 > this.order = 1;
100 > }
101 >
102 > public nextOrder(): number {
103 if (this.id === 0) {
104 return 0;
106 return this.order++;
107 }
108 > undoRedo.ts
109 > public static None = new UndoRedoGroup();
110 > }
111 >
112 > export class UndoRedoSource {
113 > private static _ID = 0;
114 >
115 > public readonly id: number;
116 > private order: number;
117 >
118 > constructor() {
119 > this.id = UndoRedoSource._ID++;
120 > this.order = 1;
121 > }
122 >
123 > public nextOrder(): number {
124 if (this.id === 0) {
125 return 0;
127 return this.order++;
128 }
129 > undoRedo.ts
130 > public static None = new UndoRedoSource();
131 > }
132 >
133 > export interface IUndoRedoService {
134 > readonly _serviceBrand: undefined;
135 >
136 > /**
137 > * Register an URI -> string hasher.
138 > * This is useful for making multiple URIs share the same undo-redo stack.
139 > */
140 > registerUriComparisonKeyComputer(scheme: string, uriComparisonKeyComputer: UriComparisonKeyComputer): IDisposable;
141 >
142 > /**
143 > * Get the hash used internally for a certain URI.
144 > * This uses any registered `UriComparisonKeyComputer`.
145 > */
146 > getUriComparisonKey(resource: URI): string;
147 >
148 > /**
149 > * Add a new element to the `undo` stack.
150 > * This will destroy the `redo` stack.
151 > */
152 > pushElement(element: IUndoRedoElement, group?: UndoRedoGroup, source?: UndoRedoSource): void;
153 >
154 > /**
155 > * Get the last pushed element for a resource.
156 > * If the last pushed element has been undone, returns null.
157 > */
158 > getLastElement(resource: URI): IUndoRedoElement | null;
159 >
160 > /**
161 > * Get all the elements associated with a resource.
162 > * This includes the past and the future.
163 > */
164 > getElements(resource: URI): IPastFutureElements;
165 >
166 > /**
167 > * Validate or invalidate stack elements associated with a resource.
168 > */
169 > setElementsValidFlag(resource: URI, isValid: boolean, filter: (element: IUndoRedoElement) => boolean): void;
170 >
171 > /**
172 > * Remove elements that target `resource`.
173 > */
174 > removeElements(resource: URI): void;
175 >
176 > /**
177 > * Create a snapshot of the current elements on the undo-redo stack for a resource.
178 > */
179 > createSnapshot(resource: URI): ResourceEditStackSnapshot;
180 > /**
181 > * Attempt (as best as possible) to restore a certain snapshot previously created with `createSnapshot` for a resource.
182 > */
183 > restoreSnapshot(snapshot: ResourceEditStackSnapshot): void;
184 >
185 > canUndo(resource: URI | UndoRedoSource): boolean;
186 > undo(resource: URI | UndoRedoSource): Promise<void> | void;
187 >
188 > canRedo(resource: URI | UndoRedoSource): boolean;
189 > redo(resource: URI | UndoRedoSource): Promise<void> | void;
190 > }