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
) { }
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;