@theia/editor 1.45.1 → 1.46.0-next.72

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 (112) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/decorations/editor-decoration-style.d.ts +8 -8
  3. package/lib/browser/decorations/editor-decoration-style.js +36 -36
  4. package/lib/browser/decorations/editor-decoration.d.ts +106 -106
  5. package/lib/browser/decorations/editor-decoration.js +37 -37
  6. package/lib/browser/decorations/editor-decorator.d.ts +6 -6
  7. package/lib/browser/decorations/editor-decorator.js +43 -43
  8. package/lib/browser/decorations/index.d.ts +3 -3
  9. package/lib/browser/decorations/index.js +30 -30
  10. package/lib/browser/diff-navigator.d.ts +9 -10
  11. package/lib/browser/diff-navigator.d.ts.map +1 -1
  12. package/lib/browser/diff-navigator.js +19 -19
  13. package/lib/browser/diff-navigator.js.map +1 -1
  14. package/lib/browser/editor-command.d.ts +102 -102
  15. package/lib/browser/editor-command.js +426 -426
  16. package/lib/browser/editor-contribution.d.ts +26 -26
  17. package/lib/browser/editor-contribution.js +198 -198
  18. package/lib/browser/editor-frontend-module.d.ts +5 -5
  19. package/lib/browser/editor-frontend-module.js +74 -74
  20. package/lib/browser/editor-generated-preference-schema.d.ts +282 -249
  21. package/lib/browser/editor-generated-preference-schema.d.ts.map +1 -1
  22. package/lib/browser/editor-generated-preference-schema.js +2451 -2316
  23. package/lib/browser/editor-generated-preference-schema.js.map +1 -1
  24. package/lib/browser/editor-keybinding.d.ts +5 -5
  25. package/lib/browser/editor-keybinding.js +55 -55
  26. package/lib/browser/editor-linenumber-contribution.d.ts +15 -15
  27. package/lib/browser/editor-linenumber-contribution.d.ts.map +1 -1
  28. package/lib/browser/editor-linenumber-contribution.js +95 -96
  29. package/lib/browser/editor-linenumber-contribution.js.map +1 -1
  30. package/lib/browser/editor-manager.d.ts +115 -115
  31. package/lib/browser/editor-manager.js +428 -428
  32. package/lib/browser/editor-menu.d.ts +48 -48
  33. package/lib/browser/editor-menu.js +210 -210
  34. package/lib/browser/editor-navigation-contribution.d.ts +67 -67
  35. package/lib/browser/editor-navigation-contribution.js +343 -343
  36. package/lib/browser/editor-preferences.d.ts +41 -41
  37. package/lib/browser/editor-preferences.js +176 -176
  38. package/lib/browser/editor-variable-contribution.d.ts +8 -8
  39. package/lib/browser/editor-variable-contribution.js +64 -64
  40. package/lib/browser/editor-widget-factory.d.ts +17 -17
  41. package/lib/browser/editor-widget-factory.js +91 -91
  42. package/lib/browser/editor-widget.d.ts +24 -24
  43. package/lib/browser/editor-widget.d.ts.map +1 -1
  44. package/lib/browser/editor-widget.js +122 -114
  45. package/lib/browser/editor-widget.js.map +1 -1
  46. package/lib/browser/editor.d.ts +295 -293
  47. package/lib/browser/editor.d.ts.map +1 -1
  48. package/lib/browser/editor.js +103 -103
  49. package/lib/browser/editor.js.map +1 -1
  50. package/lib/browser/index.d.ts +10 -10
  51. package/lib/browser/index.js +37 -37
  52. package/lib/browser/language-status/editor-language-status-service.d.ts +77 -77
  53. package/lib/browser/language-status/editor-language-status-service.js +251 -251
  54. package/lib/browser/navigation/navigation-location-service.d.ts +103 -103
  55. package/lib/browser/navigation/navigation-location-service.js +281 -281
  56. package/lib/browser/navigation/navigation-location-service.spec.d.ts +1 -1
  57. package/lib/browser/navigation/navigation-location-service.spec.js +184 -184
  58. package/lib/browser/navigation/navigation-location-similarity.d.ts +15 -15
  59. package/lib/browser/navigation/navigation-location-similarity.js +62 -62
  60. package/lib/browser/navigation/navigation-location-similarity.spec.d.ts +1 -1
  61. package/lib/browser/navigation/navigation-location-similarity.spec.js +32 -32
  62. package/lib/browser/navigation/navigation-location-updater.d.ts +35 -35
  63. package/lib/browser/navigation/navigation-location-updater.js +210 -210
  64. package/lib/browser/navigation/navigation-location-updater.spec.d.ts +1 -1
  65. package/lib/browser/navigation/navigation-location-updater.spec.js +177 -177
  66. package/lib/browser/navigation/navigation-location.d.ts +191 -191
  67. package/lib/browser/navigation/navigation-location.js +300 -300
  68. package/lib/browser/navigation/test/mock-navigation-location-updater.d.ts +15 -15
  69. package/lib/browser/navigation/test/mock-navigation-location-updater.js +38 -38
  70. package/lib/browser/quick-editor-service.d.ts +16 -16
  71. package/lib/browser/quick-editor-service.js +109 -109
  72. package/lib/browser/undo-redo-service.d.ts +23 -23
  73. package/lib/browser/undo-redo-service.js +110 -110
  74. package/lib/common/language-selector.d.ts +13 -13
  75. package/lib/common/language-selector.js +90 -90
  76. package/lib/package.spec.js +25 -25
  77. package/package.json +5 -5
  78. package/src/browser/decorations/editor-decoration-style.ts +41 -41
  79. package/src/browser/decorations/editor-decoration.ts +127 -127
  80. package/src/browser/decorations/editor-decorator.ts +36 -36
  81. package/src/browser/decorations/index.ts +19 -19
  82. package/src/browser/diff-navigator.ts +27 -28
  83. package/src/browser/editor-command.ts +414 -414
  84. package/src/browser/editor-contribution.ts +185 -185
  85. package/src/browser/editor-frontend-module.ts +87 -87
  86. package/src/browser/editor-generated-preference-schema.ts +2707 -2539
  87. package/src/browser/editor-keybinding.ts +55 -55
  88. package/src/browser/editor-linenumber-contribution.ts +88 -89
  89. package/src/browser/editor-manager.ts +442 -442
  90. package/src/browser/editor-menu.ts +224 -224
  91. package/src/browser/editor-navigation-contribution.ts +343 -343
  92. package/src/browser/editor-preferences.ts +226 -226
  93. package/src/browser/editor-variable-contribution.ts +54 -54
  94. package/src/browser/editor-widget-factory.ts +82 -82
  95. package/src/browser/editor-widget.ts +137 -130
  96. package/src/browser/editor.ts +360 -358
  97. package/src/browser/index.ts +26 -26
  98. package/src/browser/language-status/editor-language-status-service.ts +271 -271
  99. package/src/browser/language-status/editor-language-status.css +101 -101
  100. package/src/browser/navigation/navigation-location-service.spec.ts +245 -245
  101. package/src/browser/navigation/navigation-location-service.ts +284 -284
  102. package/src/browser/navigation/navigation-location-similarity.spec.ts +46 -46
  103. package/src/browser/navigation/navigation-location-similarity.ts +58 -58
  104. package/src/browser/navigation/navigation-location-updater.spec.ts +197 -197
  105. package/src/browser/navigation/navigation-location-updater.ts +220 -220
  106. package/src/browser/navigation/navigation-location.ts +418 -418
  107. package/src/browser/navigation/test/mock-navigation-location-updater.ts +41 -41
  108. package/src/browser/quick-editor-service.ts +94 -94
  109. package/src/browser/style/index.css +19 -19
  110. package/src/browser/undo-redo-service.ts +120 -120
  111. package/src/common/language-selector.ts +104 -104
  112. package/src/package.spec.ts +28 -28
