@codingame/monaco-vscode-notebook-service-override 3.2.3 → 4.1.0

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 (80) hide show
  1. package/notebook.js +13 -13
  2. package/package.json +2 -2
  3. package/external/rollup-plugin-styles/dist/runtime/inject-css.js +0 -3
  4. package/external/tslib/tslib.es6.js +0 -11
  5. package/override/vs/platform/dialogs/common/dialogs.js +0 -8
  6. package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.css.js +0 -6
  7. package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.js +0 -389
  8. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellCommands/cellCommands.js +0 -608
  9. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/contributedStatusBarItemController.js +0 -109
  10. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/statusBarProviders.js +0 -173
  11. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard.js +0 -488
  12. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookBreakpoints.js +0 -106
  13. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookCellPausing.js +0 -67
  14. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookDebugDecorations.js +0 -165
  15. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/editorHint/emptyCellEditorHint.js +0 -67
  16. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/editorStatusBar/editorStatusBar.js +0 -320
  17. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/execute/executionEditorProgress.js +0 -72
  18. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/media/notebookFind.css.js +0 -6
  19. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFind.js +0 -168
  20. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/format/formatting.js +0 -209
  21. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/gettingStarted/notebookGettingStarted.js +0 -84
  22. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/kernelDetection/notebookKernelDetection.js +0 -82
  23. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/layout/layoutActions.js +0 -67
  24. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider.js +0 -91
  25. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/navigation/arrow.js +0 -393
  26. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariableContextKeys.js +0 -5
  27. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariables.js +0 -97
  28. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesDataSource.js +0 -118
  29. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesTree.js +0 -59
  30. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.js +0 -148
  31. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline.js +0 -383
  32. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/profile/notebookProfile.js +0 -77
  33. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants.js +0 -511
  34. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout.js +0 -159
  35. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/undoRedo/notebookUndoRedo.js +0 -56
  36. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/viewportWarmup/viewportWarmup.js +0 -94
  37. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/apiActions.js +0 -51
  38. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/chat/cellChatActions.js +0 -565
  39. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/chat/notebookChatContext.js +0 -31
  40. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/chat/notebookChatController.js +0 -744
  41. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/executeActions.js +0 -707
  42. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/insertCellActions.js +0 -351
  43. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/layoutActions.js +0 -267
  44. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions.js +0 -45
  45. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.js +0 -1297
  46. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementOutputs.js +0 -284
  47. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.js +0 -563
  48. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.js +0 -108
  49. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/eventDispatcher.js +0 -39
  50. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiff.css.js +0 -6
  51. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.js +0 -313
  52. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.js +0 -890
  53. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.js +0 -13
  54. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.js +0 -393
  55. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffOverviewRuler.js +0 -175
  56. package/vscode/src/vs/workbench/contrib/notebook/browser/notebook.contribution.js +0 -1174
  57. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookAccessibility.js +0 -159
  58. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookExtensionPoint.js +0 -451
  59. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookEditorServiceImpl.js +0 -192
  60. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl.js +0 -106
  61. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionStateServiceImpl.js +0 -509
  62. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelHistoryServiceImpl.js +0 -130
  63. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl.js +0 -341
  64. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKeymapServiceImpl.js +0 -111
  65. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookLoggingServiceImpl.js +0 -28
  66. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookRendererMessagingServiceImpl.js +0 -65
  67. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.js +0 -641
  68. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookWorkerServiceImpl.js +0 -200
  69. package/vscode/src/vs/workbench/contrib/notebook/common/model/cellEdit.js +0 -80
  70. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.js +0 -1003
  71. package/vscode/src/vs/workbench/contrib/notebook/common/notebookDiffEditorInput.js +0 -103
  72. package/vscode/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverServiceImpl.js +0 -202
  73. package/vscode/src/vs/workbench/contrib/notebook/common/notebookOutputRenderer.js +0 -80
  74. package/vscode/src/vs/workbench/contrib/notebook/common/notebookProvider.js +0 -98
  75. package/vscode/src/vs/workbench/contrib/search/browser/notebookSearch/notebookSearchService.js +0 -237
  76. package/vscode/src/vs/workbench/services/workingCopy/common/abstractFileWorkingCopyManager.js +0 -89
  77. package/vscode/src/vs/workbench/services/workingCopy/common/fileWorkingCopyManager.js +0 -376
  78. package/vscode/src/vs/workbench/services/workingCopy/common/storedFileWorkingCopyManager.js +0 -408
  79. package/vscode/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopy.js +0 -144
  80. package/vscode/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopyManager.js +0 -129
