@theia/editor 1.53.0-next.4 → 1.53.0-next.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/editor-manager.d.ts.map +1 -1
  3. package/lib/browser/editor-manager.js +11 -4
  4. package/lib/browser/editor-manager.js.map +1 -1
  5. package/lib/browser/editor-variable-contribution.d.ts.map +1 -1
  6. package/lib/browser/editor-variable-contribution.js +9 -1
  7. package/lib/browser/editor-variable-contribution.js.map +1 -1
  8. package/lib/browser/editor.d.ts +5 -2
  9. package/lib/browser/editor.d.ts.map +1 -1
  10. package/lib/browser/editor.js.map +1 -1
  11. package/lib/browser/navigation/navigation-location-service.js +3 -3
  12. package/package.json +5 -5
  13. package/src/browser/decorations/editor-decoration-style.ts +41 -41
  14. package/src/browser/decorations/editor-decoration.ts +127 -127
  15. package/src/browser/decorations/editor-decorator.ts +36 -36
  16. package/src/browser/decorations/index.ts +19 -19
  17. package/src/browser/diff-navigator.ts +27 -27
  18. package/src/browser/editor-command.ts +393 -393
  19. package/src/browser/editor-contribution.ts +185 -185
  20. package/src/browser/editor-frontend-module.ts +90 -90
  21. package/src/browser/editor-generated-preference-schema.ts +2956 -2956
  22. package/src/browser/editor-keybinding.ts +55 -55
  23. package/src/browser/editor-language-quick-pick-service.ts +68 -68
  24. package/src/browser/editor-linenumber-contribution.ts +88 -88
  25. package/src/browser/editor-manager.ts +462 -452
  26. package/src/browser/editor-menu.ts +224 -224
  27. package/src/browser/editor-navigation-contribution.ts +343 -343
  28. package/src/browser/editor-preferences.ts +226 -226
  29. package/src/browser/editor-variable-contribution.ts +62 -54
  30. package/src/browser/editor-widget-factory.ts +82 -82
  31. package/src/browser/editor-widget.ts +139 -139
  32. package/src/browser/editor.ts +366 -362
  33. package/src/browser/index.ts +26 -26
  34. package/src/browser/language-status/editor-language-status-service.ts +271 -271
  35. package/src/browser/language-status/editor-language-status.css +101 -101
  36. package/src/browser/navigation/navigation-location-service.spec.ts +245 -245
  37. package/src/browser/navigation/navigation-location-service.ts +284 -284
  38. package/src/browser/navigation/navigation-location-similarity.spec.ts +46 -46
  39. package/src/browser/navigation/navigation-location-similarity.ts +58 -58
  40. package/src/browser/navigation/navigation-location-updater.spec.ts +197 -197
  41. package/src/browser/navigation/navigation-location-updater.ts +220 -220
  42. package/src/browser/navigation/navigation-location.ts +418 -418
  43. package/src/browser/navigation/test/mock-navigation-location-updater.ts +41 -41
  44. package/src/browser/quick-editor-service.ts +94 -94
  45. package/src/browser/style/index.css +19 -19
  46. package/src/browser/undo-redo-service.ts +120 -120
  47. package/src/common/language-selector.ts +104 -104
  48. package/src/package.spec.ts +28 -28