@@ -1,245 +1,245 @@
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
- import { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
17
-
18
- let disableJSDOM = enableJSDOM();
19
-
20
- import { expect } from 'chai';
21
- import { Container } from '@theia/core/shared/inversify';
22
- import URI from '@theia/core/lib/common/uri';
23
- import { ILogger } from '@theia/core/lib/common/logger';
24
- import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
25
- import { OpenerService } from '@theia/core/lib/browser/opener-service';
26
- import { MockOpenerService } from '@theia/core/lib/browser/test/mock-opener-service';
27
- import { NavigationLocationUpdater } from './navigation-location-updater';
28
- import { NoopNavigationLocationUpdater } from './test/mock-navigation-location-updater';
29
- import { NavigationLocationSimilarity } from './navigation-location-similarity';
30
- import { CursorLocation, Position, NavigationLocation, RecentlyClosedEditor } from './navigation-location';
31
- import { NavigationLocationService } from './navigation-location-service';
32
-
33
- disableJSDOM();
34
-
35
- describe('navigation-location-service', () => {
36
-
37
- let stack: NavigationLocationService;
38
-
39
- before(() => {
40
- disableJSDOM = enableJSDOM();
41
- });
42
-
43
- after(() => {
44
- disableJSDOM();
45
- });
46
-
47
- beforeEach(() => {
48
- stack = init();
49
- });
50
-
51
- it('should not allow navigating back when the stack is empty', () => {
52
- expect(stack.canGoBack()).to.be.false;
53
- });
54
-
55
- it('should not allow navigating back when the stack has a single location', () => {
56
- stack.register(createCursorLocation());
57
- expect(stack.canGoBack()).to.be.false;
58
- });
59
-
60
- it('should allow navigating back when the stack has more than one locations', () => {
61
- stack.register(
62
- createCursorLocation(),
63
- createCursorLocation({ line: 100, character: 100 })
64
- );
65
- expect(stack.canGoBack()).to.be.true;
66
- });
67
-
68
- it('should not allow navigating forward when the stack is empty', () => {
69
- expect(stack.canGoForward()).to.be.false;
70
- });
71
-
72
- it('should not allow navigating forward when the pointer points to the end last element of the stack', () => {
73
- stack.register(
74
- createCursorLocation(),
75
- createCursorLocation({ line: 100, character: 100 })
76
- );
77
- expect(stack.canGoForward()).to.be.false;
78
- });
79
-
80
- it('should not exceed the max stack item', () => {
81
- const max = NavigationLocationService['MAX_STACK_ITEMS'];
82
- const locations: NavigationLocation[] = [...Array(max + 10).keys()].map(i => createCursorLocation({ line: i * 10, character: i }, `file://${i}`));
83
- stack.register(...locations);
84
- expect(stack.locations().length).to.not.be.greaterThan(max);
85
- });
86
-
87
- it('should successfully clear the history', () => {
88
- expect(stack['recentlyClosedEditors'].length).equal(0);
89
- const editor = createMockClosedEditor(new URI('file://foo/a.ts'));
90
- stack.addClosedEditor(editor);
91
- expect(stack['recentlyClosedEditors'].length).equal(1);
92
-
93
- expect(stack['stack'].length).equal(0);
94
- stack.register(
95
- createCursorLocation(),
96
- );
97
- expect(stack['stack'].length).equal(1);
98
-
99
- stack['clearHistory']();
100
-
101
- expect(stack['recentlyClosedEditors'].length).equal(0);
102
- expect(stack['stack'].length).equal(0);
103
- });
104
-
105
- describe('last-edit-location', async () => {
106
-
107
- it('should return with undefined if the stack contains no modifications', () => {
108
- stack.register(
109
- createCursorLocation(),
110
- createCursorLocation({ line: 100, character: 100 })
111
- );
112
- expect(stack.lastEditLocation()).to.be.undefined;
113
- });
114
-
115
- it('should return with the location of the last modification', () => {
116
- const expected = NavigationLocation.create('file://path/to/file', {
117
- text: '',
118
- range: { start: { line: 200, character: 0 }, end: { line: 500, character: 0 } },
119
- rangeLength: 0
120
- });
121
- stack.register(
122
- createCursorLocation(),
123
- expected,
124
- createCursorLocation({ line: 100, character: 100 })
125
- );
126
- expect(stack.lastEditLocation()).to.be.deep.equal(expected);
127
- });
128
-
129
- it('should return with the location of the last modification even if the pointer is not on the head', async () => {
130
- const modificationLocation = NavigationLocation.create('file://path/to/file', {
131
- text: '',
132
- range: { start: { line: 300, character: 0 }, end: { line: 500, character: 0 } },
133
- rangeLength: 0
134
- });
135
- const expected = NavigationLocation.create('file://path/to/file', {
136
- text: '',
137
- range: { start: { line: 700, character: 0 }, end: { line: 800, character: 0 } },
138
- rangeLength: 0
139
- });
140
- stack.register(
141
- createCursorLocation(),
142
- modificationLocation,
143
- createCursorLocation({ line: 100, character: 100 }),
144
- expected
145
- );
146
- await stack.back();
147
- await stack.back();
148
- expect(stack.currentLocation()).to.be.deep.equal(modificationLocation);
149
- expect(stack.lastEditLocation()).to.be.deep.equal(expected);
150
- });
151
-
152
- });
153
-
154
- describe('recently-closed-editors', () => {
155
-
156
- describe('#getLastClosedEditor', () => {
157
-
158
- it('should return the last closed editor from the history', () => {
159
- const uri = new URI('file://foo/a.ts');
160
- stack.addClosedEditor(createMockClosedEditor(uri));
161
- const editor = stack.getLastClosedEditor();
162
- expect(editor?.uri).equal(uri);
163
- });
164
-
165
- it('should return `undefined` when no history is found', () => {
166
- expect(stack['recentlyClosedEditors'].length).equal(0);
167
- const editor = stack.getLastClosedEditor();
168
- expect(editor).equal(undefined);
169
- });
170
-
171
- it('should not exceed the max history', () => {
172
- expect(stack['recentlyClosedEditors'].length).equal(0);
173
- const max = NavigationLocationService['MAX_RECENTLY_CLOSED_EDITORS'];
174
- for (let i = 0; i < max + 10; i++) {
175
- const uri = new URI(`file://foo/bar-${i}.ts`);
176
- stack.addClosedEditor(createMockClosedEditor(uri));
177
- }
178
- expect(stack['recentlyClosedEditors'].length <= max).be.true;
179
- });
180
-
181
- });
182
-
183
- describe('#addToRecentlyClosedEditors', () => {
184
-
185
- it('should include unique recently closed editors in the history', () => {
186
- expect(stack['recentlyClosedEditors'].length).equal(0);
187
- const a = createMockClosedEditor(new URI('file://foo/a.ts'));
188
- const b = createMockClosedEditor(new URI('file://foo/b.ts'));
189
- stack.addClosedEditor(a);
190
- stack.addClosedEditor(b);
191
- expect(stack['recentlyClosedEditors'].length).equal(2);
192
- });
193
-
194
- it('should not include duplicate recently closed editors in the history', () => {
195
- const uri = new URI('file://foo/a.ts');
196
- [1, 2, 3].forEach(i => {
197
- stack.addClosedEditor(createMockClosedEditor(uri));
198
- });
199
- expect(stack['recentlyClosedEditors'].length).equal(1);
200
- });
201
-
202
- });
203
-
204
- describe('#removeFromRecentlyClosedEditors', () => {
205
-
206
- it('should successfully remove editors from the history that match the given editor uri', () => {
207
- expect(stack['recentlyClosedEditors'].length).equal(0);
208
- const editor = createMockClosedEditor(new URI('file://foo/a.ts'));
209
-
210
- [1, 2, 3].forEach(() => {
211
- stack['recentlyClosedEditors'].push(editor);
212
- });
213
- expect(stack['recentlyClosedEditors'].length).equal(3);
214
-
215
- // Remove the given editor from the recently closed history.
216
- stack['removeClosedEditor'](editor.uri);
217
- expect(stack['recentlyClosedEditors'].length).equal(0);
218
- });
219
-
220
- });
221
-
222
- });
223
-
224
- function createCursorLocation(context: Position = { line: 0, character: 0, }, uri: string = 'file://path/to/file'): CursorLocation {
225
- return NavigationLocation.create(uri, context);
226
- }
227
-
228
- function init(): NavigationLocationService {
229
- const container = new Container({ defaultScope: 'Singleton' });
230
- container.bind(NavigationLocationService).toSelf();
231
- container.bind(NavigationLocationSimilarity).toSelf();
232
- container.bind(MockOpenerService).toSelf();
233
- container.bind(MockLogger).toSelf();
234
- container.bind(ILogger).toService(MockLogger);
235
- container.bind(NoopNavigationLocationUpdater).toSelf();
236
- container.bind(NavigationLocationUpdater).toService(NoopNavigationLocationUpdater);
237
- container.bind(OpenerService).toService(MockOpenerService);
238
- return container.get(NavigationLocationService);
239
- }
240
-
241
- function createMockClosedEditor(uri: URI): RecentlyClosedEditor {
242
- return { uri, viewState: {} };
243
- }
244
-
245
- });
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
+ import { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
17
+
18
+ let disableJSDOM = enableJSDOM();
19
+
20
+ import { expect } from 'chai';
21
+ import { Container } from '@theia/core/shared/inversify';
22
+ import URI from '@theia/core/lib/common/uri';
23
+ import { ILogger } from '@theia/core/lib/common/logger';
24
+ import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
25
+ import { OpenerService } from '@theia/core/lib/browser/opener-service';
26
+ import { MockOpenerService } from '@theia/core/lib/browser/test/mock-opener-service';
27
+ import { NavigationLocationUpdater } from './navigation-location-updater';
28
+ import { NoopNavigationLocationUpdater } from './test/mock-navigation-location-updater';
29
+ import { NavigationLocationSimilarity } from './navigation-location-similarity';
30
+ import { CursorLocation, Position, NavigationLocation, RecentlyClosedEditor } from './navigation-location';
31
+ import { NavigationLocationService } from './navigation-location-service';
32
+
33
+ disableJSDOM();
34
+
35
+ describe('navigation-location-service', () => {
36
+
37
+ let stack: NavigationLocationService;
38
+
39
+ before(() => {
40
+ disableJSDOM = enableJSDOM();
41
+ });
42
+
43
+ after(() => {
44
+ disableJSDOM();
45
+ });
46
+
47
+ beforeEach(() => {
48
+ stack = init();
49
+ });
50
+
51
+ it('should not allow navigating back when the stack is empty', () => {
52
+ expect(stack.canGoBack()).to.be.false;
53
+ });
54
+
55
+ it('should not allow navigating back when the stack has a single location', () => {
56
+ stack.register(createCursorLocation());
57
+ expect(stack.canGoBack()).to.be.false;
58
+ });
59
+
60
+ it('should allow navigating back when the stack has more than one locations', () => {
61
+ stack.register(
62
+ createCursorLocation(),
63
+ createCursorLocation({ line: 100, character: 100 })
64
+ );
65
+ expect(stack.canGoBack()).to.be.true;
66
+ });
67
+
68
+ it('should not allow navigating forward when the stack is empty', () => {
69
+ expect(stack.canGoForward()).to.be.false;
70
+ });
71
+
72
+ it('should not allow navigating forward when the pointer points to the end last element of the stack', () => {
73
+ stack.register(
74
+ createCursorLocation(),
75
+ createCursorLocation({ line: 100, character: 100 })
76
+ );
77
+ expect(stack.canGoForward()).to.be.false;
78
+ });
79
+
80
+ it('should not exceed the max stack item', () => {
81
+ const max = NavigationLocationService['MAX_STACK_ITEMS'];
82
+ const locations: NavigationLocation[] = [...Array(max + 10).keys()].map(i => createCursorLocation({ line: i * 10, character: i }, `file://${i}`));
83
+ stack.register(...locations);
84
+ expect(stack.locations().length).to.not.be.greaterThan(max);
85
+ });
86
+
87
+ it('should successfully clear the history', () => {
88
+ expect(stack['recentlyClosedEditors'].length).equal(0);
89
+ const editor = createMockClosedEditor(new URI('file://foo/a.ts'));
90
+ stack.addClosedEditor(editor);
91
+ expect(stack['recentlyClosedEditors'].length).equal(1);
92
+
93
+ expect(stack['stack'].length).equal(0);
94
+ stack.register(
95
+ createCursorLocation(),
96
+ );
97
+ expect(stack['stack'].length).equal(1);
98
+
99
+ stack['clearHistory']();
100
+
101
+ expect(stack['recentlyClosedEditors'].length).equal(0);
102
+ expect(stack['stack'].length).equal(0);
103
+ });
104
+
105
+ describe('last-edit-location', async () => {
106
+
107
+ it('should return with undefined if the stack contains no modifications', () => {
108
+ stack.register(
109
+ createCursorLocation(),
110
+ createCursorLocation({ line: 100, character: 100 })
111
+ );
112
+ expect(stack.lastEditLocation()).to.be.undefined;
113
+ });
114
+
115
+ it('should return with the location of the last modification', () => {
116
+ const expected = NavigationLocation.create('file://path/to/file', {
117
+ text: '',
118
+ range: { start: { line: 200, character: 0 }, end: { line: 500, character: 0 } },
119
+ rangeLength: 0
120
+ });
121
+ stack.register(
122
+ createCursorLocation(),
123
+ expected,
124
+ createCursorLocation({ line: 100, character: 100 })
125
+ );
126
+ expect(stack.lastEditLocation()).to.be.deep.equal(expected);
127
+ });
128
+
129
+ it('should return with the location of the last modification even if the pointer is not on the head', async () => {
130
+ const modificationLocation = NavigationLocation.create('file://path/to/file', {
131
+ text: '',
132
+ range: { start: { line: 300, character: 0 }, end: { line: 500, character: 0 } },
133
+ rangeLength: 0
134
+ });
135
+ const expected = NavigationLocation.create('file://path/to/file', {
136
+ text: '',
137
+ range: { start: { line: 700, character: 0 }, end: { line: 800, character: 0 } },
138
+ rangeLength: 0
139
+ });
140
+ stack.register(
141
+ createCursorLocation(),
142
+ modificationLocation,
143
+ createCursorLocation({ line: 100, character: 100 }),
144
+ expected
145
+ );
146
+ await stack.back();
147
+ await stack.back();
148
+ expect(stack.currentLocation()).to.be.deep.equal(modificationLocation);
149
+ expect(stack.lastEditLocation()).to.be.deep.equal(expected);
150
+ });
151
+
152
+ });
153
+
154
+ describe('recently-closed-editors', () => {
155
+
156
+ describe('#getLastClosedEditor', () => {
157
+
158
+ it('should return the last closed editor from the history', () => {
159
+ const uri = new URI('file://foo/a.ts');
160
+ stack.addClosedEditor(createMockClosedEditor(uri));
161
+ const editor = stack.getLastClosedEditor();
162
+ expect(editor?.uri).equal(uri);
163
+ });
164
+
165
+ it('should return `undefined` when no history is found', () => {
166
+ expect(stack['recentlyClosedEditors'].length).equal(0);
167
+ const editor = stack.getLastClosedEditor();
168
+ expect(editor).equal(undefined);
169
+ });
170
+
171
+ it('should not exceed the max history', () => {
172
+ expect(stack['recentlyClosedEditors'].length).equal(0);
173
+ const max = NavigationLocationService['MAX_RECENTLY_CLOSED_EDITORS'];
174
+ for (let i = 0; i < max + 10; i++) {
175
+ const uri = new URI(`file://foo/bar-${i}.ts`);
176
+ stack.addClosedEditor(createMockClosedEditor(uri));
177
+ }
178
+ expect(stack['recentlyClosedEditors'].length <= max).be.true;
179
+ });
180
+
181
+ });
182
+
183
+ describe('#addToRecentlyClosedEditors', () => {
184
+
185
+ it('should include unique recently closed editors in the history', () => {
186
+ expect(stack['recentlyClosedEditors'].length).equal(0);
187
+ const a = createMockClosedEditor(new URI('file://foo/a.ts'));
188
+ const b = createMockClosedEditor(new URI('file://foo/b.ts'));
189
+ stack.addClosedEditor(a);
190
+ stack.addClosedEditor(b);
191
+ expect(stack['recentlyClosedEditors'].length).equal(2);
192
+ });
193
+
194
+ it('should not include duplicate recently closed editors in the history', () => {
195
+ const uri = new URI('file://foo/a.ts');
196
+ [1, 2, 3].forEach(i => {
197
+ stack.addClosedEditor(createMockClosedEditor(uri));
198
+ });
199
+ expect(stack['recentlyClosedEditors'].length).equal(1);
200
+ });
201
+
202
+ });
203
+
204
+ describe('#removeFromRecentlyClosedEditors', () => {
205
+
206
+ it('should successfully remove editors from the history that match the given editor uri', () => {
207
+ expect(stack['recentlyClosedEditors'].length).equal(0);
208
+ const editor = createMockClosedEditor(new URI('file://foo/a.ts'));
209
+
210
+ [1, 2, 3].forEach(() => {
211
+ stack['recentlyClosedEditors'].push(editor);
212
+ });
213
+ expect(stack['recentlyClosedEditors'].length).equal(3);
214
+
215
+ // Remove the given editor from the recently closed history.
216
+ stack['removeClosedEditor'](editor.uri);
217
+ expect(stack['recentlyClosedEditors'].length).equal(0);
218
+ });
219
+
220
+ });
221
+
222
+ });
223
+
224
+ function createCursorLocation(context: Position = { line: 0, character: 0, }, uri: string = 'file://path/to/file'): CursorLocation {
225
+ return NavigationLocation.create(uri, context);
226
+ }
227
+
228
+ function init(): NavigationLocationService {
229
+ const container = new Container({ defaultScope: 'Singleton' });
230
+ container.bind(NavigationLocationService).toSelf();
231
+ container.bind(NavigationLocationSimilarity).toSelf();
232
+ container.bind(MockOpenerService).toSelf();
233
+ container.bind(MockLogger).toSelf();
234
+ container.bind(ILogger).toService(MockLogger);
235
+ container.bind(NoopNavigationLocationUpdater).toSelf();
236
+ container.bind(NavigationLocationUpdater).toService(NoopNavigationLocationUpdater);
237
+ container.bind(OpenerService).toService(MockOpenerService);
238
+ return container.get(NavigationLocationService);
239
+ }
240
+
241
+ function createMockClosedEditor(uri: URI): RecentlyClosedEditor {
242
+ return { uri, viewState: {} };
243
+ }
244
+
245
+ });