@codingame/monaco-vscode-notebook-service-override 1.85.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/external/rollup-plugin-styles/dist/runtime/inject-css.js +3 -0
- package/external/tslib/tslib.es6.js +11 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/notebook.d.ts +5 -0
- package/notebook.js +44 -0
- package/override/vs/platform/dialogs/common/dialogs.js +8 -0
- package/package.json +32 -0
- package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.css.js +6 -0
- package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.js +387 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellCommands/cellCommands.js +668 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/contributedStatusBarItemController.js +109 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController.js +319 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/notebookVisibleCellObserver.js +58 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/statusBarProviders.js +173 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard.js +485 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookBreakpoints.js +106 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookCellPausing.js +67 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookDebugDecorations.js +165 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/editorHint/emptyCellEditorHint.js +67 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/editorStatusBar/editorStatusBar.js +238 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/execute/executionEditorProgress.js +72 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/media/notebookFind.css.js +6 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFind.js +168 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget.js +317 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/format/formatting.js +209 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/gettingStarted/notebookGettingStarted.js +87 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/kernelDetection/notebookKernelDetection.js +82 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/layout/layoutActions.js +67 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider.js +93 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/navigation/arrow.js +383 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariables.js +51 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesTree.js +46 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.js +135 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline.js +383 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/profile/notebookProfile.js +117 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants.js +511 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout.js +168 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/undoRedo/notebookUndoRedo.js +57 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/viewportWarmup/viewportWarmup.js +94 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/apiActions.js +51 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/executeActions.js +702 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/controller/layoutActions.js +268 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions.js +45 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.js +1297 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementOutputs.js +284 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.js +563 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.js +108 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/eventDispatcher.js +39 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiff.css.js +6 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.js +313 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.js +872 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.js +13 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.js +393 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffOverviewRuler.js +175 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/notebook.contribution.js +1121 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/notebookAccessibility.js +159 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/notebookExtensionPoint.js +339 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookCellStatusBarServiceImpl.js +41 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookEditorServiceImpl.js +182 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl.js +106 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionStateServiceImpl.js +509 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelHistoryServiceImpl.js +133 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl.js +342 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKeymapServiceImpl.js +111 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookLoggingServiceImpl.js +28 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookRendererMessagingServiceImpl.js +65 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.js +666 -0
- package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookWorkerServiceImpl.js +200 -0
- package/vscode/src/vs/workbench/contrib/notebook/common/model/cellEdit.js +80 -0
- package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.js +1001 -0
- package/vscode/src/vs/workbench/contrib/notebook/common/notebookDiffEditorInput.js +103 -0
- package/vscode/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverServiceImpl.js +202 -0
- package/vscode/src/vs/workbench/contrib/notebook/common/notebookOutputRenderer.js +80 -0
- package/vscode/src/vs/workbench/contrib/notebook/common/notebookProvider.js +98 -0
- package/vscode/src/vs/workbench/contrib/notebook/common/services/notebookSimpleWorker.js +217 -0
- package/vscode/src/vs/workbench/services/workingCopy/common/abstractFileWorkingCopyManager.js +89 -0
- package/vscode/src/vs/workbench/services/workingCopy/common/fileWorkingCopyManager.js +372 -0
- package/vscode/src/vs/workbench/services/workingCopy/common/storedFileWorkingCopy.js +706 -0
- package/vscode/src/vs/workbench/services/workingCopy/common/storedFileWorkingCopyManager.js +407 -0
- package/vscode/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopy.js +144 -0
- package/vscode/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopyManager.js +129 -0
- package/worker.js +1 -0
- package/workers/notebook.worker.js +9 -0
|
@@ -0,0 +1,1001 @@
|
|
|
1
|
+
import { __decorate, __param } from '../../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
+
import { Emitter, PauseableEmitter } from 'monaco-editor/esm/vs/base/common/event.js';
|
|
3
|
+
import { Disposable, dispose } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
|
|
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 'monaco-editor/esm/vs/platform/undoRedo/common/undoRedo.js';
|
|
7
|
+
import { SpliceCellsEdit, CellMetadataEdit, MoveCellEdit } from './cellEdit.js';
|
|
8
|
+
import { LcsDiff } from 'monaco-editor/esm/vs/base/common/diff/diff.js';
|
|
9
|
+
import { hash } from 'monaco-editor/esm/vs/base/common/hash.js';
|
|
10
|
+
import { NotebookCellOutputTextModel } from 'vscode/vscode/vs/workbench/contrib/notebook/common/model/notebookCellOutputTextModel';
|
|
11
|
+
import { IModelService } from 'monaco-editor/esm/vs/editor/common/services/model.js';
|
|
12
|
+
import { Schemas } from 'monaco-editor/esm/vs/base/common/network.js';
|
|
13
|
+
import { isEqual } from 'monaco-editor/esm/vs/base/common/resources.js';
|
|
14
|
+
import { ILanguageService } from 'monaco-editor/esm/vs/editor/common/languages/language.js';
|
|
15
|
+
import { TextModel } from 'monaco-editor/esm/vs/editor/common/model/textModel.js';
|
|
16
|
+
import { isDefined } from 'monaco-editor/esm/vs/base/common/types.js';
|
|
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.map(op => ( new NotebookCellOutputTextModel(op)))), 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 }, 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(
|
|
898
|
+
change => ({ start: change.originalStart, deleteCount: change.originalLength, newOutputs: outputs.slice(change.modifiedStart, change.modifiedStart + change.modifiedLength) })
|
|
899
|
+
));
|
|
900
|
+
splices.reverse().forEach(splice => {
|
|
901
|
+
this._spliceNotebookCellOutputs(cell, splice, false, computeUndoRedo);
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
_spliceNotebookCellOutputs(cell, splice, append, computeUndoRedo) {
|
|
905
|
+
cell.spliceNotebookCellOutputs(splice);
|
|
906
|
+
this._pauseableEmitter.fire({
|
|
907
|
+
rawEvents: [{
|
|
908
|
+
kind: NotebookCellsChangeType.Output,
|
|
909
|
+
index: this._cells.indexOf(cell),
|
|
910
|
+
outputs: ( cell.outputs.map(output => output.asDto())) ?? [],
|
|
911
|
+
append,
|
|
912
|
+
transient: this.transientOptions.transientOutputs,
|
|
913
|
+
}],
|
|
914
|
+
versionId: this.versionId,
|
|
915
|
+
synchronous: true,
|
|
916
|
+
endSelectionState: undefined
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
_appendNotebookCellOutputItems(cell, outputId, items) {
|
|
920
|
+
if (cell.changeOutputItems(outputId, true, items)) {
|
|
921
|
+
this._pauseableEmitter.fire({
|
|
922
|
+
rawEvents: [{
|
|
923
|
+
kind: NotebookCellsChangeType.OutputItem,
|
|
924
|
+
index: this._cells.indexOf(cell),
|
|
925
|
+
outputId: outputId,
|
|
926
|
+
outputItems: items,
|
|
927
|
+
append: true,
|
|
928
|
+
transient: this.transientOptions.transientOutputs
|
|
929
|
+
}],
|
|
930
|
+
versionId: this.versionId,
|
|
931
|
+
synchronous: true,
|
|
932
|
+
endSelectionState: undefined
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
_replaceNotebookCellOutputItems(cell, outputId, items) {
|
|
937
|
+
if (cell.changeOutputItems(outputId, false, items)) {
|
|
938
|
+
this._pauseableEmitter.fire({
|
|
939
|
+
rawEvents: [{
|
|
940
|
+
kind: NotebookCellsChangeType.OutputItem,
|
|
941
|
+
index: this._cells.indexOf(cell),
|
|
942
|
+
outputId: outputId,
|
|
943
|
+
outputItems: items,
|
|
944
|
+
append: false,
|
|
945
|
+
transient: this.transientOptions.transientOutputs
|
|
946
|
+
}],
|
|
947
|
+
versionId: this.versionId,
|
|
948
|
+
synchronous: true,
|
|
949
|
+
endSelectionState: undefined
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
_moveCellToIdx(index, length, newIdx, synchronous, pushedToUndoStack, beforeSelections, endSelections) {
|
|
954
|
+
if (pushedToUndoStack) {
|
|
955
|
+
this._operationManager.pushEditOperation(( new MoveCellEdit(this.uri, index, length, newIdx, {
|
|
956
|
+
moveCell: (fromIndex, length, toIndex, beforeSelections, endSelections) => {
|
|
957
|
+
this._moveCellToIdx(fromIndex, length, toIndex, true, false, beforeSelections, endSelections);
|
|
958
|
+
},
|
|
959
|
+
}, beforeSelections, endSelections)), beforeSelections, endSelections);
|
|
960
|
+
}
|
|
961
|
+
this._assertIndex(index);
|
|
962
|
+
this._assertIndex(newIdx);
|
|
963
|
+
const cells = this._cells.splice(index, length);
|
|
964
|
+
this._cells.splice(newIdx, 0, ...cells);
|
|
965
|
+
this._pauseableEmitter.fire({
|
|
966
|
+
rawEvents: [{ kind: NotebookCellsChangeType.Move, index, length, newIdx, cells, transient: false }],
|
|
967
|
+
versionId: this.versionId,
|
|
968
|
+
synchronous: synchronous,
|
|
969
|
+
endSelectionState: endSelections
|
|
970
|
+
});
|
|
971
|
+
return true;
|
|
972
|
+
}
|
|
973
|
+
_assertIndex(index) {
|
|
974
|
+
if (this._indexIsInvalid(index)) {
|
|
975
|
+
throw new Error(`model index out of range ${index}`);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
_indexIsInvalid(index) {
|
|
979
|
+
return index < 0 || index >= this._cells.length;
|
|
980
|
+
}
|
|
981
|
+
};
|
|
982
|
+
NotebookTextModel = NotebookTextModel_1 = ( __decorate([
|
|
983
|
+
( __param(5, IUndoRedoService)),
|
|
984
|
+
( __param(6, IModelService)),
|
|
985
|
+
( __param(7, ILanguageService))
|
|
986
|
+
], NotebookTextModel));
|
|
987
|
+
class OutputSequence {
|
|
988
|
+
constructor(outputs) {
|
|
989
|
+
this.outputs = outputs;
|
|
990
|
+
}
|
|
991
|
+
getElements() {
|
|
992
|
+
return ( this.outputs.map(output => {
|
|
993
|
+
return hash(( output.outputs.map(output => ({
|
|
994
|
+
mime: output.mime,
|
|
995
|
+
data: output.data
|
|
996
|
+
}))));
|
|
997
|
+
}));
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
export { NotebookTextModel };
|