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

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