@@ -1,41 +1,41 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { Range } from '../navigation-location';
18
- import { NavigationLocationUpdater } from '../navigation-location-updater';
19
-
20
- /**
21
- * Navigation location updater with increased method visibility for testing.
22
- */
23
- export class MockNavigationLocationUpdater extends NavigationLocationUpdater {
24
-
25
- override contained(subRange: Range, range: Range): boolean {
26
- return super.contained(subRange, range);
27
- }
28
-
29
- }
30
-
31
- /**
32
- * NOOP navigation location updater for testing. Use this, if you want to avoid any
33
- * location updates during the tests.
34
- */
35
- export class NoopNavigationLocationUpdater extends NavigationLocationUpdater {
36
-
37
- override affects(): false {
38
- return false;
39
- }
40
-
41
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { Range } from '../navigation-location';
18
+ import { NavigationLocationUpdater } from '../navigation-location-updater';
19
+
20
+ /**
21
+ * Navigation location updater with increased method visibility for testing.
22
+ */
23
+ export class MockNavigationLocationUpdater extends NavigationLocationUpdater {
24
+
25
+ override contained(subRange: Range, range: Range): boolean {
26
+ return super.contained(subRange, range);
27
+ }
28
+
29
+ }
30
+
31
+ /**
32
+ * NOOP navigation location updater for testing. Use this, if you want to avoid any
33
+ * location updates during the tests.
34
+ */
35
+ export class NoopNavigationLocationUpdater extends NavigationLocationUpdater {
36
+
37
+ override affects(): false {
38
+ return false;
39
+ }
40
+
41
+ }
@@ -1,94 +1,94 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2021 SAP SE or an SAP affiliate company and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { injectable, inject } from '@theia/core/shared/inversify';
18
- import { CancellationToken, nls, QuickPickItemOrSeparator } from '@theia/core/lib/common';
19
- import { LabelProvider } from '@theia/core/lib/browser/label-provider';
20
- import { QuickAccessProvider, QuickAccessRegistry, QuickAccessContribution } from '@theia/core/lib/browser/quick-input/quick-access';
21
- import { filterItems, QuickPickItem, QuickPickSeparator } from '@theia/core/lib/browser/quick-input/quick-input-service';
22
- import { ApplicationShell, NavigatableWidget, TabBar, Widget } from '@theia/core/lib/browser';
23
-
24
- @injectable()
25
- export class QuickEditorService implements QuickAccessContribution, QuickAccessProvider {
26
- static PREFIX = 'edt ';
27
-
28
- @inject(LabelProvider) protected readonly labelProvider: LabelProvider;
29
- @inject(QuickAccessRegistry) protected readonly quickAccessRegistry: QuickAccessRegistry;
30
- @inject(ApplicationShell) protected readonly shell: ApplicationShell;
31
-
32
- protected groupLocalizations: string[] = [];
33
-
34
- registerQuickAccessProvider(): void {
35
- this.quickAccessRegistry.registerQuickAccessProvider({
36
- getInstance: () => this,
37
- prefix: QuickEditorService.PREFIX,
38
- placeholder: '',
39
- helpEntries: [{ description: 'Show All Opened Editors', needsEditor: false }]
40
- });
41
- }
42
-
43
- getPicks(filter: string, token: CancellationToken): (QuickPickItem | QuickPickSeparator)[] {
44
- const editorItems: QuickPickItemOrSeparator[] = [];
45
- const hasUri = (widget: Widget): widget is NavigatableWidget => Boolean(NavigatableWidget.getUri(widget));
46
- const handleWidgets = (widgets: NavigatableWidget[], label: string) => {
47
- if (widgets.length) {
48
- editorItems.push({ type: 'separator', label });
49
- }
50
- editorItems.push(...widgets.map(widget => this.toItem(widget)));
51
- };
52
- const handleSplittableArea = (tabbars: TabBar<Widget>[], labelPrefix: string) => {
53
- tabbars.forEach((tabbar, index) => {
54
- const editorsOnTabbar = tabbar.titles.reduce<NavigatableWidget[]>((widgets, title) => {
55
- if (hasUri(title.owner)) {
56
- widgets.push(title.owner);
57
- }
58
- return widgets;
59
- }, []);
60
- const label = tabbars.length > 1 ? `${labelPrefix} ${this.getGroupLocalization(index)}` : labelPrefix;
61
- handleWidgets(editorsOnTabbar, label);
62
- });
63
- };
64
-
65
- handleSplittableArea(this.shell.mainAreaTabBars, ApplicationShell.areaLabels.main);
66
- handleSplittableArea(this.shell.bottomAreaTabBars, ApplicationShell.areaLabels.bottom);
67
-
68
- for (const area of ['left', 'right'] as ApplicationShell.Area[]) {
69
- const editorsInArea = this.shell.getWidgets(area).filter(hasUri);
70
- handleWidgets(editorsInArea, ApplicationShell.areaLabels[area]);
71
- }
72
-
73
- return filterItems(editorItems.slice(), filter);
74
- }
75
-
76
- protected getGroupLocalization(index: number): string {
77
- return this.groupLocalizations[index] || nls.localizeByDefault('Group {0}', index + 1);
78
- }
79
-
80
- protected toItem(widget: NavigatableWidget): QuickPickItem {
81
- const uri = NavigatableWidget.getUri(widget)!;
82
- const icon = this.labelProvider.getIcon(uri);
83
- const iconClasses = icon === '' ? undefined : [icon + ' file-icon'];
84
-
85
- return {
86
- label: this.labelProvider.getName(uri),
87
- description: this.labelProvider.getDetails(uri),
88
- iconClasses,
89
- ariaLabel: uri.path.fsPath(),
90
- alwaysShow: true,
91
- execute: () => this.shell.activateWidget(widget.id),
92
- };
93
- }
94
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2021 SAP SE or an SAP affiliate company and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { injectable, inject } from '@theia/core/shared/inversify';
18
+ import { CancellationToken, nls, QuickPickItemOrSeparator } from '@theia/core/lib/common';
19
+ import { LabelProvider } from '@theia/core/lib/browser/label-provider';
20
+ import { QuickAccessProvider, QuickAccessRegistry, QuickAccessContribution } from '@theia/core/lib/browser/quick-input/quick-access';
21
+ import { filterItems, QuickPickItem, QuickPickSeparator } from '@theia/core/lib/browser/quick-input/quick-input-service';
22
+ import { ApplicationShell, NavigatableWidget, TabBar, Widget } from '@theia/core/lib/browser';
23
+
24
+ @injectable()
25
+ export class QuickEditorService implements QuickAccessContribution, QuickAccessProvider {
26
+ static PREFIX = 'edt ';
27
+
28
+ @inject(LabelProvider) protected readonly labelProvider: LabelProvider;
29
+ @inject(QuickAccessRegistry) protected readonly quickAccessRegistry: QuickAccessRegistry;
30
+ @inject(ApplicationShell) protected readonly shell: ApplicationShell;
31
+
32
+ protected groupLocalizations: string[] = [];
33
+
34
+ registerQuickAccessProvider(): void {
35
+ this.quickAccessRegistry.registerQuickAccessProvider({
36
+ getInstance: () => this,
37
+ prefix: QuickEditorService.PREFIX,
38
+ placeholder: '',
39
+ helpEntries: [{ description: 'Show All Opened Editors', needsEditor: false }]
40
+ });
41
+ }
42
+
43
+ getPicks(filter: string, token: CancellationToken): (QuickPickItem | QuickPickSeparator)[] {
44
+ const editorItems: QuickPickItemOrSeparator[] = [];
45
+ const hasUri = (widget: Widget): widget is NavigatableWidget => Boolean(NavigatableWidget.getUri(widget));
46
+ const handleWidgets = (widgets: NavigatableWidget[], label: string) => {
47
+ if (widgets.length) {
48
+ editorItems.push({ type: 'separator', label });
49
+ }
50
+ editorItems.push(...widgets.map(widget => this.toItem(widget)));
51
+ };
52
+ const handleSplittableArea = (tabbars: TabBar<Widget>[], labelPrefix: string) => {
53
+ tabbars.forEach((tabbar, index) => {
54
+ const editorsOnTabbar = tabbar.titles.reduce<NavigatableWidget[]>((widgets, title) => {
55
+ if (hasUri(title.owner)) {
56
+ widgets.push(title.owner);
57
+ }
58
+ return widgets;
59
+ }, []);
60
+ const label = tabbars.length > 1 ? `${labelPrefix} ${this.getGroupLocalization(index)}` : labelPrefix;
61
+ handleWidgets(editorsOnTabbar, label);
62
+ });
63
+ };
64
+
65
+ handleSplittableArea(this.shell.mainAreaTabBars, ApplicationShell.areaLabels.main);
66
+ handleSplittableArea(this.shell.bottomAreaTabBars, ApplicationShell.areaLabels.bottom);
67
+
68
+ for (const area of ['left', 'right'] as ApplicationShell.Area[]) {
69
+ const editorsInArea = this.shell.getWidgets(area).filter(hasUri);
70
+ handleWidgets(editorsInArea, ApplicationShell.areaLabels[area]);
71
+ }
72
+
73
+ return filterItems(editorItems.slice(), filter);
74
+ }
75
+
76
+ protected getGroupLocalization(index: number): string {
77
+ return this.groupLocalizations[index] || nls.localizeByDefault('Group {0}', index + 1);
78
+ }
79
+
80
+ protected toItem(widget: NavigatableWidget): QuickPickItem {
81
+ const uri = NavigatableWidget.getUri(widget)!;
82
+ const icon = this.labelProvider.getIcon(uri);
83
+ const iconClasses = icon === '' ? undefined : [icon + ' file-icon'];
84
+
85
+ return {
86
+ label: this.labelProvider.getName(uri),
87
+ description: this.labelProvider.getDetails(uri),
88
+ iconClasses,
89
+ ariaLabel: uri.path.fsPath(),
90
+ alwaysShow: true,
91
+ execute: () => this.shell.activateWidget(widget.id),
92
+ };
93
+ }
94
+ }
@@ -1,19 +1,19 @@
1
- /********************************************************************************
2
- * Copyright (C) 2020 TypeFox and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the Eclipse Public License v. 2.0 which is available at
6
- * http://www.eclipse.org/legal/epl-2.0.
7
- *
8
- * This Source Code may also be made available under the following Secondary
9
- * Licenses when the conditions for such availability set forth in the Eclipse
10
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- * with the GNU Classpath Exception which is available at
12
- * https://www.gnu.org/software/classpath/license.html.
13
- *
14
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
-
17
- .theia-editor {
18
- height: 100%;
19
- }
1
+ /********************************************************************************
2
+ * Copyright (C) 2020 TypeFox and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+
17
+ .theia-editor {
18
+ height: 100%;
19
+ }
@@ -1,120 +1,120 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2021 SAP SE or an SAP affiliate company and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
- /*---------------------------------------------------------------------------------------------
17
- * Copyright (c) Microsoft Corporation. All rights reserved.
18
- * Licensed under the MIT License. See License.txt in the project root for license information.
19
- *--------------------------------------------------------------------------------------------*/
20
- // copied and modified from https://github.com/microsoft/vscode/blob/53eac52308c4611000a171cc7bf1214293473c78/src/vs/platform/undoRedo/common/undoRedoService.ts#
21
-
22
- import { injectable } from '@theia/core/shared/inversify';
23
- import URI from '@theia/core/lib/common/uri';
24
-
25
- @injectable()
26
- export class UndoRedoService {
27
- private readonly editStacks = new Map<string, ResourceEditStack>();
28
-
29
- pushElement(resource: URI, undo: () => Promise<void>, redo: () => Promise<void>): void {
30
- let editStack: ResourceEditStack;
31
- if (this.editStacks.has(resource.toString())) {
32
- editStack = this.editStacks.get(resource.toString())!;
33
- } else {
34
- editStack = new ResourceEditStack();
35
- this.editStacks.set(resource.toString(), editStack);
36
- }
37
-
38
- editStack.pushElement({ undo, redo });
39
- }
40
-
41
- removeElements(resource: URI): void {
42
- if (this.editStacks.has(resource.toString())) {
43
- this.editStacks.delete(resource.toString());
44
- }
45
- }
46
-
47
- undo(resource: URI): void {
48
- if (!this.editStacks.has(resource.toString())) {
49
- return;
50
- }
51
-
52
- const editStack = this.editStacks.get(resource.toString())!;
53
- const element = editStack.getClosestPastElement();
54
- if (!element) {
55
- return;
56
- }
57
-
58
- editStack.moveBackward(element);
59
- element.undo();
60
- }
61
-
62
- redo(resource: URI): void {
63
- if (!this.editStacks.has(resource.toString())) {
64
- return;
65
- }
66
-
67
- const editStack = this.editStacks.get(resource.toString())!;
68
- const element = editStack.getClosestFutureElement();
69
- if (!element) {
70
- return;
71
- }
72
-
73
- editStack.moveForward(element);
74
- element.redo();
75
- }
76
- }
77
-
78
- interface StackElement {
79
- undo(): Promise<void> | void;
80
- redo(): Promise<void> | void;
81
- }
82
-
83
- export class ResourceEditStack {
84
- private past: StackElement[];
85
- private future: StackElement[];
86
-
87
- constructor() {
88
- this.past = [];
89
- this.future = [];
90
- }
91
-
92
- pushElement(element: StackElement): void {
93
- this.future = [];
94
- this.past.push(element);
95
- }
96
-
97
- getClosestPastElement(): StackElement | undefined {
98
- if (this.past.length === 0) {
99
- return undefined;
100
- }
101
- return this.past[this.past.length - 1];
102
- }
103
-
104
- getClosestFutureElement(): StackElement | undefined {
105
- if (this.future.length === 0) {
106
- return undefined;
107
- }
108
- return this.future[this.future.length - 1];
109
- }
110
-
111
- moveBackward(element: StackElement): void {
112
- this.past.pop();
113
- this.future.push(element);
114
- }
115
-
116
- moveForward(element: StackElement): void {
117
- this.future.pop();
118
- this.past.push(element);
119
- }
120
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2021 SAP SE or an SAP affiliate company and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+ /*---------------------------------------------------------------------------------------------
17
+ * Copyright (c) Microsoft Corporation. All rights reserved.
18
+ * Licensed under the MIT License. See License.txt in the project root for license information.
19
+ *--------------------------------------------------------------------------------------------*/
20
+ // copied and modified from https://github.com/microsoft/vscode/blob/53eac52308c4611000a171cc7bf1214293473c78/src/vs/platform/undoRedo/common/undoRedoService.ts#
21
+
22
+ import { injectable } from '@theia/core/shared/inversify';
23
+ import URI from '@theia/core/lib/common/uri';
24
+
25
+ @injectable()
26
+ export class UndoRedoService {
27
+ private readonly editStacks = new Map<string, ResourceEditStack>();
28
+
29
+ pushElement(resource: URI, undo: () => Promise<void>, redo: () => Promise<void>): void {
30
+ let editStack: ResourceEditStack;
31
+ if (this.editStacks.has(resource.toString())) {
32
+ editStack = this.editStacks.get(resource.toString())!;
33
+ } else {
34
+ editStack = new ResourceEditStack();
35
+ this.editStacks.set(resource.toString(), editStack);
36
+ }
37
+
38
+ editStack.pushElement({ undo, redo });
39
+ }
40
+
41
+ removeElements(resource: URI): void {
42
+ if (this.editStacks.has(resource.toString())) {
43
+ this.editStacks.delete(resource.toString());
44
+ }
45
+ }
46
+
47
+ undo(resource: URI): void {
48
+ if (!this.editStacks.has(resource.toString())) {
49
+ return;
50
+ }
51
+
52
+ const editStack = this.editStacks.get(resource.toString())!;
53
+ const element = editStack.getClosestPastElement();
54
+ if (!element) {
55
+ return;
56
+ }
57
+
58
+ editStack.moveBackward(element);
59
+ element.undo();
60
+ }
61
+
62
+ redo(resource: URI): void {
63
+ if (!this.editStacks.has(resource.toString())) {
64
+ return;
65
+ }
66
+
67
+ const editStack = this.editStacks.get(resource.toString())!;
68
+ const element = editStack.getClosestFutureElement();
69
+ if (!element) {
70
+ return;
71
+ }
72
+
73
+ editStack.moveForward(element);
74
+ element.redo();
75
+ }
76
+ }
77
+
78
+ interface StackElement {
79
+ undo(): Promise<void> | void;
80
+ redo(): Promise<void> | void;
81
+ }
82
+
83
+ export class ResourceEditStack {
84
+ private past: StackElement[];
85
+ private future: StackElement[];
86
+
87
+ constructor() {
88
+ this.past = [];
89
+ this.future = [];
90
+ }
91
+
92
+ pushElement(element: StackElement): void {
93
+ this.future = [];
94
+ this.past.push(element);
95
+ }
96
+
97
+ getClosestPastElement(): StackElement | undefined {
98
+ if (this.past.length === 0) {
99
+ return undefined;
100
+ }
101
+ return this.past[this.past.length - 1];
102
+ }
103
+
104
+ getClosestFutureElement(): StackElement | undefined {
105
+ if (this.future.length === 0) {
106
+ return undefined;
107
+ }
108
+ return this.future[this.future.length - 1];
109
+ }
110
+
111
+ moveBackward(element: StackElement): void {
112
+ this.past.pop();
113
+ this.future.push(element);
114
+ }
115
+
116
+ moveForward(element: StackElement): void {
117
+ this.future.pop();
118
+ this.past.push(element);
119
+ }
120
+ }