@codingame/monaco-vscode-notebook-service-override 2.1.3 → 2.2.0-next.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-notebook-service-override",
3
- "version": "2.1.3",
3
+ "version": "2.2.0-next.1",
4
4
  "keywords": [],
5
5
  "author": {
6
6
  "name": "CodinGame",
@@ -18,7 +18,7 @@
18
18
  "module": "index.js",
19
19
  "types": "index.d.ts",
20
20
  "dependencies": {
21
- "vscode": "npm:@codingame/monaco-vscode-api@2.1.3",
21
+ "vscode": "npm:@codingame/monaco-vscode-api@2.2.0-next.1",
22
22
  "vscode-marked": "npm:marked@=3.0.2"
23
23
  },
24
24
  "exports": {
@@ -2,7 +2,7 @@ import { __decorate, __param } from '../../../../../../../../../external/tslib/t
2
2
  import { Throttler } from 'vscode/vscode/vs/base/common/async';
3
3
  import { CancellationTokenSource } from 'vscode/vscode/vs/base/common/cancellation';
4
4
  import { Disposable, toDisposable } from 'vscode/vscode/vs/base/common/lifecycle';
5
- import { NotebookVisibleCellObserver } from './notebookVisibleCellObserver.js';
5
+ import { NotebookVisibleCellObserver } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/notebookVisibleCellObserver';
6
6
  import { registerNotebookContribution } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookEditorExtensions';
7
7
  import { INotebookCellStatusBarService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCellStatusBarService';
8
8
 
@@ -7,7 +7,7 @@ import { StartFindAction, StartFindReplaceAction, getSelectionSearchString } fro
7
7
  import { localize2WithPath } from 'vscode/vscode/vs/nls';
8
8
  import { registerAction2, Action2 } from 'vscode/vscode/vs/platform/actions/common/actions';
9
9
  import { ContextKeyExpr } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
10
- import { NotebookFindContrib } from './notebookFindWidget.js';
10
+ import { NotebookFindContrib } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget';
11
11
  import { getNotebookEditorFromEditorPane } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser';
12
12
  import { registerNotebookContribution } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookEditorExtensions';
13
13
  import { CellUri } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
@@ -60,7 +60,7 @@ import './contrib/outline/notebookOutline.js';
60
60
  import './contrib/profile/notebookProfile.js';
61
61
  import './contrib/cellStatusBar/statusBarProviders.js';
62
62
  import './contrib/cellStatusBar/contributedStatusBarItemController.js';
63
- import './contrib/cellStatusBar/executionStatusBarItemController.js';
63
+ import 'vscode/vscode/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController';
64
64
  import './contrib/editorStatusBar/editorStatusBar.js';
65
65
  import './contrib/undoRedo/notebookUndoRedo.js';
66
66
  import './contrib/cellCommands/cellCommands.js';
@@ -82,7 +82,7 @@ import { COMMENTEDITOR_DECORATION_KEY } from 'vscode/vscode/vs/workbench/contrib
82
82
  import { ICodeEditorService } from 'vscode/vscode/vs/editor/browser/services/codeEditorService';
83
83
  import './services/notebookKernelHistoryServiceImpl.js';
84
84
  import './services/notebookLoggingServiceImpl.js';
85
- import product$1 from 'vscode/vscode/vs/platform/product/common/product';
85
+ import product from 'vscode/vscode/vs/platform/product/common/product';
86
86
  import { NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_OUTPUT_FOCUSED } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookContextKeys';
87
87
  import { runAccessibilityHelpAction, showAccessibleOutput } from './notebookAccessibility.js';
88
88
  import { IAccessibleViewService } from 'vscode/vscode/vs/workbench/contrib/accessibility/browser/accessibleView';
@@ -962,7 +962,7 @@ configurationRegistry.registerConfiguration({
962
962
  )),
963
963
  type: 'boolean',
964
964
  tags: ['notebookLayout', 'notebookOutputLayout'],
965
- default: typeof product$1.quality === 'string' && product$1.quality !== 'stable'
965
+ default: typeof product.quality === 'string' && product.quality !== 'stable'
966
966
  },
967
967
  [NotebookSetting.outputWordWrap]: {
968
968
  markdownDescription: ( localizeWithPath(
@@ -1082,7 +1082,7 @@ configurationRegistry.registerConfiguration({
1082
1082
  "Enables the incremental saving of notebooks in Remote environment. When enabled, only the changes to the notebook are sent to the extension host, improving performance for large notebooks and slow network connections."
1083
1083
  )),
1084
1084
  type: 'boolean',
1085
- default: typeof product$1.quality === 'string' && product$1.quality !== 'stable'
1085
+ default: typeof product.quality === 'string' && product.quality !== 'stable'
1086
1086
  },
1087
1087
  [NotebookSetting.scrollToRevealCell]: {
1088
1088
  markdownDescription: ( localizeWithPath(
@@ -1,319 +0,0 @@
1
- import { __decorate, __param } from '../../../../../../../../../external/tslib/tslib.es6.js';
2
- import { disposableTimeout, RunOnceScheduler } from 'vscode/vscode/vs/base/common/async';
3
- import { Disposable, MutableDisposable, dispose } from 'vscode/vscode/vs/base/common/lifecycle';
4
- import { language } from 'vscode/vscode/vs/base/common/platform';
5
- import { localizeWithPath } from 'vscode/vscode/vs/nls';
6
- import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
7
- import { themeColorFromId } from 'vscode/vscode/vs/platform/theme/common/themeService';
8
- import { ThemeIcon } from 'vscode/vscode/vs/base/common/themables';
9
- import { NotebookVisibleCellObserver } from './notebookVisibleCellObserver.js';
10
- import { registerNotebookContribution } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookEditorExtensions';
11
- import { cellStatusIconSuccess, cellStatusIconError } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookEditorWidget';
12
- import { successStateIcon, errorStateIcon, pendingStateIcon, executingStateIcon } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookIcons';
13
- import { NotebookCellExecutionState } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
14
- import { NotebookExecutionType, INotebookExecutionStateService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookExecutionStateService';
15
- import { INotebookService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookService';
16
-
17
- var ExecutionStateCellStatusBarItem_1, TimerCellStatusBarItem_1;
18
- function formatCellDuration(duration, showMilliseconds = true) {
19
- if (showMilliseconds && duration < 1000) {
20
- return `${duration}ms`;
21
- }
22
- const minutes = Math.floor(duration / 1000 / 60);
23
- const seconds = Math.floor(duration / 1000) % 60;
24
- const tenths = Math.floor((duration % 1000) / 100);
25
- if (minutes > 0) {
26
- return `${minutes}m ${seconds}.${tenths}s`;
27
- }
28
- else {
29
- return `${seconds}.${tenths}s`;
30
- }
31
- }
32
- class NotebookStatusBarController extends Disposable {
33
- constructor(_notebookEditor, _itemFactory) {
34
- super();
35
- this._notebookEditor = _notebookEditor;
36
- this._itemFactory = _itemFactory;
37
- this._visibleCells = ( new Map());
38
- this._observer = this._register(( new NotebookVisibleCellObserver(this._notebookEditor)));
39
- this._register(this._observer.onDidChangeVisibleCells(this._updateVisibleCells, this));
40
- this._updateEverything();
41
- }
42
- _updateEverything() {
43
- this._visibleCells.forEach(dispose);
44
- this._visibleCells.clear();
45
- this._updateVisibleCells({ added: this._observer.visibleCells, removed: [] });
46
- }
47
- _updateVisibleCells(e) {
48
- const vm = this._notebookEditor.getViewModel();
49
- if (!vm) {
50
- return;
51
- }
52
- for (const oldCell of e.removed) {
53
- this._visibleCells.get(oldCell.handle)?.dispose();
54
- this._visibleCells.delete(oldCell.handle);
55
- }
56
- for (const newCell of e.added) {
57
- this._visibleCells.set(newCell.handle, this._itemFactory(vm, newCell));
58
- }
59
- }
60
- dispose() {
61
- super.dispose();
62
- this._visibleCells.forEach(dispose);
63
- this._visibleCells.clear();
64
- }
65
- }
66
- let ExecutionStateCellStatusBarContrib = class ExecutionStateCellStatusBarContrib extends Disposable {
67
- static { this.id = 'workbench.notebook.statusBar.execState'; }
68
- constructor(notebookEditor, instantiationService) {
69
- super();
70
- this._register(( new NotebookStatusBarController(
71
- notebookEditor,
72
- (vm, cell) => instantiationService.createInstance(ExecutionStateCellStatusBarItem, vm, cell)
73
- )));
74
- }
75
- };
76
- ExecutionStateCellStatusBarContrib = ( __decorate([
77
- ( __param(1, IInstantiationService))
78
- ], ExecutionStateCellStatusBarContrib));
79
- registerNotebookContribution(ExecutionStateCellStatusBarContrib.id, ExecutionStateCellStatusBarContrib);
80
- let ExecutionStateCellStatusBarItem = class ExecutionStateCellStatusBarItem extends Disposable {
81
- static { ExecutionStateCellStatusBarItem_1 = this; }
82
- static { this.MIN_SPINNER_TIME = 500; }
83
- constructor(_notebookViewModel, _cell, _executionStateService) {
84
- super();
85
- this._notebookViewModel = _notebookViewModel;
86
- this._cell = _cell;
87
- this._executionStateService = _executionStateService;
88
- this._currentItemIds = [];
89
- this._clearExecutingStateTimer = this._register(( new MutableDisposable()));
90
- this._update();
91
- this._register(this._executionStateService.onDidChangeExecution(e => {
92
- if (e.type === NotebookExecutionType.cell && e.affectsCell(this._cell.uri)) {
93
- this._update();
94
- }
95
- }));
96
- this._register(this._cell.model.onDidChangeInternalMetadata(() => this._update()));
97
- }
98
- async _update() {
99
- const items = this._getItemsForCell();
100
- if (Array.isArray(items)) {
101
- this._currentItemIds = this._notebookViewModel.deltaCellStatusBarItems(this._currentItemIds, [{ handle: this._cell.handle, items }]);
102
- }
103
- }
104
- _getItemsForCell() {
105
- const runState = this._executionStateService.getCellExecution(this._cell.uri);
106
- if (runState?.state === NotebookCellExecutionState.Executing && typeof this._showedExecutingStateTime !== 'number') {
107
- this._showedExecutingStateTime = Date.now();
108
- }
109
- else if (runState?.state !== NotebookCellExecutionState.Executing && typeof this._showedExecutingStateTime === 'number') {
110
- const timeUntilMin = ExecutionStateCellStatusBarItem_1.MIN_SPINNER_TIME - (Date.now() - this._showedExecutingStateTime);
111
- if (timeUntilMin > 0) {
112
- if (!this._clearExecutingStateTimer.value) {
113
- this._clearExecutingStateTimer.value = disposableTimeout(() => {
114
- this._showedExecutingStateTime = undefined;
115
- this._clearExecutingStateTimer.clear();
116
- this._update();
117
- }, timeUntilMin);
118
- }
119
- return undefined;
120
- }
121
- else {
122
- this._showedExecutingStateTime = undefined;
123
- }
124
- }
125
- const items = this._getItemForState(runState, this._cell.internalMetadata);
126
- return items;
127
- }
128
- _getItemForState(runState, internalMetadata) {
129
- const state = runState?.state;
130
- const { lastRunSuccess } = internalMetadata;
131
- if (!state && lastRunSuccess) {
132
- return [{
133
- text: `$(${successStateIcon.id})`,
134
- color: themeColorFromId(cellStatusIconSuccess),
135
- tooltip: ( localizeWithPath(
136
- 'vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController',
137
- 'notebook.cell.status.success',
138
- "Success"
139
- )),
140
- alignment: 1 ,
141
- priority: Number.MAX_SAFE_INTEGER
142
- }];
143
- }
144
- else if (!state && lastRunSuccess === false) {
145
- return [{
146
- text: `$(${errorStateIcon.id})`,
147
- color: themeColorFromId(cellStatusIconError),
148
- tooltip: ( localizeWithPath(
149
- 'vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController',
150
- 'notebook.cell.status.failed',
151
- "Failed"
152
- )),
153
- alignment: 1 ,
154
- priority: Number.MAX_SAFE_INTEGER
155
- }];
156
- }
157
- else if (state === NotebookCellExecutionState.Pending || state === NotebookCellExecutionState.Unconfirmed) {
158
- return [{
159
- text: `$(${pendingStateIcon.id})`,
160
- tooltip: ( localizeWithPath(
161
- 'vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController',
162
- 'notebook.cell.status.pending',
163
- "Pending"
164
- )),
165
- alignment: 1 ,
166
- priority: Number.MAX_SAFE_INTEGER
167
- }];
168
- }
169
- else if (state === NotebookCellExecutionState.Executing) {
170
- const icon = runState?.didPause ?
171
- executingStateIcon :
172
- ThemeIcon.modify(executingStateIcon, 'spin');
173
- return [{
174
- text: `$(${icon.id})`,
175
- tooltip: ( localizeWithPath(
176
- 'vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController',
177
- 'notebook.cell.status.executing',
178
- "Executing"
179
- )),
180
- alignment: 1 ,
181
- priority: Number.MAX_SAFE_INTEGER
182
- }];
183
- }
184
- return [];
185
- }
186
- dispose() {
187
- super.dispose();
188
- this._notebookViewModel.deltaCellStatusBarItems(this._currentItemIds, [{ handle: this._cell.handle, items: [] }]);
189
- }
190
- };
191
- ExecutionStateCellStatusBarItem = ExecutionStateCellStatusBarItem_1 = ( __decorate([
192
- ( __param(2, INotebookExecutionStateService))
193
- ], ExecutionStateCellStatusBarItem));
194
- let TimerCellStatusBarContrib = class TimerCellStatusBarContrib extends Disposable {
195
- static { this.id = 'workbench.notebook.statusBar.execTimer'; }
196
- constructor(notebookEditor, instantiationService) {
197
- super();
198
- this._register(( new NotebookStatusBarController(
199
- notebookEditor,
200
- (vm, cell) => instantiationService.createInstance(TimerCellStatusBarItem, vm, cell)
201
- )));
202
- }
203
- };
204
- TimerCellStatusBarContrib = ( __decorate([
205
- ( __param(1, IInstantiationService))
206
- ], TimerCellStatusBarContrib));
207
- registerNotebookContribution(TimerCellStatusBarContrib.id, TimerCellStatusBarContrib);
208
- const UPDATE_TIMER_GRACE_PERIOD = 200;
209
- let TimerCellStatusBarItem = class TimerCellStatusBarItem extends Disposable {
210
- static { TimerCellStatusBarItem_1 = this; }
211
- static { this.UPDATE_INTERVAL = 100; }
212
- constructor(_notebookViewModel, _cell, _executionStateService, _notebookService) {
213
- super();
214
- this._notebookViewModel = _notebookViewModel;
215
- this._cell = _cell;
216
- this._executionStateService = _executionStateService;
217
- this._notebookService = _notebookService;
218
- this._currentItemIds = [];
219
- this._scheduler = this._register(( new RunOnceScheduler(() => this._update(), TimerCellStatusBarItem_1.UPDATE_INTERVAL)));
220
- this._update();
221
- this._register(this._cell.model.onDidChangeInternalMetadata(() => this._update()));
222
- }
223
- async _update() {
224
- let timerItem;
225
- const runState = this._executionStateService.getCellExecution(this._cell.uri);
226
- const state = runState?.state;
227
- const startTime = this._cell.internalMetadata.runStartTime;
228
- const adjustment = this._cell.internalMetadata.runStartTimeAdjustment ?? 0;
229
- const endTime = this._cell.internalMetadata.runEndTime;
230
- if (runState?.didPause) {
231
- timerItem = undefined;
232
- }
233
- else if (state === NotebookCellExecutionState.Executing) {
234
- if (typeof startTime === 'number') {
235
- timerItem = this._getTimeItem(startTime, Date.now(), adjustment);
236
- this._scheduler.schedule();
237
- }
238
- }
239
- else if (!state) {
240
- if (typeof startTime === 'number' && typeof endTime === 'number') {
241
- const timerDuration = Date.now() - startTime + adjustment;
242
- const executionDuration = endTime - startTime;
243
- const renderDuration = this._cell.internalMetadata.renderDuration ?? {};
244
- timerItem = this._getTimeItem(startTime, endTime, undefined, {
245
- timerDuration,
246
- executionDuration,
247
- renderDuration
248
- });
249
- }
250
- }
251
- const items = timerItem ? [timerItem] : [];
252
- if (!items.length && !!runState) {
253
- if (!this._deferredUpdate) {
254
- this._deferredUpdate = disposableTimeout(() => {
255
- this._deferredUpdate = undefined;
256
- this._currentItemIds = this._notebookViewModel.deltaCellStatusBarItems(this._currentItemIds, [{ handle: this._cell.handle, items }]);
257
- }, UPDATE_TIMER_GRACE_PERIOD);
258
- }
259
- }
260
- else {
261
- this._deferredUpdate?.dispose();
262
- this._deferredUpdate = undefined;
263
- this._currentItemIds = this._notebookViewModel.deltaCellStatusBarItems(this._currentItemIds, [{ handle: this._cell.handle, items }]);
264
- }
265
- }
266
- _getTimeItem(startTime, endTime, adjustment = 0, runtimeInformation) {
267
- const duration = endTime - startTime + adjustment;
268
- let tooltip;
269
- if (runtimeInformation) {
270
- const lastExecution = ( new Date(endTime)).toLocaleTimeString(language);
271
- const { renderDuration, executionDuration, timerDuration } = runtimeInformation;
272
- let renderTimes = '';
273
- for (const key in renderDuration) {
274
- const rendererInfo = this._notebookService.getRendererInfo(key);
275
- const args = encodeURIComponent(JSON.stringify({
276
- extensionId: rendererInfo?.extensionId.value ?? '',
277
- issueBody: `Auto-generated text from notebook cell performance. The duration for the renderer, ${rendererInfo?.displayName ?? key}, is slower than expected.\n` +
278
- `Execution Time: ${formatCellDuration(executionDuration)}\n` +
279
- `Renderer Duration: ${formatCellDuration(renderDuration[key])}\n`
280
- }));
281
- renderTimes += `- [${rendererInfo?.displayName ?? key}](command:workbench.action.openIssueReporter?${args}) ${formatCellDuration(renderDuration[key])}\n`;
282
- }
283
- renderTimes += `\n*${( localizeWithPath(
284
- 'vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController',
285
- 'notebook.cell.statusBar.timerTooltip.reportIssueFootnote',
286
- "Use the links above to file an issue using the issue reporter."
287
- ))}*\n`;
288
- tooltip = {
289
- value: ( localizeWithPath(
290
- 'vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController',
291
- 'notebook.cell.statusBar.timerTooltip',
292
- "**Last Execution** {0}\n\n**Execution Time** {1}\n\n**Overhead Time** {2}\n\n**Render Times**\n\n{3}",
293
- lastExecution,
294
- formatCellDuration(executionDuration),
295
- formatCellDuration(timerDuration - executionDuration),
296
- renderTimes
297
- )),
298
- isTrusted: true
299
- };
300
- }
301
- return {
302
- text: formatCellDuration(duration, false),
303
- alignment: 1 ,
304
- priority: Number.MAX_SAFE_INTEGER - 5,
305
- tooltip
306
- };
307
- }
308
- dispose() {
309
- super.dispose();
310
- this._deferredUpdate?.dispose();
311
- this._notebookViewModel.deltaCellStatusBarItems(this._currentItemIds, [{ handle: this._cell.handle, items: [] }]);
312
- }
313
- };
314
- TimerCellStatusBarItem = TimerCellStatusBarItem_1 = ( __decorate([
315
- ( __param(2, INotebookExecutionStateService)),
316
- ( __param(3, INotebookService))
317
- ], TimerCellStatusBarItem));
318
-
319
- export { ExecutionStateCellStatusBarContrib, NotebookStatusBarController, TimerCellStatusBarContrib, formatCellDuration };
@@ -1,58 +0,0 @@
1
- import { diffSets } from 'vscode/vscode/vs/base/common/collections';
2
- import { Emitter } from 'vscode/vscode/vs/base/common/event';
3
- import { Disposable, DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
4
- import { isDefined } from 'vscode/vscode/vs/base/common/types';
5
- import { cellRangesToIndexes } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookRange';
6
-
7
- class NotebookVisibleCellObserver extends Disposable {
8
- get visibleCells() {
9
- return this._visibleCells;
10
- }
11
- constructor(_notebookEditor) {
12
- super();
13
- this._notebookEditor = _notebookEditor;
14
- this._onDidChangeVisibleCells = this._register(( new Emitter()));
15
- this.onDidChangeVisibleCells = this._onDidChangeVisibleCells.event;
16
- this._viewModelDisposables = this._register(( new DisposableStore()));
17
- this._visibleCells = [];
18
- this._register(this._notebookEditor.onDidChangeVisibleRanges(this._updateVisibleCells, this));
19
- this._register(this._notebookEditor.onDidChangeModel(this._onModelChange, this));
20
- this._updateVisibleCells();
21
- }
22
- _onModelChange() {
23
- this._viewModelDisposables.clear();
24
- if (this._notebookEditor.hasModel()) {
25
- this._viewModelDisposables.add(this._notebookEditor.onDidChangeViewCells(() => this.updateEverything()));
26
- }
27
- this.updateEverything();
28
- }
29
- updateEverything() {
30
- this._onDidChangeVisibleCells.fire({ added: [], removed: Array.from(this._visibleCells) });
31
- this._visibleCells = [];
32
- this._updateVisibleCells();
33
- }
34
- _updateVisibleCells() {
35
- if (!this._notebookEditor.hasModel()) {
36
- return;
37
- }
38
- const newVisibleCells = ( cellRangesToIndexes(this._notebookEditor.visibleRanges)
39
- .map(index => this._notebookEditor.cellAt(index)))
40
- .filter(isDefined);
41
- const newVisibleHandles = ( new Set(( newVisibleCells.map(cell => cell.handle))));
42
- const oldVisibleHandles = ( new Set(( this._visibleCells.map(cell => cell.handle))));
43
- const diff = diffSets(oldVisibleHandles, newVisibleHandles);
44
- const added = ( diff.added
45
- .map(handle => this._notebookEditor.getCellByHandle(handle)))
46
- .filter(isDefined);
47
- const removed = ( diff.removed
48
- .map(handle => this._notebookEditor.getCellByHandle(handle)))
49
- .filter(isDefined);
50
- this._visibleCells = newVisibleCells;
51
- this._onDidChangeVisibleCells.fire({
52
- added,
53
- removed
54
- });
55
- }
56
- }
57
-
58
- export { NotebookVisibleCellObserver };
@@ -1,317 +0,0 @@
1
- import { __decorate, __param } from '../../../../../../../../../external/tslib/tslib.es6.js';
2
- import { append, addDisposableListener, EventType, getWindow } from 'vscode/vscode/vs/base/browser/dom';
3
- import { alert } from 'vscode/vscode/vs/base/browser/ui/aria/aria';
4
- import { Lazy } from 'vscode/vscode/vs/base/common/lazy';
5
- import { Disposable } from 'vscode/vscode/vs/base/common/lifecycle';
6
- import { format } from 'vscode/vscode/vs/base/common/strings';
7
- import { MATCHES_LIMIT } from 'vscode/vscode/vs/editor/contrib/find/browser/findModel';
8
- import { FindReplaceState } from 'vscode/vscode/vs/editor/contrib/find/browser/findState';
9
- import { NLS_MATCHES_LOCATION, NLS_NO_RESULTS } from 'vscode/vscode/vs/editor/contrib/find/browser/findWidget';
10
- import { localizeWithPath } from 'vscode/vscode/vs/nls';
11
- import { IMenuService } from 'vscode/vscode/vs/platform/actions/common/actions';
12
- import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
13
- import { IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
14
- import { IContextViewService, IContextMenuService } from 'vscode/vscode/vs/platform/contextview/browser/contextView';
15
- import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
16
- import { FindModel } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/contrib/find/findModel';
17
- import { SimpleFindReplaceWidget } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindReplaceWidget';
18
- import { CellEditState } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser';
19
- import { KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookContextKeys';
20
-
21
- const FIND_HIDE_TRANSITION = 'find-hide-transition';
22
- const FIND_SHOW_TRANSITION = 'find-show-transition';
23
- let MAX_MATCHES_COUNT_WIDTH = 69;
24
- const PROGRESS_BAR_DELAY = 200;
25
- let NotebookFindContrib = class NotebookFindContrib extends Disposable {
26
- static { this.id = 'workbench.notebook.find'; }
27
- constructor(notebookEditor, instantiationService) {
28
- super();
29
- this.notebookEditor = notebookEditor;
30
- this.instantiationService = instantiationService;
31
- this.widget = ( new Lazy(
32
- () => this._register(this.instantiationService.createInstance(NotebookFindWidget, this.notebookEditor))
33
- ));
34
- }
35
- show(initialInput, options) {
36
- return this.widget.value.show(initialInput, options);
37
- }
38
- hide() {
39
- this.widget.rawValue?.hide();
40
- }
41
- replace(searchString) {
42
- return this.widget.value.replace(searchString);
43
- }
44
- };
45
- NotebookFindContrib = ( __decorate([
46
- ( __param(1, IInstantiationService))
47
- ], NotebookFindContrib));
48
- let NotebookFindWidget = class NotebookFindWidget extends SimpleFindReplaceWidget {
49
- constructor(_notebookEditor, contextViewService, contextKeyService, configurationService, contextMenuService, menuService, instantiationService) {
50
- super(contextViewService, contextKeyService, configurationService, contextMenuService, instantiationService, ( new FindReplaceState()), _notebookEditor);
51
- this._showTimeout = null;
52
- this._hideTimeout = null;
53
- this._findModel = ( new FindModel(this._notebookEditor, this._state, this._configurationService));
54
- append(this._notebookEditor.getDomNode(), this.getDomNode());
55
- this._findWidgetFocused = KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED.bindTo(contextKeyService);
56
- this._register(this._findInput.onKeyDown((e) => this._onFindInputKeyDown(e)));
57
- this._register(this._replaceInput.onKeyDown((e) => this._onReplaceInputKeyDown(e)));
58
- this._register(this._state.onFindReplaceStateChange((e) => {
59
- this.onInputChanged();
60
- if (e.isSearching) {
61
- if (this._state.isSearching) {
62
- this._progressBar.infinite().show(PROGRESS_BAR_DELAY);
63
- }
64
- else {
65
- this._progressBar.stop().hide();
66
- }
67
- }
68
- if (this._findModel.currentMatch >= 0) {
69
- const currentMatch = this._findModel.getCurrentMatch();
70
- this._replaceBtn.setEnabled(currentMatch.isModelMatch);
71
- }
72
- const matches = this._findModel.findMatches;
73
- this._replaceAllBtn.setEnabled(matches.length > 0 && matches.find(match => match.webviewMatches.length > 0) === undefined);
74
- if (e.filters) {
75
- this._findInput.updateFilterState(this._state.filters?.isModified() ?? false);
76
- }
77
- }));
78
- this._register(addDisposableListener(this.getDomNode(), EventType.FOCUS, e => {
79
- this._previousFocusElement = e.relatedTarget instanceof HTMLElement ? e.relatedTarget : undefined;
80
- }, true));
81
- }
82
- _onFindInputKeyDown(e) {
83
- if (e.equals(3 )) {
84
- this.find(false);
85
- e.preventDefault();
86
- return;
87
- }
88
- else if (e.equals(1024 | 3 )) {
89
- this.find(true);
90
- e.preventDefault();
91
- return;
92
- }
93
- }
94
- _onReplaceInputKeyDown(e) {
95
- if (e.equals(3 )) {
96
- this.replaceOne();
97
- e.preventDefault();
98
- return;
99
- }
100
- }
101
- onInputChanged() {
102
- this._state.change({ searchString: this.inputValue }, false);
103
- const findMatches = this._findModel.findMatches;
104
- if (findMatches && findMatches.length) {
105
- return true;
106
- }
107
- return false;
108
- }
109
- findIndex(index) {
110
- this._findModel.find({ index });
111
- }
112
- find(previous) {
113
- this._findModel.find({ previous });
114
- }
115
- replaceOne() {
116
- if (!this._notebookEditor.hasModel()) {
117
- return;
118
- }
119
- if (!this._findModel.findMatches.length) {
120
- return;
121
- }
122
- this._findModel.ensureFindMatches();
123
- if (this._findModel.currentMatch < 0) {
124
- this._findModel.find({ previous: false });
125
- }
126
- const currentMatch = this._findModel.getCurrentMatch();
127
- const cell = currentMatch.cell;
128
- if (currentMatch.isModelMatch) {
129
- const match = currentMatch.match;
130
- this._progressBar.infinite().show(PROGRESS_BAR_DELAY);
131
- const replacePattern = this.replacePattern;
132
- const replaceString = replacePattern.buildReplaceString(match.matches, this._state.preserveCase);
133
- const viewModel = this._notebookEditor.getViewModel();
134
- viewModel.replaceOne(cell, match.range, replaceString).then(() => {
135
- this._progressBar.stop();
136
- });
137
- }
138
- else {
139
- console.error('Replace does not work for output match');
140
- }
141
- }
142
- replaceAll() {
143
- if (!this._notebookEditor.hasModel()) {
144
- return;
145
- }
146
- this._progressBar.infinite().show(PROGRESS_BAR_DELAY);
147
- const replacePattern = this.replacePattern;
148
- const cellFindMatches = this._findModel.findMatches;
149
- const replaceStrings = [];
150
- cellFindMatches.forEach(cellFindMatch => {
151
- cellFindMatch.contentMatches.forEach(match => {
152
- const matches = match.matches;
153
- replaceStrings.push(replacePattern.buildReplaceString(matches, this._state.preserveCase));
154
- });
155
- });
156
- const viewModel = this._notebookEditor.getViewModel();
157
- viewModel.replaceAll(this._findModel.findMatches, replaceStrings).then(() => {
158
- this._progressBar.stop();
159
- });
160
- }
161
- findFirst() { }
162
- onFocusTrackerFocus() {
163
- this._findWidgetFocused.set(true);
164
- }
165
- onFocusTrackerBlur() {
166
- this._previousFocusElement = undefined;
167
- this._findWidgetFocused.reset();
168
- }
169
- onReplaceInputFocusTrackerFocus() {
170
- }
171
- onReplaceInputFocusTrackerBlur() {
172
- }
173
- onFindInputFocusTrackerFocus() { }
174
- onFindInputFocusTrackerBlur() { }
175
- async show(initialInput, options) {
176
- const searchStringUpdate = this._state.searchString !== initialInput;
177
- super.show(initialInput, options);
178
- this._state.change({ searchString: initialInput ?? this._state.searchString, isRevealed: true }, false);
179
- if (typeof options?.matchIndex === 'number') {
180
- if (!this._findModel.findMatches.length) {
181
- await this._findModel.research();
182
- }
183
- this.findIndex(options.matchIndex);
184
- }
185
- else {
186
- this._findInput.select();
187
- }
188
- if (!searchStringUpdate && options?.searchStringSeededFrom) {
189
- this._findModel.refreshCurrentMatch(options.searchStringSeededFrom);
190
- }
191
- if (this._showTimeout === null) {
192
- if (this._hideTimeout !== null) {
193
- getWindow(this.getDomNode()).clearTimeout(this._hideTimeout);
194
- this._hideTimeout = null;
195
- this._notebookEditor.removeClassName(FIND_HIDE_TRANSITION);
196
- }
197
- this._notebookEditor.addClassName(FIND_SHOW_TRANSITION);
198
- this._showTimeout = getWindow(this.getDomNode()).setTimeout(() => {
199
- this._notebookEditor.removeClassName(FIND_SHOW_TRANSITION);
200
- this._showTimeout = null;
201
- }, 200);
202
- }
203
- }
204
- replace(initialFindInput, initialReplaceInput) {
205
- super.showWithReplace(initialFindInput, initialReplaceInput);
206
- this._state.change({ searchString: initialFindInput ?? '', replaceString: initialReplaceInput ?? '', isRevealed: true }, false);
207
- this._replaceInput.select();
208
- if (this._showTimeout === null) {
209
- if (this._hideTimeout !== null) {
210
- getWindow(this.getDomNode()).clearTimeout(this._hideTimeout);
211
- this._hideTimeout = null;
212
- this._notebookEditor.removeClassName(FIND_HIDE_TRANSITION);
213
- }
214
- this._notebookEditor.addClassName(FIND_SHOW_TRANSITION);
215
- this._showTimeout = getWindow(this.getDomNode()).setTimeout(() => {
216
- this._notebookEditor.removeClassName(FIND_SHOW_TRANSITION);
217
- this._showTimeout = null;
218
- }, 200);
219
- }
220
- }
221
- hide() {
222
- super.hide();
223
- this._state.change({ isRevealed: false }, false);
224
- this._findModel.clear();
225
- this._notebookEditor.findStop();
226
- this._progressBar.stop();
227
- if (this._hideTimeout === null) {
228
- if (this._showTimeout !== null) {
229
- getWindow(this.getDomNode()).clearTimeout(this._showTimeout);
230
- this._showTimeout = null;
231
- this._notebookEditor.removeClassName(FIND_SHOW_TRANSITION);
232
- }
233
- this._notebookEditor.addClassName(FIND_HIDE_TRANSITION);
234
- this._hideTimeout = getWindow(this.getDomNode()).setTimeout(() => {
235
- this._notebookEditor.removeClassName(FIND_HIDE_TRANSITION);
236
- }, 200);
237
- }
238
- if (this._previousFocusElement && this._previousFocusElement.offsetParent) {
239
- this._previousFocusElement.focus();
240
- this._previousFocusElement = undefined;
241
- }
242
- if (this._notebookEditor.hasModel()) {
243
- for (let i = 0; i < this._notebookEditor.getLength(); i++) {
244
- const cell = this._notebookEditor.cellAt(i);
245
- if (cell.getEditState() === CellEditState.Editing && cell.editStateSource === 'find') {
246
- cell.updateEditState(CellEditState.Preview, 'closeFind');
247
- }
248
- }
249
- }
250
- }
251
- _updateMatchesCount() {
252
- if (!this._findModel || !this._findModel.findMatches) {
253
- return;
254
- }
255
- this._matchesCount.style.width = MAX_MATCHES_COUNT_WIDTH + 'px';
256
- this._matchesCount.title = '';
257
- if (this._matchesCount.firstChild) {
258
- this._matchesCount.removeChild(this._matchesCount.firstChild);
259
- }
260
- let label;
261
- if (this._state.matchesCount > 0) {
262
- let matchesCount = String(this._state.matchesCount);
263
- if (this._state.matchesCount >= MATCHES_LIMIT) {
264
- matchesCount += '+';
265
- }
266
- const matchesPosition = this._findModel.currentMatch < 0 ? '?' : String((this._findModel.currentMatch + 1));
267
- label = format(NLS_MATCHES_LOCATION, matchesPosition, matchesCount);
268
- }
269
- else {
270
- label = NLS_NO_RESULTS;
271
- }
272
- this._matchesCount.appendChild(document.createTextNode(label));
273
- alert(this._getAriaLabel(label, this._state.currentMatch, this._state.searchString));
274
- MAX_MATCHES_COUNT_WIDTH = Math.max(MAX_MATCHES_COUNT_WIDTH, this._matchesCount.clientWidth);
275
- }
276
- _getAriaLabel(label, currentMatch, searchString) {
277
- if (label === NLS_NO_RESULTS) {
278
- return searchString === ''
279
- ? ( localizeWithPath(
280
- 'vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget',
281
- 'ariaSearchNoResultEmpty',
282
- "{0} found",
283
- label
284
- ))
285
- : ( localizeWithPath(
286
- 'vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget',
287
- 'ariaSearchNoResult',
288
- "{0} found for '{1}'",
289
- label,
290
- searchString
291
- ));
292
- }
293
- return ( localizeWithPath(
294
- 'vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget',
295
- 'ariaSearchNoResultWithLineNumNoCurrentMatch',
296
- "{0} found for '{1}'",
297
- label,
298
- searchString
299
- ));
300
- }
301
- dispose() {
302
- this._notebookEditor?.removeClassName(FIND_SHOW_TRANSITION);
303
- this._notebookEditor?.removeClassName(FIND_HIDE_TRANSITION);
304
- this._findModel.dispose();
305
- super.dispose();
306
- }
307
- };
308
- NotebookFindWidget = ( __decorate([
309
- ( __param(1, IContextViewService)),
310
- ( __param(2, IContextKeyService)),
311
- ( __param(3, IConfigurationService)),
312
- ( __param(4, IContextMenuService)),
313
- ( __param(5, IMenuService)),
314
- ( __param(6, IInstantiationService))
315
- ], NotebookFindWidget));
316
-
317
- export { NotebookFindContrib };