@@ -1,1003 +0,0 @@
1
- import { __decorate, __param } from '../../../../../../../../external/tslib/tslib.es6.js';
2
- import { Emitter, PauseableEmitter } from 'vscode/vscode/vs/base/common/event';
3
- import { Disposable, dispose } from 'vscode/vscode/vs/base/common/lifecycle';
4
- import { NotebookCellTextModel } from 'vscode/vscode/vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
5
- import { CellUri, NotebookCellsChangeType, CellKind, diff } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
6
- import { IUndoRedoService } from 'vscode/vscode/vs/platform/undoRedo/common/undoRedo';
7
- import { SpliceCellsEdit, CellMetadataEdit, MoveCellEdit } from './cellEdit.js';
8
- import { LcsDiff } from 'vscode/vscode/vs/base/common/diff/diff';
9
- import { hash } from 'vscode/vscode/vs/base/common/hash';
10
- import { NotebookCellOutputTextModel } from 'vscode/vscode/vs/workbench/contrib/notebook/common/model/notebookCellOutputTextModel';
11
- import { IModelService } from 'vscode/vscode/vs/editor/common/services/model';
12
- import { Schemas } from 'vscode/vscode/vs/base/common/network';
13
- import { isEqual } from 'vscode/vscode/vs/base/common/resources';
14
- import { ILanguageService } from 'vscode/vscode/vs/editor/common/languages/language';
15
- import { TextModel } from 'vscode/vscode/vs/editor/common/model/textModel';
16
- import { isDefined } from 'vscode/vscode/vs/base/common/types';
17
-
18
- var NotebookTextModel_1;
19
- class StackOperation {
20
- constructor(textModel, label, undoRedoGroup, _pauseableEmitter, _postUndoRedo, selectionState, beginAlternativeVersionId) {
21
- this.textModel = textModel;
22
- this.label = label;
23
- this.undoRedoGroup = undoRedoGroup;
24
- this._pauseableEmitter = _pauseableEmitter;
25
- this._postUndoRedo = _postUndoRedo;
26
- this.code = 'undoredo.notebooks.stackOperation';
27
- this._operations = [];
28
- this._beginSelectionState = undefined;
29
- this._resultSelectionState = undefined;
30
- this.type = 1 ;
31
- this._beginSelectionState = selectionState;
32
- this._beginAlternativeVersionId = beginAlternativeVersionId;
33
- this._resultAlternativeVersionId = beginAlternativeVersionId;
34
- }
35
- get resources() {
36
- return [this.textModel.uri];
37
- }
38
- get isEmpty() {
39
- return this._operations.length === 0;
40
- }
41
- pushEndState(alternativeVersionId, selectionState) {
42
- this._resultAlternativeVersionId = alternativeVersionId;
43
- this._resultSelectionState = selectionState;
44
- }
45
- pushEditOperation(element, beginSelectionState, resultSelectionState) {
46
- if (this._operations.length === 0) {
47
- this._beginSelectionState = this._beginSelectionState ?? beginSelectionState;
48
- }
49
- this._operations.push(element);
50
- this._resultSelectionState = resultSelectionState;
51
- }
52
- async undo() {
53
- this._pauseableEmitter.pause();
54
- for (let i = this._operations.length - 1; i >= 0; i--) {
55
- await this._operations[i].undo();
56
- }
57
- this._postUndoRedo(this._beginAlternativeVersionId);
58
- this._pauseableEmitter.fire({
59
- rawEvents: [],
60
- synchronous: undefined,
61
- versionId: this.textModel.versionId,
62
- endSelectionState: this._beginSelectionState
63
- });
64
- this._pauseableEmitter.resume();
65
- }
66
- async redo() {
67
- this._pauseableEmitter.pause();
68
- for (let i = 0; i < this._operations.length; i++) {
69
- await this._operations[i].redo();
70
- }
71
- this._postUndoRedo(this._resultAlternativeVersionId);
72
- this._pauseableEmitter.fire({
73
- rawEvents: [],
74
- synchronous: undefined,
75
- versionId: this.textModel.versionId,
76
- endSelectionState: this._resultSelectionState
77
- });
78
- this._pauseableEmitter.resume();
79
- }
80
- }
81
- class NotebookOperationManager {
82
- constructor(_textModel, _undoService, _pauseableEmitter, _postUndoRedo) {
83
- this._textModel = _textModel;
84
- this._undoService = _undoService;
85
- this._pauseableEmitter = _pauseableEmitter;
86
- this._postUndoRedo = _postUndoRedo;
87
- this._pendingStackOperation = null;
88
- }
89
- isUndoStackEmpty() {
90
- return this._pendingStackOperation === null || this._pendingStackOperation.isEmpty;
91
- }
92
- pushStackElement(label, selectionState, undoRedoGroup, alternativeVersionId) {
93
- if (this._pendingStackOperation) {
94
- this._pendingStackOperation.pushEndState(alternativeVersionId, selectionState);
95
- if (!this._pendingStackOperation.isEmpty) {
96
- this._undoService.pushElement(this._pendingStackOperation, this._pendingStackOperation.undoRedoGroup);
97
- }
98
- this._pendingStackOperation = null;
99
- return;
100
- }
101
- this._pendingStackOperation = ( new StackOperation(
102
- this._textModel,
103
- label,
104
- undoRedoGroup,
105
- this._pauseableEmitter,
106
- this._postUndoRedo,
107
- selectionState,
108
- alternativeVersionId
109
- ));
110
- }
111
- pushEditOperation(element, beginSelectionState, resultSelectionState) {
112
- if (this._pendingStackOperation) {
113
- this._pendingStackOperation.pushEditOperation(element, beginSelectionState, resultSelectionState);
114
- return;
115
- }
116
- this._undoService.pushElement(element);
117
- }
118
- }
119
- class NotebookEventEmitter extends PauseableEmitter {
120
- isDirtyEvent() {
121
- for (const e of this._eventQueue) {
122
- for (let i = 0; i < e.rawEvents.length; i++) {
123
- if (!e.rawEvents[i].transient) {
124
- return true;
125
- }
126
- }
127
- }
128
- return false;
129
- }
130
- }
131
- let NotebookTextModel = NotebookTextModel_1 = class NotebookTextModel extends Disposable {
132
- get length() {
133
- return this._cells.length;
134
- }
135
- get cells() {
136
- return this._cells;
137
- }
138
- get versionId() {
139
- return this._versionId;
140
- }
141
- get alternativeVersionId() {
142
- return this._alternativeVersionId;
143
- }
144
- constructor(viewType, uri, cells, metadata, options, _undoService, _modelService, _languageService) {
145
- super();
146
- this.viewType = viewType;
147
- this.uri = uri;
148
- this._undoService = _undoService;
149
- this._modelService = _modelService;
150
- this._languageService = _languageService;
151
- this._isDisposed = false;
152
- this._onWillDispose = this._register(( new Emitter()));
153
- this._onWillAddRemoveCells = this._register(( new Emitter()));
154
- this._onDidChangeContent = this._register(( new Emitter()));
155
- this.onWillDispose = this._onWillDispose.event;
156
- this.onWillAddRemoveCells = this._onWillAddRemoveCells.event;
157
- this.onDidChangeContent = this._onDidChangeContent.event;
158
- this._cellhandlePool = 0;
159
- this._cellListeners = ( new Map());
160
- this._cells = [];
161
- this.metadata = {};
162
- this.transientOptions = { transientCellMetadata: {}, transientDocumentMetadata: {}, transientOutputs: false, cellContentMetadata: {} };
163
- this._versionId = 0;
164
- this._notebookSpecificAlternativeId = 0;
165
- this._alternativeVersionId = '1';
166
- this.transientOptions = options;
167
- this.metadata = metadata;
168
- this._initialize(cells);
169
- const maybeUpdateCellTextModel = (textModel) => {
170
- if (textModel.uri.scheme === Schemas.vscodeNotebookCell && textModel instanceof TextModel) {
171
- const cellUri = CellUri.parse(textModel.uri);
172
- if (cellUri && isEqual(cellUri.notebook, this.uri)) {
173
- const cellIdx = this._getCellIndexByHandle(cellUri.handle);
174
- if (cellIdx >= 0) {
175
- const cell = this.cells[cellIdx];
176
- if (cell) {
177
- cell.textModel = textModel;
178
- }
179
- }
180
- }
181
- }
182
- };
183
- this._register(_modelService.onModelAdded(e => maybeUpdateCellTextModel(e)));
184
- this._pauseableEmitter = ( new NotebookEventEmitter({
185
- merge: (events) => {
186
- const first = events[0];
187
- const rawEvents = first.rawEvents;
188
- let versionId = first.versionId;
189
- let endSelectionState = first.endSelectionState;
190
- let synchronous = first.synchronous;
191
- for (let i = 1; i < events.length; i++) {
192
- rawEvents.push(...events[i].rawEvents);
193
- versionId = events[i].versionId;
194
- endSelectionState = events[i].endSelectionState !== undefined ? events[i].endSelectionState : endSelectionState;
195
- synchronous = events[i].synchronous !== undefined ? events[i].synchronous : synchronous;
196
- }
197
- return { rawEvents, versionId, endSelectionState, synchronous };
198
- }
199
- }));
200
- this._register(this._pauseableEmitter.event(e => {
201
- if (e.rawEvents.length) {
202
- this._onDidChangeContent.fire(e);
203
- }
204
- }));
205
- this._operationManager = ( new NotebookOperationManager(
206
- this,
207
- this._undoService,
208
- this._pauseableEmitter,
209
- (alternativeVersionId) => {
210
- this._increaseVersionId(true);
211
- this._overwriteAlternativeVersionId(alternativeVersionId);
212
- }
213
- ));
214
- }
215
- setCellCollapseDefault(collapseConfig) {
216
- this._defaultCollapseConfig = collapseConfig;
217
- }
218
- _initialize(cells, triggerDirty) {
219
- this._cells = [];
220
- this._versionId = 0;
221
- this._notebookSpecificAlternativeId = 0;
222
- const mainCells = ( cells.map(cell => {
223
- const cellHandle = this._cellhandlePool++;
224
- const cellUri = CellUri.generate(this.uri, cellHandle);
225
- const collapseState = this._getDefaultCollapseState(cell);
226
- return ( new NotebookCellTextModel(
227
- cellUri,
228
- cellHandle,
229
- cell.source,
230
- cell.language,
231
- cell.mime,
232
- cell.cellKind,
233
- cell.outputs,
234
- cell.metadata,
235
- cell.internalMetadata,
236
- collapseState,
237
- this.transientOptions,
238
- this._languageService
239
- ));
240
- }));
241
- for (let i = 0; i < mainCells.length; i++) {
242
- const dirtyStateListener = mainCells[i].onDidChangeContent((e) => {
243
- this._bindCellContentHandler(mainCells[i], e);
244
- });
245
- this._cellListeners.set(mainCells[i].handle, dirtyStateListener);
246
- this._register(mainCells[i]);
247
- }
248
- this._cells.splice(0, 0, ...mainCells);
249
- this._alternativeVersionId = this._generateAlternativeId();
250
- if (triggerDirty) {
251
- this._pauseableEmitter.fire({
252
- rawEvents: [{ kind: NotebookCellsChangeType.Unknown, transient: false }],
253
- versionId: this.versionId,
254
- synchronous: true,
255
- endSelectionState: undefined
256
- });
257
- }
258
- }
259
- _bindCellContentHandler(cell, e) {
260
- this._increaseVersionId(e === 'content');
261
- switch (e) {
262
- case 'content':
263
- this._pauseableEmitter.fire({
264
- rawEvents: [{ kind: NotebookCellsChangeType.ChangeCellContent, index: this._getCellIndexByHandle(cell.handle), transient: false }],
265
- versionId: this.versionId,
266
- synchronous: true,
267
- endSelectionState: undefined
268
- });
269
- break;
270
- case 'language':
271
- this._pauseableEmitter.fire({
272
- rawEvents: [{ kind: NotebookCellsChangeType.ChangeCellLanguage, index: this._getCellIndexByHandle(cell.handle), language: cell.language, transient: false }],
273
- versionId: this.versionId,
274
- synchronous: true,
275
- endSelectionState: undefined
276
- });
277
- break;
278
- case 'mime':
279
- this._pauseableEmitter.fire({
280
- rawEvents: [{ kind: NotebookCellsChangeType.ChangeCellMime, index: this._getCellIndexByHandle(cell.handle), mime: cell.mime, transient: false }],
281
- versionId: this.versionId,
282
- synchronous: true,
283
- endSelectionState: undefined
284
- });
285
- break;
286
- }
287
- }
288
- _generateAlternativeId() {
289
- return `${this._notebookSpecificAlternativeId}_` + ( this.cells.map(cell => cell.handle + ',' + cell.alternativeId)).join(';');
290
- }
291
- dispose() {
292
- if (this._isDisposed) {
293
- return;
294
- }
295
- this._isDisposed = true;
296
- this._onWillDispose.fire();
297
- this._undoService.removeElements(this.uri);
298
- dispose(( this._cellListeners.values()));
299
- this._cellListeners.clear();
300
- dispose(this._cells);
301
- this._cells = [];
302
- super.dispose();
303
- }
304
- pushStackElement(label, selectionState, undoRedoGroup) {
305
- this._operationManager.pushStackElement(label, selectionState, undoRedoGroup, this.alternativeVersionId);
306
- }
307
- _getCellIndexByHandle(handle) {
308
- return this.cells.findIndex(c => c.handle === handle);
309
- }
310
- _getCellIndexWithOutputIdHandleFromEdits(outputId, rawEdits) {
311
- const edit = rawEdits.find(e => 'outputs' in e && ( e.outputs.some(o => o.outputId === outputId)));
312
- if (edit) {
313
- if ('index' in edit) {
314
- return edit.index;
315
- }
316
- else if ('handle' in edit) {
317
- const cellIndex = this._getCellIndexByHandle(edit.handle);
318
- this._assertIndex(cellIndex);
319
- return cellIndex;
320
- }
321
- }
322
- return -1;
323
- }
324
- _getCellIndexWithOutputIdHandle(outputId) {
325
- return this.cells.findIndex(c => !!c.outputs.find(o => o.outputId === outputId));
326
- }
327
- reset(cells, metadata, transientOptions) {
328
- this.transientOptions = transientOptions;
329
- const edits = NotebookTextModel_1.computeEdits(this, cells);
330
- this.applyEdits([
331
- ...edits,
332
- { editType: 5 , metadata }
333
- ], true, undefined, () => undefined, undefined, false);
334
- }
335
- static computeEdits(model, cells) {
336
- const edits = [];
337
- const commonPrefix = this._commonPrefix(model.cells, model.cells.length, 0, cells, cells.length, 0);
338
- if (commonPrefix > 0) {
339
- for (let i = 0; i < commonPrefix; i++) {
340
- edits.push({
341
- editType: 3 ,
342
- index: i,
343
- metadata: cells[i].metadata ?? {}
344
- }, ...this._computeOutputEdit(i, model.cells[i].outputs, cells[i].outputs));
345
- }
346
- }
347
- if (model.cells.length === cells.length && commonPrefix === model.cells.length) {
348
- return edits;
349
- }
350
- const commonSuffix = this._commonSuffix(model.cells, model.cells.length - commonPrefix, commonPrefix, cells, cells.length - commonPrefix, commonPrefix);
351
- if (commonSuffix > 0) {
352
- edits.push({ editType: 1 , index: commonPrefix, count: model.cells.length - commonPrefix - commonSuffix, cells: cells.slice(commonPrefix, cells.length - commonSuffix) });
353
- }
354
- else if (commonPrefix > 0) {
355
- edits.push({ editType: 1 , index: commonPrefix, count: model.cells.length - commonPrefix, cells: cells.slice(commonPrefix) });
356
- }
357
- else {
358
- edits.push({ editType: 1 , index: 0, count: model.cells.length, cells });
359
- }
360
- if (commonSuffix > 0) {
361
- for (let i = commonSuffix; i > 0; i--) {
362
- edits.push({
363
- editType: 3 ,
364
- index: model.cells.length - i,
365
- metadata: cells[cells.length - i].metadata ?? {}
366
- }, ...this._computeOutputEdit(model.cells.length - i, model.cells[model.cells.length - i].outputs, cells[cells.length - i].outputs));
367
- }
368
- }
369
- return edits;
370
- }
371
- static _computeOutputEdit(index, a, b) {
372
- if (a.length !== b.length) {
373
- return [
374
- {
375
- editType: 2 ,
376
- index: index,
377
- outputs: b,
378
- append: false
379
- }
380
- ];
381
- }
382
- if (a.length === 0) {
383
- return [];
384
- }
385
- return ( b.map((output, i) => {
386
- return {
387
- editType: 7 ,
388
- outputId: a[i].outputId,
389
- items: output.outputs,
390
- append: false
391
- };
392
- }));
393
- }
394
- static _commonPrefix(a, aLen, aDelta, b, bLen, bDelta) {
395
- const maxResult = Math.min(aLen, bLen);
396
- let result = 0;
397
- for (let i = 0; i < maxResult && a[aDelta + i].fastEqual(b[bDelta + i]); i++) {
398
- result++;
399
- }
400
- return result;
401
- }
402
- static _commonSuffix(a, aLen, aDelta, b, bLen, bDelta) {
403
- const maxResult = Math.min(aLen, bLen);
404
- let result = 0;
405
- for (let i = 0; i < maxResult && a[aDelta + aLen - i - 1].fastEqual(b[bDelta + bLen - i - 1]); i++) {
406
- result++;
407
- }
408
- return result;
409
- }
410
- applyEdits(rawEdits, synchronous, beginSelectionState, endSelectionsComputer, undoRedoGroup, computeUndoRedo) {
411
- this._pauseableEmitter.pause();
412
- this.pushStackElement('edit', beginSelectionState, undoRedoGroup);
413
- try {
414
- this._doApplyEdits(rawEdits, synchronous, computeUndoRedo);
415
- return true;
416
- }
417
- finally {
418
- const endSelections = endSelectionsComputer();
419
- this._increaseVersionId(this._operationManager.isUndoStackEmpty() && !this._pauseableEmitter.isDirtyEvent());
420
- this.pushStackElement('edit', endSelections, undefined);
421
- this._pauseableEmitter.fire({ rawEvents: [], versionId: this.versionId, synchronous: synchronous, endSelectionState: endSelections });
422
- this._pauseableEmitter.resume();
423
- }
424
- }
425
- _doApplyEdits(rawEdits, synchronous, computeUndoRedo) {
426
- const editsWithDetails = ( rawEdits.map((edit, index) => {
427
- let cellIndex = -1;
428
- if ('index' in edit) {
429
- cellIndex = edit.index;
430
- }
431
- else if ('handle' in edit) {
432
- cellIndex = this._getCellIndexByHandle(edit.handle);
433
- this._assertIndex(cellIndex);
434
- }
435
- else if ('outputId' in edit) {
436
- cellIndex = this._getCellIndexWithOutputIdHandle(edit.outputId);
437
- if (this._indexIsInvalid(cellIndex)) {
438
- cellIndex = this._getCellIndexWithOutputIdHandleFromEdits(edit.outputId, rawEdits.slice(0, index));
439
- }
440
- if (this._indexIsInvalid(cellIndex)) {
441
- return null;
442
- }
443
- }
444
- else if (edit.editType !== 5 ) {
445
- throw new Error('Invalid cell edit');
446
- }
447
- return {
448
- edit,
449
- cellIndex,
450
- end: ((edit.editType === 5) )
451
- ? undefined
452
- : (edit.editType === 1 ? edit.index + edit.count : cellIndex),
453
- originalIndex: index
454
- };
455
- })).filter(isDefined);
456
- const edits = ( this._mergeCellEdits(editsWithDetails)
457
- .sort((a, b) => {
458
- if (a.end === undefined) {
459
- return -1;
460
- }
461
- if (b.end === undefined) {
462
- return -1;
463
- }
464
- return b.end - a.end || b.originalIndex - a.originalIndex;
465
- }).reduce((prev, curr) => {
466
- if (!prev.length) {
467
- prev.push([curr]);
468
- }
469
- else {
470
- const last = prev[prev.length - 1];
471
- const index = last[0].cellIndex;
472
- if (curr.cellIndex === index) {
473
- last.push(curr);
474
- }
475
- else {
476
- prev.push([curr]);
477
- }
478
- }
479
- return prev;
480
- }, []).map(editsOnSameIndex => {
481
- const replaceEdits = [];
482
- const otherEdits = [];
483
- editsOnSameIndex.forEach(edit => {
484
- if (edit.edit.editType === 1 ) {
485
- replaceEdits.push(edit);
486
- }
487
- else {
488
- otherEdits.push(edit);
489
- }
490
- });
491
- return [...otherEdits.reverse(), ...replaceEdits];
492
- }));
493
- const flattenEdits = edits.flat();
494
- for (const { edit, cellIndex } of flattenEdits) {
495
- switch (edit.editType) {
496
- case 1 :
497
- this._replaceCells(edit.index, edit.count, edit.cells, synchronous, computeUndoRedo);
498
- break;
499
- case 2 : {
500
- this._assertIndex(cellIndex);
501
- const cell = this._cells[cellIndex];
502
- if (edit.append) {
503
- this._spliceNotebookCellOutputs(cell, { start: cell.outputs.length, deleteCount: 0, newOutputs: ( edit.outputs.map(op => ( new NotebookCellOutputTextModel(op)))) }, true, computeUndoRedo);
504
- }
505
- else {
506
- this._spliceNotebookCellOutputs2(cell, edit.outputs, computeUndoRedo);
507
- }
508
- break;
509
- }
510
- case 7 :
511
- {
512
- this._assertIndex(cellIndex);
513
- const cell = this._cells[cellIndex];
514
- if (edit.append) {
515
- this._appendNotebookCellOutputItems(cell, edit.outputId, edit.items);
516
- }
517
- else {
518
- this._replaceNotebookCellOutputItems(cell, edit.outputId, edit.items);
519
- }
520
- }
521
- break;
522
- case 3 :
523
- this._assertIndex(edit.index);
524
- this._changeCellMetadata(this._cells[edit.index], edit.metadata, computeUndoRedo);
525
- break;
526
- case 8 :
527
- this._assertIndex(cellIndex);
528
- this._changeCellMetadataPartial(this._cells[cellIndex], edit.metadata, computeUndoRedo);
529
- break;
530
- case 9 :
531
- this._assertIndex(cellIndex);
532
- this._changeCellInternalMetadataPartial(this._cells[cellIndex], edit.internalMetadata);
533
- break;
534
- case 4 :
535
- this._assertIndex(edit.index);
536
- this._changeCellLanguage(this._cells[edit.index], edit.language, computeUndoRedo);
537
- break;
538
- case 5 :
539
- this._updateNotebookMetadata(edit.metadata, computeUndoRedo);
540
- break;
541
- case 6 :
542
- this._moveCellToIdx(edit.index, edit.length, edit.newIdx, synchronous, computeUndoRedo, undefined, undefined);
543
- break;
544
- }
545
- }
546
- }
547
- _mergeCellEdits(rawEdits) {
548
- const mergedEdits = [];
549
- rawEdits.forEach(edit => {
550
- if (mergedEdits.length) {
551
- const last = mergedEdits[mergedEdits.length - 1];
552
- if (last.edit.editType === 2
553
- && last.edit.append
554
- && edit.edit.editType === 2
555
- && edit.edit.append
556
- && last.cellIndex === edit.cellIndex) {
557
- last.edit.outputs = [...last.edit.outputs, ...edit.edit.outputs];
558
- }
559
- else if (last.edit.editType === 2
560
- && !last.edit.append
561
- && last.edit.outputs.length === 0
562
- && edit.edit.editType === 2
563
- && edit.edit.append
564
- && last.cellIndex === edit.cellIndex) {
565
- last.edit.append = false;
566
- last.edit.outputs = edit.edit.outputs;
567
- }
568
- else {
569
- mergedEdits.push(edit);
570
- }
571
- }
572
- else {
573
- mergedEdits.push(edit);
574
- }
575
- });
576
- return mergedEdits;
577
- }
578
- _getDefaultCollapseState(cellDto) {
579
- const defaultConfig = cellDto.cellKind === CellKind.Code ? this._defaultCollapseConfig?.codeCell : this._defaultCollapseConfig?.markupCell;
580
- return cellDto.collapseState ?? (defaultConfig ?? undefined);
581
- }
582
- _replaceCells(index, count, cellDtos, synchronous, computeUndoRedo) {
583
- if (count === 0 && cellDtos.length === 0) {
584
- return;
585
- }
586
- const oldViewCells = this._cells.slice(0);
587
- const oldSet = ( new Set());
588
- oldViewCells.forEach(cell => {
589
- oldSet.add(cell.handle);
590
- });
591
- for (let i = index; i < Math.min(index + count, this._cells.length); i++) {
592
- const cell = this._cells[i];
593
- this._cellListeners.get(cell.handle)?.dispose();
594
- this._cellListeners.delete(cell.handle);
595
- }
596
- const cells = ( cellDtos.map(cellDto => {
597
- const cellHandle = this._cellhandlePool++;
598
- const cellUri = CellUri.generate(this.uri, cellHandle);
599
- const collapseState = this._getDefaultCollapseState(cellDto);
600
- const cell = ( new NotebookCellTextModel(
601
- cellUri,
602
- cellHandle,
603
- cellDto.source,
604
- cellDto.language,
605
- cellDto.mime,
606
- cellDto.cellKind,
607
- cellDto.outputs || [],
608
- cellDto.metadata,
609
- cellDto.internalMetadata,
610
- collapseState,
611
- this.transientOptions,
612
- this._languageService
613
- ));
614
- const textModel = this._modelService.getModel(cellUri);
615
- if (textModel && textModel instanceof TextModel) {
616
- cell.textModel = textModel;
617
- cell.language = cellDto.language;
618
- cell.textModel.setValue(cellDto.source);
619
- cell.resetTextBuffer(cell.textModel.getTextBuffer());
620
- }
621
- const dirtyStateListener = cell.onDidChangeContent((e) => {
622
- this._bindCellContentHandler(cell, e);
623
- });
624
- this._cellListeners.set(cell.handle, dirtyStateListener);
625
- this._register(cell);
626
- return cell;
627
- }));
628
- const cellsCopy = this._cells.slice(0);
629
- cellsCopy.splice(index, count, ...cells);
630
- const diffs = ( diff(this._cells, cellsCopy, cell => {
631
- return ( oldSet.has(cell.handle));
632
- }).map(diff => {
633
- return [diff.start, diff.deleteCount, diff.toInsert];
634
- }));
635
- this._onWillAddRemoveCells.fire({ rawEvent: { kind: NotebookCellsChangeType.ModelChange, changes: diffs } });
636
- this._cells = cellsCopy;
637
- const undoDiff = ( diffs.map(diff => {
638
- const deletedCells = oldViewCells.slice(diff[0], diff[0] + diff[1]);
639
- return [diff[0], deletedCells, diff[2]];
640
- }));
641
- if (computeUndoRedo) {
642
- this._operationManager.pushEditOperation(( new SpliceCellsEdit(this.uri, undoDiff, {
643
- insertCell: (index, cell, endSelections) => { this._insertNewCell(index, [cell], true, endSelections); },
644
- deleteCell: (index, endSelections) => { this._removeCell(index, 1, true, endSelections); },
645
- replaceCell: (index, count, cells, endSelections) => { this._replaceNewCells(index, count, cells, true, endSelections); },
646
- }, undefined, undefined)), undefined, undefined);
647
- }
648
- this._pauseableEmitter.fire({
649
- rawEvents: [{ kind: NotebookCellsChangeType.ModelChange, changes: diffs, transient: false }],
650
- versionId: this.versionId,
651
- synchronous: synchronous,
652
- endSelectionState: undefined
653
- });
654
- }
655
- _increaseVersionId(transient) {
656
- this._versionId = this._versionId + 1;
657
- if (!transient) {
658
- this._notebookSpecificAlternativeId = this._versionId;
659
- }
660
- this._alternativeVersionId = this._generateAlternativeId();
661
- }
662
- _overwriteAlternativeVersionId(newAlternativeVersionId) {
663
- this._alternativeVersionId = newAlternativeVersionId;
664
- this._notebookSpecificAlternativeId = Number(newAlternativeVersionId.substring(0, newAlternativeVersionId.indexOf('_')));
665
- }
666
- _updateNotebookMetadata(metadata, computeUndoRedo) {
667
- const oldMetadata = this.metadata;
668
- const triggerDirtyChange = this._isDocumentMetadataChanged(this.metadata, metadata);
669
- if (triggerDirtyChange) {
670
- if (computeUndoRedo) {
671
- const that = this;
672
- this._operationManager.pushEditOperation(new (class {
673
- constructor() {
674
- this.type = 0 ;
675
- this.label = 'Update Notebook Metadata';
676
- this.code = 'undoredo.notebooks.updateCellMetadata';
677
- }
678
- get resource() {
679
- return that.uri;
680
- }
681
- undo() {
682
- that._updateNotebookMetadata(oldMetadata, false);
683
- }
684
- redo() {
685
- that._updateNotebookMetadata(metadata, false);
686
- }
687
- })(), undefined, undefined);
688
- }
689
- }
690
- this.metadata = metadata;
691
- this._pauseableEmitter.fire({
692
- rawEvents: [{ kind: NotebookCellsChangeType.ChangeDocumentMetadata, metadata: this.metadata, transient: !triggerDirtyChange }],
693
- versionId: this.versionId,
694
- synchronous: true,
695
- endSelectionState: undefined
696
- });
697
- }
698
- _insertNewCell(index, cells, synchronous, endSelections) {
699
- for (let i = 0; i < cells.length; i++) {
700
- const dirtyStateListener = cells[i].onDidChangeContent((e) => {
701
- this._bindCellContentHandler(cells[i], e);
702
- });
703
- this._cellListeners.set(cells[i].handle, dirtyStateListener);
704
- }
705
- const changes = [[index, 0, cells]];
706
- this._onWillAddRemoveCells.fire({ rawEvent: { kind: NotebookCellsChangeType.ModelChange, changes } });
707
- this._cells.splice(index, 0, ...cells);
708
- this._pauseableEmitter.fire({
709
- rawEvents: [{ kind: NotebookCellsChangeType.ModelChange, changes, transient: false }],
710
- versionId: this.versionId,
711
- synchronous: synchronous,
712
- endSelectionState: endSelections
713
- });
714
- return;
715
- }
716
- _removeCell(index, count, synchronous, endSelections) {
717
- for (let i = index; i < index + count; i++) {
718
- const cell = this._cells[i];
719
- this._cellListeners.get(cell.handle)?.dispose();
720
- this._cellListeners.delete(cell.handle);
721
- }
722
- const changes = [[index, count, []]];
723
- this._onWillAddRemoveCells.fire({ rawEvent: { kind: NotebookCellsChangeType.ModelChange, changes } });
724
- this._cells.splice(index, count);
725
- this._pauseableEmitter.fire({
726
- rawEvents: [{ kind: NotebookCellsChangeType.ModelChange, changes, transient: false }],
727
- versionId: this.versionId,
728
- synchronous: synchronous,
729
- endSelectionState: endSelections
730
- });
731
- }
732
- _replaceNewCells(index, count, cells, synchronous, endSelections) {
733
- for (let i = index; i < index + count; i++) {
734
- const cell = this._cells[i];
735
- this._cellListeners.get(cell.handle)?.dispose();
736
- this._cellListeners.delete(cell.handle);
737
- }
738
- for (let i = 0; i < cells.length; i++) {
739
- const dirtyStateListener = cells[i].onDidChangeContent((e) => {
740
- this._bindCellContentHandler(cells[i], e);
741
- });
742
- this._cellListeners.set(cells[i].handle, dirtyStateListener);
743
- }
744
- const changes = [[index, count, cells]];
745
- this._onWillAddRemoveCells.fire({ rawEvent: { kind: NotebookCellsChangeType.ModelChange, changes } });
746
- this._cells.splice(index, count, ...cells);
747
- this._pauseableEmitter.fire({
748
- rawEvents: [{ kind: NotebookCellsChangeType.ModelChange, changes, transient: false }],
749
- versionId: this.versionId,
750
- synchronous: synchronous,
751
- endSelectionState: endSelections
752
- });
753
- }
754
- _isDocumentMetadataChanged(a, b) {
755
- const keys = ( new Set([...( Object.keys(a || {})), ...( Object.keys(b || {}))]));
756
- for (const key of keys) {
757
- if (key === 'custom') {
758
- if (!this._customMetadataEqual(a[key], b[key])
759
- &&
760
- !(this.transientOptions.transientDocumentMetadata[key])) {
761
- return true;
762
- }
763
- }
764
- else if ((a[key] !== b[key])
765
- &&
766
- !(this.transientOptions.transientDocumentMetadata[key])) {
767
- return true;
768
- }
769
- }
770
- return false;
771
- }
772
- _isCellMetadataChanged(a, b) {
773
- const keys = ( new Set([...( Object.keys(a || {})), ...( Object.keys(b || {}))]));
774
- for (const key of keys) {
775
- if ((a[key] !== b[key])
776
- &&
777
- !(this.transientOptions.transientCellMetadata[key])) {
778
- return true;
779
- }
780
- }
781
- return false;
782
- }
783
- _customMetadataEqual(a, b) {
784
- if (!a && !b) {
785
- return true;
786
- }
787
- if (!a || !b) {
788
- return false;
789
- }
790
- const aProps = Object.getOwnPropertyNames(a);
791
- const bProps = Object.getOwnPropertyNames(b);
792
- if (aProps.length !== bProps.length) {
793
- return false;
794
- }
795
- for (let i = 0; i < aProps.length; i++) {
796
- const propName = aProps[i];
797
- if (a[propName] !== b[propName]) {
798
- return false;
799
- }
800
- }
801
- return true;
802
- }
803
- _changeCellMetadataPartial(cell, metadata, computeUndoRedo) {
804
- const newMetadata = {
805
- ...cell.metadata
806
- };
807
- let k;
808
- for (k in metadata) {
809
- const value = metadata[k] ?? undefined;
810
- newMetadata[k] = value;
811
- }
812
- return this._changeCellMetadata(cell, newMetadata, computeUndoRedo);
813
- }
814
- _changeCellMetadata(cell, metadata, computeUndoRedo) {
815
- const triggerDirtyChange = this._isCellMetadataChanged(cell.metadata, metadata);
816
- if (triggerDirtyChange) {
817
- if (computeUndoRedo) {
818
- const index = this._cells.indexOf(cell);
819
- this._operationManager.pushEditOperation(( new CellMetadataEdit(this.uri, index, ( Object.freeze(cell.metadata)), ( Object.freeze(metadata)), {
820
- updateCellMetadata: (index, newMetadata) => {
821
- const cell = this._cells[index];
822
- if (!cell) {
823
- return;
824
- }
825
- this._changeCellMetadata(cell, newMetadata, false);
826
- }
827
- })), undefined, undefined);
828
- }
829
- }
830
- cell.metadata = metadata;
831
- this._pauseableEmitter.fire({
832
- rawEvents: [{ kind: NotebookCellsChangeType.ChangeCellMetadata, index: this._cells.indexOf(cell), metadata: cell.metadata, transient: !triggerDirtyChange }],
833
- versionId: this.versionId,
834
- synchronous: true,
835
- endSelectionState: undefined
836
- });
837
- }
838
- _changeCellInternalMetadataPartial(cell, internalMetadata) {
839
- const newInternalMetadata = {
840
- ...cell.internalMetadata
841
- };
842
- let k;
843
- for (k in internalMetadata) {
844
- const value = internalMetadata[k] ?? undefined;
845
- newInternalMetadata[k] = value;
846
- }
847
- cell.internalMetadata = newInternalMetadata;
848
- this._pauseableEmitter.fire({
849
- rawEvents: [{ kind: NotebookCellsChangeType.ChangeCellInternalMetadata, index: this._cells.indexOf(cell), internalMetadata: cell.internalMetadata, transient: true }],
850
- versionId: this.versionId,
851
- synchronous: true,
852
- endSelectionState: undefined
853
- });
854
- }
855
- _changeCellLanguage(cell, languageId, computeUndoRedo) {
856
- if (cell.language === languageId) {
857
- return;
858
- }
859
- const oldLanguage = cell.language;
860
- cell.language = languageId;
861
- if (computeUndoRedo) {
862
- const that = this;
863
- this._operationManager.pushEditOperation(new (class {
864
- constructor() {
865
- this.type = 0 ;
866
- this.label = 'Update Cell Language';
867
- this.code = 'undoredo.notebooks.updateCellLanguage';
868
- }
869
- get resource() {
870
- return that.uri;
871
- }
872
- undo() {
873
- that._changeCellLanguage(cell, oldLanguage, false);
874
- }
875
- redo() {
876
- that._changeCellLanguage(cell, languageId, false);
877
- }
878
- })(), undefined, undefined);
879
- }
880
- this._pauseableEmitter.fire({
881
- rawEvents: [{ kind: NotebookCellsChangeType.ChangeCellLanguage, index: this._cells.indexOf(cell), language: languageId, transient: false }],
882
- versionId: this.versionId,
883
- synchronous: true,
884
- endSelectionState: undefined
885
- });
886
- }
887
- _spliceNotebookCellOutputs2(cell, outputs, computeUndoRedo) {
888
- if (outputs.length === 0 && cell.outputs.length === 0) {
889
- return;
890
- }
891
- if (outputs.length <= 1) {
892
- this._spliceNotebookCellOutputs(cell, { start: 0, deleteCount: cell.outputs.length, newOutputs: ( outputs.map(op => ( new NotebookCellOutputTextModel(op)))) }, false, computeUndoRedo);
893
- return;
894
- }
895
- const diff = ( new LcsDiff(( new OutputSequence(cell.outputs)), ( new OutputSequence(outputs))));
896
- const diffResult = diff.ComputeDiff(false);
897
- const splices = ( diffResult.changes.map(change => ({
898
- start: change.originalStart,
899
- deleteCount: change.originalLength,
900
- newOutputs: ( outputs.slice(change.modifiedStart, change.modifiedStart + change.modifiedLength).map(op => ( new NotebookCellOutputTextModel(op))))
901
- })));
902
- splices.reverse().forEach(splice => {
903
- this._spliceNotebookCellOutputs(cell, splice, false, computeUndoRedo);
904
- });
905
- }
906
- _spliceNotebookCellOutputs(cell, splice, append, computeUndoRedo) {
907
- cell.spliceNotebookCellOutputs(splice);
908
- this._pauseableEmitter.fire({
909
- rawEvents: [{
910
- kind: NotebookCellsChangeType.Output,
911
- index: this._cells.indexOf(cell),
912
- outputs: ( cell.outputs.map(output => output.asDto())) ?? [],
913
- append,
914
- transient: this.transientOptions.transientOutputs,
915
- }],
916
- versionId: this.versionId,
917
- synchronous: true,
918
- endSelectionState: undefined
919
- });
920
- }
921
- _appendNotebookCellOutputItems(cell, outputId, items) {
922
- if (cell.changeOutputItems(outputId, true, items)) {
923
- this._pauseableEmitter.fire({
924
- rawEvents: [{
925
- kind: NotebookCellsChangeType.OutputItem,
926
- index: this._cells.indexOf(cell),
927
- outputId: outputId,
928
- outputItems: items,
929
- append: true,
930
- transient: this.transientOptions.transientOutputs
931
- }],
932
- versionId: this.versionId,
933
- synchronous: true,
934
- endSelectionState: undefined
935
- });
936
- }
937
- }
938
- _replaceNotebookCellOutputItems(cell, outputId, items) {
939
- if (cell.changeOutputItems(outputId, false, items)) {
940
- this._pauseableEmitter.fire({
941
- rawEvents: [{
942
- kind: NotebookCellsChangeType.OutputItem,
943
- index: this._cells.indexOf(cell),
944
- outputId: outputId,
945
- outputItems: items,
946
- append: false,
947
- transient: this.transientOptions.transientOutputs
948
- }],
949
- versionId: this.versionId,
950
- synchronous: true,
951
- endSelectionState: undefined
952
- });
953
- }
954
- }
955
- _moveCellToIdx(index, length, newIdx, synchronous, pushedToUndoStack, beforeSelections, endSelections) {
956
- if (pushedToUndoStack) {
957
- this._operationManager.pushEditOperation(( new MoveCellEdit(this.uri, index, length, newIdx, {
958
- moveCell: (fromIndex, length, toIndex, beforeSelections, endSelections) => {
959
- this._moveCellToIdx(fromIndex, length, toIndex, true, false, beforeSelections, endSelections);
960
- },
961
- }, beforeSelections, endSelections)), beforeSelections, endSelections);
962
- }
963
- this._assertIndex(index);
964
- this._assertIndex(newIdx);
965
- const cells = this._cells.splice(index, length);
966
- this._cells.splice(newIdx, 0, ...cells);
967
- this._pauseableEmitter.fire({
968
- rawEvents: [{ kind: NotebookCellsChangeType.Move, index, length, newIdx, cells, transient: false }],
969
- versionId: this.versionId,
970
- synchronous: synchronous,
971
- endSelectionState: endSelections
972
- });
973
- return true;
974
- }
975
- _assertIndex(index) {
976
- if (this._indexIsInvalid(index)) {
977
- throw new Error(`model index out of range ${index}`);
978
- }
979
- }
980
- _indexIsInvalid(index) {
981
- return index < 0 || index >= this._cells.length;
982
- }
983
- };
984
- NotebookTextModel = NotebookTextModel_1 = ( __decorate([
985
- ( __param(5, IUndoRedoService)),
986
- ( __param(6, IModelService)),
987
- ( __param(7, ILanguageService))
988
- ], NotebookTextModel));
989
- class OutputSequence {
990
- constructor(outputs) {
991
- this.outputs = outputs;
992
- }
993
- getElements() {
994
- return ( this.outputs.map(output => {
995
- return hash(( output.outputs.map(output => ({
996
- mime: output.mime,
997
- data: output.data
998
- }))));
999
- }));
1000
- }
1001
- }
1002
-
1003
- export { NotebookTextModel };