@codingame/monaco-vscode-api 33.0.3 → 33.0.4

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 (52) hide show
  1. package/package.json +9 -9
  2. package/services.js +3 -3
  3. package/vscode/src/vs/platform/product/common/product.js +1 -1
  4. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/cellOperations.d.ts +0 -26
  5. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/cellOperations.js +0 -746
  6. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/insertCellActions.d.ts +0 -13
  7. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/insertCellActions.js +0 -300
  8. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions.d.ts +0 -8
  9. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions.js +0 -55
  10. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.d.ts +0 -273
  11. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.js +0 -1963
  12. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementOutputs.d.ts +0 -50
  13. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementOutputs.js +0 -314
  14. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.d.ts +0 -258
  15. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.js +0 -886
  16. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.d.ts +0 -41
  17. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.js +0 -118
  18. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/editorHeightCalculator.d.ts +0 -17
  19. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/editorHeightCalculator.js +0 -71
  20. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/eventDispatcher.d.ts +0 -27
  21. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/eventDispatcher.js +0 -40
  22. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookCellDiffDecorator.d.ts +0 -23
  23. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookCellDiffDecorator.js +0 -313
  24. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookDeletedCellDecorator.d.ts +0 -51
  25. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookDeletedCellDecorator.js +0 -265
  26. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInlineDiff.d.ts +0 -24
  27. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInlineDiff.js +0 -185
  28. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInlineDiffWidget.d.ts +0 -28
  29. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInlineDiffWidget.js +0 -104
  30. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInsertedCellDecorator.d.ts +0 -10
  31. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookInsertedCellDecorator.js +0 -43
  32. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookOriginalCellModelFactory.d.ts +0 -21
  33. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookOriginalCellModelFactory.js +0 -41
  34. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookOriginalModelRefFactory.d.ts +0 -25
  35. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/inlineDiff/notebookOriginalModelRefFactory.js +0 -69
  36. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiff.css +0 -469
  37. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.d.ts +0 -149
  38. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.js +0 -933
  39. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.d.ts +0 -180
  40. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.js +0 -32
  41. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.d.ts +0 -102
  42. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.js +0 -643
  43. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffOverviewRuler.d.ts +0 -30
  44. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffOverviewRuler.js +0 -197
  45. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffViewModel.d.ts +0 -75
  46. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffViewModel.js +0 -539
  47. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/unchangedEditorRegions.d.ts +0 -13
  48. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/unchangedEditorRegions.js +0 -39
  49. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookMetadataTextModel.d.ts +0 -19
  50. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookMetadataTextModel.js +0 -90
  51. package/vscode/src/vs/workbench/contrib/notebook/common/notebookDiff.d.ts +0 -26
  52. package/vscode/src/vs/workbench/contrib/notebook/common/notebookDiff.js +0 -92
@@ -1,1963 +0,0 @@
1
-
2
- import { __decorate, __param } from '../../../../../../../../external/tslib/tslib.es6.js';
3
- import { addDisposableListener, append, $, reset, scheduleAtNextAnimationFrame, getWindow, h } from '../../../../../base/browser/dom.js';
4
- import { Disposable, DisposableStore } from '../../../../../base/common/lifecycle.js';
5
- import { Schemas } from '../../../../../base/common/network.js';
6
- import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';
7
- import { PropertyFoldingState, NotebookDocumentMetadataViewModel, SideBySideDiffElementViewModel, getFormattedOutputJSON, OUTPUT_EDITOR_HEIGHT_MAGIC, OutputComparison, outputEqual } from './diffElementViewModel.js';
8
- import { NOTEBOOK_DIFF_CELL_PROPERTY, NOTEBOOK_DIFF_CELL_PROPERTY_EXPANDED, DIFF_CELL_MARGIN, NOTEBOOK_DIFF_METADATA, DiffSide, NOTEBOOK_DIFF_CELL_INPUT, NOTEBOOK_DIFF_CELL_IGNORE_WHITESPACE } from './notebookDiffEditorBrowser.js';
9
- import { CodeEditorWidget } from '../../../../../editor/browser/widget/codeEditor/codeEditorWidget.js';
10
- import { IModelService } from '../../../../../editor/common/services/model.service.js';
11
- import { ILanguageService } from '../../../../../editor/common/languages/language.service.js';
12
- import { CellEditType, CellUri } from '../../common/notebookCommon.js';
13
- import { IContextMenuService } from '../../../../../platform/contextview/browser/contextView.service.js';
14
- import { MenuItemAction, MenuId } from '../../../../../platform/actions/common/actions.js';
15
- import { IMenuService } from '../../../../../platform/actions/common/actions.service.js';
16
- import { IKeybindingService } from '../../../../../platform/keybinding/common/keybinding.service.js';
17
- import { INotificationService } from '../../../../../platform/notification/common/notification.service.js';
18
- import { getFlatActionBarActions } from '../../../../../platform/actions/browser/menuEntryActionViewItem.js';
19
- import { IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.service.js';
20
- import { CodiconActionViewItem } from '../view/cellParts/cellActionView.js';
21
- import { collapsedIcon, expandedIcon } from '../notebookIcons.js';
22
- import { OutputContainer } from './diffElementOutputs.js';
23
- import { EditorExtensionsRegistry } from '../../../../../editor/browser/editorExtensions.js';
24
- import { ContextMenuController } from '../../../../../editor/contrib/contextmenu/browser/contextmenu.js';
25
- import { SnippetController2 } from '../../../../../editor/contrib/snippet/browser/snippetController2.js';
26
- import { SuggestController } from '../../../../../editor/contrib/suggest/browser/suggestController.js';
27
- import { MenuPreventer } from '../../../codeEditor/browser/menuPreventer.js';
28
- import { SelectionClipboardContributionID } from '../../../codeEditor/browser/selectionClipboard.js';
29
- import { TabCompletionController } from '../../../snippets/browser/tabCompletion.js';
30
- import { renderIcon, renderLabelWithIcons } from '../../../../../base/browser/ui/iconLabel/iconLabels.js';
31
- import { ITextModelService } from '../../../../../editor/common/services/resolverService.service.js';
32
- import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.service.js';
33
- import { IThemeService } from '../../../../../platform/theme/common/themeService.service.js';
34
- import { WorkbenchToolBar } from '../../../../../platform/actions/browser/toolbar.js';
35
- import { ITelemetryService } from '../../../../../platform/telemetry/common/telemetry.service.js';
36
- import { getEditorPadding, fixedDiffEditorOptions, fixedEditorOptions } from './diffCellEditorOptions.js';
37
- import { AccessibilityVerbositySettingId } from '../../../accessibility/browser/accessibilityConfiguration.js';
38
- import { IAccessibilityService } from '../../../../../platform/accessibility/common/accessibility.service.js';
39
- import { DiffEditorWidget } from '../../../../../editor/browser/widget/diffEditor/diffEditorWidget.js';
40
- import { ICommandService } from '../../../../../platform/commands/common/commands.service.js';
41
- import { localize } from '../../../../../nls.js';
42
- import { Emitter } from '../../../../../base/common/event.js';
43
- import { ITextResourceConfigurationService } from '../../../../../editor/common/services/textResourceConfiguration.service.js';
44
- import { getFormattedMetadataJSON } from '../../common/model/notebookCellTextModel.js';
45
- import { getUnchangedRegionSettings } from './unchangedEditorRegions.js';
46
-
47
- function getOptimizedNestedCodeEditorWidgetOptions() {
48
- return {
49
- isSimpleWidget: false,
50
- contributions: EditorExtensionsRegistry.getSomeEditorContributions([
51
- MenuPreventer.ID,
52
- SelectionClipboardContributionID,
53
- ContextMenuController.ID,
54
- SuggestController.ID,
55
- SnippetController2.ID,
56
- TabCompletionController.ID
57
- ])
58
- };
59
- }
60
- class CellDiffPlaceholderElement extends Disposable {
61
- constructor(placeholder, templateData) {
62
- super();
63
- templateData.body.classList.remove("left", "right", "full");
64
- const text = (placeholder.hiddenCells.length === 1) ? ( localize(11788, "{0} hidden cell", placeholder.hiddenCells.length)) : ( localize(11789, "{0} hidden cells", placeholder.hiddenCells.length));
65
- templateData.placeholder.innerText = text;
66
- this._register(addDisposableListener(templateData.placeholder, "dblclick", e => {
67
- if (e.button !== 0) {
68
- return;
69
- }
70
- e.preventDefault();
71
- placeholder.showHiddenCells();
72
- }));
73
- this._register(templateData.marginOverlay.onAction(() => placeholder.showHiddenCells()));
74
- templateData.marginOverlay.show();
75
- }
76
- }
77
- let PropertyHeader = class PropertyHeader extends Disposable {
78
- constructor(
79
- cell,
80
- propertyHeaderContainer,
81
- notebookEditor,
82
- accessor,
83
- contextMenuService,
84
- keybindingService,
85
- commandService,
86
- notificationService,
87
- menuService,
88
- contextKeyService,
89
- themeService,
90
- telemetryService,
91
- accessibilityService
92
- ) {
93
- super();
94
- this.cell = cell;
95
- this.propertyHeaderContainer = propertyHeaderContainer;
96
- this.notebookEditor = notebookEditor;
97
- this.accessor = accessor;
98
- this.contextMenuService = contextMenuService;
99
- this.keybindingService = keybindingService;
100
- this.commandService = commandService;
101
- this.notificationService = notificationService;
102
- this.menuService = menuService;
103
- this.contextKeyService = contextKeyService;
104
- this.themeService = themeService;
105
- this.telemetryService = telemetryService;
106
- this.accessibilityService = accessibilityService;
107
- }
108
- buildHeader() {
109
- this._foldingIndicator = append(this.propertyHeaderContainer, $(".property-folding-indicator"));
110
- this._foldingIndicator.classList.add(this.accessor.prefix);
111
- const metadataStatus = append(this.propertyHeaderContainer, $("div.property-status"));
112
- this._statusSpan = append(metadataStatus, $("span"));
113
- this._description = append(metadataStatus, $("span.property-description"));
114
- const cellToolbarContainer = append(this.propertyHeaderContainer, $("div.property-toolbar"));
115
- this._toolbar = this._register(( new WorkbenchToolBar(cellToolbarContainer, {
116
- actionViewItemProvider: (action, options) => {
117
- if (action instanceof MenuItemAction) {
118
- const item = ( new CodiconActionViewItem(action, {
119
- hoverDelegate: options.hoverDelegate
120
- }, this.keybindingService, this.notificationService, this.contextKeyService, this.themeService, this.contextMenuService, this.accessibilityService));
121
- return item;
122
- }
123
- return undefined;
124
- }
125
- }, this.menuService, this.contextKeyService, this.contextMenuService, this.keybindingService, this.commandService, this.telemetryService)));
126
- this._toolbar.context = this.cell;
127
- const scopedContextKeyService = this.contextKeyService.createScoped(cellToolbarContainer);
128
- this._register(scopedContextKeyService);
129
- this._propertyChanged = NOTEBOOK_DIFF_CELL_PROPERTY.bindTo(scopedContextKeyService);
130
- this._propertyExpanded = NOTEBOOK_DIFF_CELL_PROPERTY_EXPANDED.bindTo(scopedContextKeyService);
131
- this._menu = this._register(this.menuService.createMenu(this.accessor.menuId, scopedContextKeyService));
132
- this._register(this._menu.onDidChange(() => this.updateMenu()));
133
- this._register(this.notebookEditor.onMouseUp(e => {
134
- if (!e.event.target || e.target !== this.cell) {
135
- return;
136
- }
137
- const target = e.event.target;
138
- if (target === this.propertyHeaderContainer || target === this._foldingIndicator || this._foldingIndicator.contains(target) || target === metadataStatus || metadataStatus.contains(target)) {
139
- const oldFoldingState = this.accessor.getFoldingState();
140
- this.accessor.updateFoldingState(
141
- oldFoldingState === PropertyFoldingState.Expanded ? PropertyFoldingState.Collapsed : PropertyFoldingState.Expanded
142
- );
143
- this._updateFoldingIcon();
144
- this.accessor.updateInfoRendering(this.cell.renderOutput);
145
- }
146
- }));
147
- this.refresh();
148
- this.accessor.updateInfoRendering(this.cell.renderOutput);
149
- }
150
- refresh() {
151
- this.updateMenu();
152
- this._updateFoldingIcon();
153
- const metadataChanged = this.accessor.checkIfModified();
154
- if (this._propertyChanged) {
155
- this._propertyChanged.set(!!metadataChanged);
156
- }
157
- if (metadataChanged) {
158
- this._statusSpan.textContent = this.accessor.changedLabel;
159
- this._statusSpan.style.fontWeight = "bold";
160
- if (metadataChanged.reason) {
161
- this._description.textContent = metadataChanged.reason;
162
- }
163
- this.propertyHeaderContainer.classList.add("modified");
164
- } else {
165
- this._statusSpan.textContent = this.accessor.unChangedLabel;
166
- this._statusSpan.style.fontWeight = "normal";
167
- this._description.textContent = "";
168
- this.propertyHeaderContainer.classList.remove("modified");
169
- }
170
- }
171
- updateMenu() {
172
- const metadataChanged = this.accessor.checkIfModified();
173
- if (metadataChanged) {
174
- const actions = getFlatActionBarActions(this._menu.getActions({
175
- shouldForwardArgs: true
176
- }));
177
- this._toolbar.setActions(actions);
178
- } else {
179
- this._toolbar.setActions([]);
180
- }
181
- }
182
- _updateFoldingIcon() {
183
- if (this.accessor.getFoldingState() === PropertyFoldingState.Collapsed) {
184
- reset(this._foldingIndicator, renderIcon(collapsedIcon));
185
- this._propertyExpanded?.set(false);
186
- } else {
187
- reset(this._foldingIndicator, renderIcon(expandedIcon));
188
- this._propertyExpanded?.set(true);
189
- }
190
- }
191
- };
192
- PropertyHeader = ( __decorate([( __param(4, IContextMenuService)), ( __param(5, IKeybindingService)), ( __param(6, ICommandService)), ( __param(7, INotificationService)), ( __param(8, IMenuService)), ( __param(9, IContextKeyService)), ( __param(10, IThemeService)), ( __param(11, ITelemetryService)), ( __param(12, IAccessibilityService))], PropertyHeader));
193
- let NotebookDocumentMetadataElement = class NotebookDocumentMetadataElement extends Disposable {
194
- constructor(
195
- notebookEditor,
196
- viewModel,
197
- templateData,
198
- instantiationService,
199
- textModelService,
200
- menuService,
201
- contextKeyService,
202
- textConfigurationService,
203
- configurationService
204
- ) {
205
- super();
206
- this.notebookEditor = notebookEditor;
207
- this.viewModel = viewModel;
208
- this.templateData = templateData;
209
- this.instantiationService = instantiationService;
210
- this.textModelService = textModelService;
211
- this.menuService = menuService;
212
- this.contextKeyService = contextKeyService;
213
- this.textConfigurationService = textConfigurationService;
214
- this.configurationService = configurationService;
215
- this._editor = templateData.sourceEditor;
216
- this._cellHeaderContainer = this.templateData.cellHeaderContainer;
217
- this._editorContainer = this.templateData.editorContainer;
218
- this._diffEditorContainer = this.templateData.diffEditorContainer;
219
- this._editorViewStateChanged = false;
220
- this._register(viewModel.onDidLayoutChange(e => {
221
- this.layout(e);
222
- this.updateBorders();
223
- }));
224
- this.buildBody();
225
- this.updateBorders();
226
- }
227
- buildBody() {
228
- const body = this.templateData.body;
229
- body.classList.remove("full");
230
- body.classList.add("full");
231
- this.updateSourceEditor();
232
- if (this.viewModel instanceof NotebookDocumentMetadataViewModel) {
233
- this._register(this.viewModel.modifiedMetadata.onDidChange(e => {
234
- this._cellHeader.refresh();
235
- }));
236
- }
237
- }
238
- layoutNotebookCell() {
239
- this.notebookEditor.layoutNotebookCell(this.viewModel, this.viewModel.layoutInfo.totalHeight);
240
- }
241
- updateBorders() {
242
- this.templateData.leftBorder.style.height = `${this.viewModel.layoutInfo.totalHeight - 32}px`;
243
- this.templateData.rightBorder.style.height = `${this.viewModel.layoutInfo.totalHeight - 32}px`;
244
- this.templateData.bottomBorder.style.top = `${this.viewModel.layoutInfo.totalHeight - 32}px`;
245
- }
246
- updateSourceEditor() {
247
- this._cellHeaderContainer.style.display = "flex";
248
- this._cellHeaderContainer.innerText = "";
249
- this._editorContainer.classList.add("diff");
250
- const updateSourceEditor = () => {
251
- if (this.viewModel.cellFoldingState === PropertyFoldingState.Collapsed) {
252
- this._editorContainer.style.display = "none";
253
- this.viewModel.editorHeight = 0;
254
- return;
255
- }
256
- const lineHeight = this.notebookEditor.getLayoutInfo().fontInfo.lineHeight || 17;
257
- const editorHeight = this.viewModel.layoutInfo.editorHeight !== 0 ? this.viewModel.layoutInfo.editorHeight : this.viewModel.computeInputEditorHeight(lineHeight);
258
- this._editorContainer.style.height = `${editorHeight}px`;
259
- this._editorContainer.style.display = "block";
260
- const contentHeight = this._editor.getContentHeight();
261
- if (contentHeight >= 0) {
262
- this.viewModel.editorHeight = contentHeight;
263
- }
264
- return editorHeight;
265
- };
266
- const renderSourceEditor = () => {
267
- const editorHeight = updateSourceEditor();
268
- if (!editorHeight) {
269
- return;
270
- }
271
- const lineCount = this.viewModel.modifiedMetadata.textBuffer.getLineCount();
272
- const options = {
273
- padding: getEditorPadding(lineCount)
274
- };
275
- const unchangedRegions = this._register(getUnchangedRegionSettings(this.configurationService));
276
- if (unchangedRegions.options.enabled) {
277
- options.hideUnchangedRegions = unchangedRegions.options;
278
- }
279
- this._editor.updateOptions(options);
280
- this._register(unchangedRegions.onDidChangeEnablement(() => {
281
- options.hideUnchangedRegions = unchangedRegions.options;
282
- this._editor.updateOptions(options);
283
- }));
284
- this._editor.layout({
285
- width: this.notebookEditor.getLayoutInfo().width - 2 * DIFF_CELL_MARGIN,
286
- height: editorHeight
287
- });
288
- this._register(this._editor.onDidContentSizeChange(e => {
289
- if (this.viewModel.cellFoldingState === PropertyFoldingState.Expanded && e.contentHeightChanged && this.viewModel.layoutInfo.editorHeight !== e.contentHeight) {
290
- this.viewModel.editorHeight = e.contentHeight;
291
- }
292
- }));
293
- this._initializeSourceDiffEditor();
294
- };
295
- this._cellHeader = this._register(this.instantiationService.createInstance(
296
- PropertyHeader,
297
- this.viewModel,
298
- this._cellHeaderContainer,
299
- this.notebookEditor,
300
- {
301
- updateInfoRendering: () => renderSourceEditor(),
302
- checkIfModified: () => {
303
- return this.viewModel.originalMetadata.getHash() !== this.viewModel.modifiedMetadata.getHash() ? {
304
- reason: undefined
305
- } : false;
306
- },
307
- getFoldingState: () => this.viewModel.cellFoldingState,
308
- updateFoldingState: state => this.viewModel.cellFoldingState = state,
309
- unChangedLabel: "Notebook Metadata",
310
- changedLabel: "Notebook Metadata changed",
311
- prefix: "metadata",
312
- menuId: MenuId.NotebookDiffDocumentMetadata
313
- }
314
- ));
315
- this._cellHeader.buildHeader();
316
- renderSourceEditor();
317
- const scopedContextKeyService = this.contextKeyService.createScoped(this.templateData.inputToolbarContainer);
318
- this._register(scopedContextKeyService);
319
- const inputChanged = NOTEBOOK_DIFF_METADATA.bindTo(scopedContextKeyService);
320
- inputChanged.set(
321
- this.viewModel.originalMetadata.getHash() !== this.viewModel.modifiedMetadata.getHash()
322
- );
323
- this._toolbar = this.templateData.toolbar;
324
- this._toolbar.context = this.viewModel;
325
- const refreshToolbar = () => {
326
- const hasChanges = this.viewModel.originalMetadata.getHash() !== this.viewModel.modifiedMetadata.getHash();
327
- inputChanged.set(hasChanges);
328
- if (hasChanges) {
329
- const menu = this.menuService.getMenuActions(MenuId.NotebookDiffDocumentMetadata, scopedContextKeyService, {
330
- shouldForwardArgs: true
331
- });
332
- const actions = getFlatActionBarActions(menu);
333
- this._toolbar.setActions(actions);
334
- } else {
335
- this._toolbar.setActions([]);
336
- }
337
- };
338
- this._register(this.viewModel.modifiedMetadata.onDidChange(() => {
339
- refreshToolbar();
340
- }));
341
- refreshToolbar();
342
- }
343
- async _initializeSourceDiffEditor() {
344
- const [originalRef, modifiedRef] = await Promise.all([
345
- this.textModelService.createModelReference(this.viewModel.originalMetadata.uri),
346
- this.textModelService.createModelReference(this.viewModel.modifiedMetadata.uri)
347
- ]);
348
- if (this._store.isDisposed) {
349
- originalRef.dispose();
350
- modifiedRef.dispose();
351
- return;
352
- }
353
- this._register(originalRef);
354
- this._register(modifiedRef);
355
- const vm = this._register(this._editor.createViewModel({
356
- original: originalRef.object.textEditorModel,
357
- modified: modifiedRef.object.textEditorModel
358
- }));
359
- await vm.waitForDiff();
360
- this._editor.setModel(vm);
361
- const handleViewStateChange = () => {
362
- this._editorViewStateChanged = true;
363
- };
364
- const handleScrollChange = e => {
365
- if (e.scrollTopChanged || e.scrollLeftChanged) {
366
- this._editorViewStateChanged = true;
367
- }
368
- };
369
- this.updateEditorOptionsForWhitespace();
370
- this._register(
371
- this._editor.getOriginalEditor().onDidChangeCursorSelection(handleViewStateChange)
372
- );
373
- this._register(this._editor.getOriginalEditor().onDidScrollChange(handleScrollChange));
374
- this._register(
375
- this._editor.getModifiedEditor().onDidChangeCursorSelection(handleViewStateChange)
376
- );
377
- this._register(this._editor.getModifiedEditor().onDidScrollChange(handleScrollChange));
378
- const editorViewState = this.viewModel.getSourceEditorViewState();
379
- if (editorViewState) {
380
- this._editor.restoreViewState(editorViewState);
381
- }
382
- const contentHeight = this._editor.getContentHeight();
383
- this.viewModel.editorHeight = contentHeight;
384
- }
385
- updateEditorOptionsForWhitespace() {
386
- const editor = this._editor;
387
- const uri = editor.getModel()?.modified.uri || editor.getModel()?.original.uri;
388
- if (!uri) {
389
- return;
390
- }
391
- const ignoreTrimWhitespace = this.textConfigurationService.getValue(uri, "diffEditor.ignoreTrimWhitespace");
392
- editor.updateOptions({
393
- ignoreTrimWhitespace
394
- });
395
- this._register(this.textConfigurationService.onDidChangeConfiguration(e => {
396
- if (e.affectsConfiguration(uri, "diffEditor") && ( e.affectedKeys.has("diffEditor.ignoreTrimWhitespace"))) {
397
- const ignoreTrimWhitespace = this.textConfigurationService.getValue(uri, "diffEditor.ignoreTrimWhitespace");
398
- editor.updateOptions({
399
- ignoreTrimWhitespace
400
- });
401
- }
402
- }));
403
- }
404
- layout(state) {
405
- scheduleAtNextAnimationFrame(getWindow(this._diffEditorContainer), () => {
406
- if (state.editorHeight) {
407
- this._editorContainer.style.height = `${this.viewModel.layoutInfo.editorHeight}px`;
408
- this._editor.layout({
409
- width: this._editor.getViewWidth(),
410
- height: this.viewModel.layoutInfo.editorHeight
411
- });
412
- }
413
- if (state.outerWidth) {
414
- this._editorContainer.style.height = `${this.viewModel.layoutInfo.editorHeight}px`;
415
- this._editor.layout();
416
- }
417
- this.layoutNotebookCell();
418
- });
419
- }
420
- dispose() {
421
- this._editor.setModel(null);
422
- if (this._editorViewStateChanged) {
423
- this.viewModel.saveSpirceEditorViewState(this._editor.saveViewState());
424
- }
425
- super.dispose();
426
- }
427
- };
428
- NotebookDocumentMetadataElement = ( __decorate([( __param(3, IInstantiationService)), ( __param(4, ITextModelService)), ( __param(5, IMenuService)), ( __param(6, IContextKeyService)), ( __param(7, ITextResourceConfigurationService)), ( __param(8, IConfigurationService))], NotebookDocumentMetadataElement));
429
- class AbstractElementRenderer extends Disposable {
430
- constructor(
431
- notebookEditor,
432
- cell,
433
- templateData,
434
- style,
435
- instantiationService,
436
- languageService,
437
- modelService,
438
- textModelService,
439
- contextMenuService,
440
- keybindingService,
441
- notificationService,
442
- menuService,
443
- contextKeyService,
444
- configurationService,
445
- textConfigurationService
446
- ) {
447
- super();
448
- this.notebookEditor = notebookEditor;
449
- this.cell = cell;
450
- this.templateData = templateData;
451
- this.style = style;
452
- this.instantiationService = instantiationService;
453
- this.languageService = languageService;
454
- this.modelService = modelService;
455
- this.textModelService = textModelService;
456
- this.contextMenuService = contextMenuService;
457
- this.keybindingService = keybindingService;
458
- this.notificationService = notificationService;
459
- this.menuService = menuService;
460
- this.contextKeyService = contextKeyService;
461
- this.configurationService = configurationService;
462
- this.textConfigurationService = textConfigurationService;
463
- this._metadataLocalDisposable = this._register(( new DisposableStore()));
464
- this._outputLocalDisposable = this._register(( new DisposableStore()));
465
- this._ignoreMetadata = false;
466
- this._ignoreOutputs = false;
467
- this._isDisposed = false;
468
- this._metadataEditorDisposeStore = this._register(( new DisposableStore()));
469
- this._outputEditorDisposeStore = this._register(( new DisposableStore()));
470
- this._register(cell.onDidLayoutChange(e => {
471
- this.layout(e);
472
- }));
473
- this._register(cell.onDidLayoutChange(e => this.updateBorders()));
474
- this.init();
475
- this.buildBody();
476
- this._register(cell.onDidStateChange(() => {
477
- this.updateOutputRendering(this.cell.renderOutput);
478
- }));
479
- }
480
- buildBody() {
481
- const body = this.templateData.body;
482
- this._diffEditorContainer = this.templateData.diffEditorContainer;
483
- body.classList.remove("left", "right", "full");
484
- switch (this.style) {
485
- case "left":
486
- body.classList.add("left");
487
- break;
488
- case "right":
489
- body.classList.add("right");
490
- break;
491
- default:
492
- body.classList.add("full");
493
- break;
494
- }
495
- this.styleContainer(this._diffEditorContainer);
496
- this.updateSourceEditor();
497
- if (this.cell.modified) {
498
- this._register(
499
- this.cell.modified.textModel.onDidChangeContent(() => this._cellHeader.refresh())
500
- );
501
- }
502
- this._ignoreMetadata = this.configurationService.getValue("notebook.diff.ignoreMetadata");
503
- if (this._ignoreMetadata) {
504
- this._disposeMetadata();
505
- } else {
506
- this._buildMetadata();
507
- }
508
- this._ignoreOutputs = this.configurationService.getValue("notebook.diff.ignoreOutputs") || !!(this.notebookEditor.textModel?.transientOptions.transientOutputs);
509
- if (this._ignoreOutputs) {
510
- this._disposeOutput();
511
- } else {
512
- this._buildOutput();
513
- }
514
- this._register(this.configurationService.onDidChangeConfiguration(e => {
515
- let metadataLayoutChange = false;
516
- let outputLayoutChange = false;
517
- if (e.affectsConfiguration("notebook.diff.ignoreMetadata")) {
518
- const newValue = this.configurationService.getValue("notebook.diff.ignoreMetadata");
519
- if (newValue !== undefined && this._ignoreMetadata !== newValue) {
520
- this._ignoreMetadata = newValue;
521
- this._metadataLocalDisposable.clear();
522
- if (this.configurationService.getValue("notebook.diff.ignoreMetadata")) {
523
- this._disposeMetadata();
524
- } else {
525
- this.cell.metadataStatusHeight = 25;
526
- this._buildMetadata();
527
- this.updateMetadataRendering();
528
- metadataLayoutChange = true;
529
- }
530
- }
531
- }
532
- if (e.affectsConfiguration("notebook.diff.ignoreOutputs")) {
533
- const newValue = this.configurationService.getValue("notebook.diff.ignoreOutputs");
534
- if (newValue !== undefined && this._ignoreOutputs !== (newValue || this.notebookEditor.textModel?.transientOptions.transientOutputs)) {
535
- this._ignoreOutputs = newValue || !!(this.notebookEditor.textModel?.transientOptions.transientOutputs);
536
- this._outputLocalDisposable.clear();
537
- if (this._ignoreOutputs) {
538
- this._disposeOutput();
539
- this.cell.layoutChange();
540
- } else {
541
- this.cell.outputStatusHeight = 25;
542
- this._buildOutput();
543
- outputLayoutChange = true;
544
- }
545
- }
546
- }
547
- if (metadataLayoutChange || outputLayoutChange) {
548
- this.layout({
549
- metadataHeight: metadataLayoutChange,
550
- outputTotalHeight: outputLayoutChange
551
- });
552
- }
553
- }));
554
- }
555
- updateMetadataRendering() {
556
- if (this.cell.metadataFoldingState === PropertyFoldingState.Expanded) {
557
- this._metadataInfoContainer.style.display = "block";
558
- if (!this._metadataEditorContainer || !this._metadataEditor) {
559
- this._metadataEditorContainer = append(this._metadataInfoContainer, $(".metadata-editor-container"));
560
- this._buildMetadataEditor();
561
- } else {
562
- this.cell.metadataHeight = this._metadataEditor.getContentHeight();
563
- }
564
- } else {
565
- this._metadataInfoContainer.style.display = "none";
566
- this.cell.metadataHeight = 0;
567
- }
568
- }
569
- updateOutputRendering(renderRichOutput) {
570
- if (this.cell.outputFoldingState === PropertyFoldingState.Expanded) {
571
- this._outputInfoContainer.style.display = "block";
572
- if (renderRichOutput) {
573
- this._hideOutputsRaw();
574
- this._buildOutputRendererContainer();
575
- this._showOutputsRenderer();
576
- this._showOutputsEmptyView();
577
- } else {
578
- this._hideOutputsRenderer();
579
- this._buildOutputRawContainer();
580
- this._showOutputsRaw();
581
- }
582
- } else {
583
- this._outputInfoContainer.style.display = "none";
584
- this._hideOutputsRaw();
585
- this._hideOutputsRenderer();
586
- this._hideOutputsEmptyView();
587
- }
588
- }
589
- _buildOutputRawContainer() {
590
- if (!this._outputEditorContainer) {
591
- this._outputEditorContainer = append(this._outputInfoContainer, $(".output-editor-container"));
592
- this._buildOutputEditor();
593
- }
594
- }
595
- _showOutputsRaw() {
596
- if (this._outputEditorContainer) {
597
- this._outputEditorContainer.style.display = "block";
598
- this.cell.rawOutputHeight = this._outputEditor.getContentHeight();
599
- }
600
- }
601
- _showOutputsEmptyView() {
602
- this.cell.layoutChange();
603
- }
604
- _hideOutputsRaw() {
605
- if (this._outputEditorContainer) {
606
- this._outputEditorContainer.style.display = "none";
607
- this.cell.rawOutputHeight = 0;
608
- }
609
- }
610
- _hideOutputsEmptyView() {
611
- this.cell.layoutChange();
612
- }
613
- _applySanitizedMetadataChanges(currentMetadata, newMetadata) {
614
- const result = {};
615
- try {
616
- const newMetadataObj = JSON.parse(newMetadata);
617
- const keys = ( new Set([...( Object.keys(newMetadataObj))]));
618
- for (const key of keys) {
619
- switch (key) {
620
- case "inputCollapsed":
621
- case "outputCollapsed":
622
- if (typeof newMetadataObj[key] === "boolean") {
623
- result[key] = newMetadataObj[key];
624
- } else {
625
- result[key] = currentMetadata[key];
626
- }
627
- break;
628
- default:
629
- result[key] = newMetadataObj[key];
630
- break;
631
- }
632
- }
633
- const index = this.notebookEditor.textModel.cells.indexOf(this.cell.modified.textModel);
634
- if (index < 0) {
635
- return;
636
- }
637
- this.notebookEditor.textModel.applyEdits([{
638
- editType: CellEditType.Metadata,
639
- index,
640
- metadata: result
641
- }], true, undefined, () => undefined, undefined, true);
642
- } catch {}
643
- }
644
- async _buildMetadataEditor() {
645
- this._metadataEditorDisposeStore.clear();
646
- if (this.cell instanceof SideBySideDiffElementViewModel) {
647
- this._metadataEditor = this.instantiationService.createInstance(DiffEditorWidget, this._metadataEditorContainer, {
648
- ...fixedDiffEditorOptions,
649
- overflowWidgetsDomNode: this.notebookEditor.getOverflowContainerDomNode(),
650
- readOnly: false,
651
- originalEditable: false,
652
- ignoreTrimWhitespace: false,
653
- automaticLayout: false,
654
- dimension: {
655
- height: this.cell.layoutInfo.metadataHeight,
656
- width: this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), true, true)
657
- }
658
- }, {
659
- originalEditor: getOptimizedNestedCodeEditorWidgetOptions(),
660
- modifiedEditor: getOptimizedNestedCodeEditorWidgetOptions()
661
- });
662
- const unchangedRegions = this._register(getUnchangedRegionSettings(this.configurationService));
663
- if (unchangedRegions.options.enabled) {
664
- this._metadataEditor.updateOptions({
665
- hideUnchangedRegions: unchangedRegions.options
666
- });
667
- }
668
- this._metadataEditorDisposeStore.add(unchangedRegions.onDidChangeEnablement(() => {
669
- if (this._metadataEditor) {
670
- this._metadataEditor.updateOptions({
671
- hideUnchangedRegions: unchangedRegions.options
672
- });
673
- }
674
- }));
675
- this.layout({
676
- metadataHeight: true
677
- });
678
- this._metadataEditorDisposeStore.add(this._metadataEditor);
679
- this._metadataEditorContainer?.classList.add("diff");
680
- const [originalMetadataModel, modifiedMetadataModel] = await Promise.all([
681
- this.textModelService.createModelReference(CellUri.generateCellPropertyUri(
682
- this.cell.originalDocument.uri,
683
- this.cell.original.handle,
684
- Schemas.vscodeNotebookCellMetadata
685
- )),
686
- this.textModelService.createModelReference(CellUri.generateCellPropertyUri(
687
- this.cell.modifiedDocument.uri,
688
- this.cell.modified.handle,
689
- Schemas.vscodeNotebookCellMetadata
690
- ))
691
- ]);
692
- if (this._isDisposed) {
693
- originalMetadataModel.dispose();
694
- modifiedMetadataModel.dispose();
695
- return;
696
- }
697
- this._metadataEditorDisposeStore.add(originalMetadataModel);
698
- this._metadataEditorDisposeStore.add(modifiedMetadataModel);
699
- const vm = this._metadataEditor.createViewModel({
700
- original: originalMetadataModel.object.textEditorModel,
701
- modified: modifiedMetadataModel.object.textEditorModel
702
- });
703
- this._metadataEditor.setModel(vm);
704
- await vm.waitForDiff();
705
- if (this._isDisposed) {
706
- return;
707
- }
708
- this.cell.metadataHeight = this._metadataEditor.getContentHeight();
709
- this._metadataEditorDisposeStore.add(this._metadataEditor.onDidContentSizeChange(e => {
710
- if (e.contentHeightChanged && this.cell.metadataFoldingState === PropertyFoldingState.Expanded) {
711
- this.cell.metadataHeight = e.contentHeight;
712
- }
713
- }));
714
- let respondingToContentChange = false;
715
- this._metadataEditorDisposeStore.add(modifiedMetadataModel.object.textEditorModel.onDidChangeContent(() => {
716
- respondingToContentChange = true;
717
- const value = modifiedMetadataModel.object.textEditorModel.getValue();
718
- this._applySanitizedMetadataChanges(this.cell.modified.metadata, value);
719
- this._metadataHeader.refresh();
720
- respondingToContentChange = false;
721
- }));
722
- this._metadataEditorDisposeStore.add(this.cell.modified.textModel.onDidChangeMetadata(() => {
723
- if (respondingToContentChange) {
724
- return;
725
- }
726
- const modifiedMetadataSource = getFormattedMetadataJSON(
727
- this.notebookEditor.textModel?.transientOptions.transientCellMetadata,
728
- this.cell.modified?.metadata || {},
729
- this.cell.modified?.language,
730
- true
731
- );
732
- modifiedMetadataModel.object.textEditorModel.setValue(modifiedMetadataSource);
733
- }));
734
- return;
735
- } else {
736
- this._metadataEditor = this.instantiationService.createInstance(CodeEditorWidget, this._metadataEditorContainer, {
737
- ...fixedEditorOptions,
738
- dimension: {
739
- width: this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), false, true),
740
- height: this.cell.layoutInfo.metadataHeight
741
- },
742
- overflowWidgetsDomNode: this.notebookEditor.getOverflowContainerDomNode(),
743
- readOnly: false,
744
- allowVariableLineHeights: false
745
- }, {});
746
- this.layout({
747
- metadataHeight: true
748
- });
749
- this._metadataEditorDisposeStore.add(this._metadataEditor);
750
- const mode = this.languageService.createById("jsonc");
751
- const originalMetadataSource = getFormattedMetadataJSON(
752
- this.notebookEditor.textModel?.transientOptions.transientCellMetadata,
753
- this.cell.type === "insert" ? this.cell.modified.metadata || {} : this.cell.original.metadata || {},
754
- undefined,
755
- true
756
- );
757
- const uri = this.cell.type === "insert" ? this.cell.modified.uri : this.cell.original.uri;
758
- const handle = this.cell.type === "insert" ? this.cell.modified.handle : this.cell.original.handle;
759
- const modelUri = CellUri.generateCellPropertyUri(uri, handle, Schemas.vscodeNotebookCellMetadata);
760
- const metadataModel = this.modelService.createModel(originalMetadataSource, mode, modelUri, false);
761
- this._metadataEditor.setModel(metadataModel);
762
- this._metadataEditorDisposeStore.add(metadataModel);
763
- this.cell.metadataHeight = this._metadataEditor.getContentHeight();
764
- this._metadataEditorDisposeStore.add(this._metadataEditor.onDidContentSizeChange(e => {
765
- if (e.contentHeightChanged && this.cell.metadataFoldingState === PropertyFoldingState.Expanded) {
766
- this.cell.metadataHeight = e.contentHeight;
767
- }
768
- }));
769
- }
770
- }
771
- _buildOutputEditor() {
772
- this._outputEditorDisposeStore.clear();
773
- if ((this.cell.type === "modified" || this.cell.type === "unchanged") && !this.notebookEditor.textModel.transientOptions.transientOutputs) {
774
- const originalOutputsSource = getFormattedOutputJSON(this.cell.original?.outputs || []);
775
- const modifiedOutputsSource = getFormattedOutputJSON(this.cell.modified?.outputs || []);
776
- if (originalOutputsSource !== modifiedOutputsSource) {
777
- const mode = this.languageService.createById("json");
778
- const originalModel = this.modelService.createModel(originalOutputsSource, mode, undefined, true);
779
- const modifiedModel = this.modelService.createModel(modifiedOutputsSource, mode, undefined, true);
780
- this._outputEditorDisposeStore.add(originalModel);
781
- this._outputEditorDisposeStore.add(modifiedModel);
782
- const lineHeight = this.notebookEditor.getLayoutInfo().fontInfo.lineHeight || 17;
783
- const lineCount = Math.max(originalModel.getLineCount(), modifiedModel.getLineCount());
784
- this._outputEditor = this.instantiationService.createInstance(DiffEditorWidget, this._outputEditorContainer, {
785
- ...fixedDiffEditorOptions,
786
- overflowWidgetsDomNode: this.notebookEditor.getOverflowContainerDomNode(),
787
- readOnly: true,
788
- ignoreTrimWhitespace: false,
789
- automaticLayout: false,
790
- dimension: {
791
- height: Math.min(
792
- OUTPUT_EDITOR_HEIGHT_MAGIC,
793
- this.cell.layoutInfo.rawOutputHeight || lineHeight * lineCount
794
- ),
795
- width: this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), false, true)
796
- },
797
- accessibilityVerbose: this.configurationService.getValue(AccessibilityVerbositySettingId.DiffEditor) ?? false
798
- }, {
799
- originalEditor: getOptimizedNestedCodeEditorWidgetOptions(),
800
- modifiedEditor: getOptimizedNestedCodeEditorWidgetOptions()
801
- });
802
- this._outputEditorDisposeStore.add(this._outputEditor);
803
- this._outputEditorContainer?.classList.add("diff");
804
- this._outputEditor.setModel({
805
- original: originalModel,
806
- modified: modifiedModel
807
- });
808
- this._outputEditor.restoreViewState(this.cell.getOutputEditorViewState());
809
- this.cell.rawOutputHeight = this._outputEditor.getContentHeight();
810
- this._outputEditorDisposeStore.add(this._outputEditor.onDidContentSizeChange(e => {
811
- if (e.contentHeightChanged && this.cell.outputFoldingState === PropertyFoldingState.Expanded) {
812
- this.cell.rawOutputHeight = e.contentHeight;
813
- }
814
- }));
815
- this._outputEditorDisposeStore.add(this.cell.modified.textModel.onDidChangeOutputs(() => {
816
- const modifiedOutputsSource = getFormattedOutputJSON(this.cell.modified?.outputs || []);
817
- modifiedModel.setValue(modifiedOutputsSource);
818
- this._outputHeader.refresh();
819
- }));
820
- return;
821
- }
822
- }
823
- this._outputEditor = this.instantiationService.createInstance(CodeEditorWidget, this._outputEditorContainer, {
824
- ...fixedEditorOptions,
825
- dimension: {
826
- width: Math.min(OUTPUT_EDITOR_HEIGHT_MAGIC, this.cell.getComputedCellContainerWidth(
827
- this.notebookEditor.getLayoutInfo(),
828
- false,
829
- this.cell.type === "unchanged" || this.cell.type === "modified"
830
- ) - 32),
831
- height: this.cell.layoutInfo.rawOutputHeight
832
- },
833
- overflowWidgetsDomNode: this.notebookEditor.getOverflowContainerDomNode(),
834
- allowVariableLineHeights: false
835
- }, {});
836
- this._outputEditorDisposeStore.add(this._outputEditor);
837
- const mode = this.languageService.createById("json");
838
- const originaloutputSource = getFormattedOutputJSON(
839
- this.notebookEditor.textModel.transientOptions.transientOutputs ? [] : this.cell.type === "insert" ? this.cell.modified?.outputs || [] : this.cell.original?.outputs || []
840
- );
841
- const outputModel = this.modelService.createModel(originaloutputSource, mode, undefined, true);
842
- this._outputEditorDisposeStore.add(outputModel);
843
- this._outputEditor.setModel(outputModel);
844
- this._outputEditor.restoreViewState(this.cell.getOutputEditorViewState());
845
- this.cell.rawOutputHeight = this._outputEditor.getContentHeight();
846
- this._outputEditorDisposeStore.add(this._outputEditor.onDidContentSizeChange(e => {
847
- if (e.contentHeightChanged && this.cell.outputFoldingState === PropertyFoldingState.Expanded) {
848
- this.cell.rawOutputHeight = e.contentHeight;
849
- }
850
- }));
851
- }
852
- layoutNotebookCell() {
853
- this.notebookEditor.layoutNotebookCell(this.cell, this.cell.layoutInfo.totalHeight);
854
- }
855
- updateBorders() {
856
- this.templateData.leftBorder.style.height = `${this.cell.layoutInfo.totalHeight - 32}px`;
857
- this.templateData.rightBorder.style.height = `${this.cell.layoutInfo.totalHeight - 32}px`;
858
- this.templateData.bottomBorder.style.top = `${this.cell.layoutInfo.totalHeight - 32}px`;
859
- }
860
- dispose() {
861
- if (this._outputEditor) {
862
- this.cell.saveOutputEditorViewState(this._outputEditor.saveViewState());
863
- }
864
- if (this._metadataEditor) {
865
- this.cell.saveMetadataEditorViewState(this._metadataEditor.saveViewState());
866
- }
867
- this._metadataEditorDisposeStore.dispose();
868
- this._outputEditorDisposeStore.dispose();
869
- this._isDisposed = true;
870
- super.dispose();
871
- }
872
- }
873
- class SingleSideDiffElement extends AbstractElementRenderer {
874
- constructor(
875
- notebookEditor,
876
- cell,
877
- templateData,
878
- style,
879
- instantiationService,
880
- languageService,
881
- modelService,
882
- textModelService,
883
- contextMenuService,
884
- keybindingService,
885
- notificationService,
886
- menuService,
887
- contextKeyService,
888
- configurationService,
889
- textConfigurationService
890
- ) {
891
- super(
892
- notebookEditor,
893
- cell,
894
- templateData,
895
- style,
896
- instantiationService,
897
- languageService,
898
- modelService,
899
- textModelService,
900
- contextMenuService,
901
- keybindingService,
902
- notificationService,
903
- menuService,
904
- contextKeyService,
905
- configurationService,
906
- textConfigurationService
907
- );
908
- this.cell = cell;
909
- this.templateData = templateData;
910
- this.updateBorders();
911
- }
912
- init() {
913
- this._diagonalFill = this.templateData.diagonalFill;
914
- }
915
- buildBody() {
916
- const body = this.templateData.body;
917
- this._diffEditorContainer = this.templateData.diffEditorContainer;
918
- body.classList.remove("left", "right", "full");
919
- switch (this.style) {
920
- case "left":
921
- body.classList.add("left");
922
- break;
923
- case "right":
924
- body.classList.add("right");
925
- break;
926
- default:
927
- body.classList.add("full");
928
- break;
929
- }
930
- this.styleContainer(this._diffEditorContainer);
931
- this.updateSourceEditor();
932
- if (this.configurationService.getValue("notebook.diff.ignoreMetadata")) {
933
- this._disposeMetadata();
934
- } else {
935
- this._buildMetadata();
936
- }
937
- if (this.configurationService.getValue("notebook.diff.ignoreOutputs") || this.notebookEditor.textModel?.transientOptions.transientOutputs) {
938
- this._disposeOutput();
939
- } else {
940
- this._buildOutput();
941
- }
942
- this._register(this.configurationService.onDidChangeConfiguration(e => {
943
- let metadataLayoutChange = false;
944
- let outputLayoutChange = false;
945
- if (e.affectsConfiguration("notebook.diff.ignoreMetadata")) {
946
- this._metadataLocalDisposable.clear();
947
- if (this.configurationService.getValue("notebook.diff.ignoreMetadata")) {
948
- this._disposeMetadata();
949
- } else {
950
- this.cell.metadataStatusHeight = 25;
951
- this._buildMetadata();
952
- this.updateMetadataRendering();
953
- metadataLayoutChange = true;
954
- }
955
- }
956
- if (e.affectsConfiguration("notebook.diff.ignoreOutputs")) {
957
- this._outputLocalDisposable.clear();
958
- if (this.configurationService.getValue("notebook.diff.ignoreOutputs") || this.notebookEditor.textModel?.transientOptions.transientOutputs) {
959
- this._disposeOutput();
960
- } else {
961
- this.cell.outputStatusHeight = 25;
962
- this._buildOutput();
963
- outputLayoutChange = true;
964
- }
965
- }
966
- if (metadataLayoutChange || outputLayoutChange) {
967
- this.layout({
968
- metadataHeight: metadataLayoutChange,
969
- outputTotalHeight: outputLayoutChange
970
- });
971
- }
972
- }));
973
- }
974
- updateSourceEditor() {
975
- this._cellHeaderContainer = this.templateData.cellHeaderContainer;
976
- this._cellHeaderContainer.style.display = "flex";
977
- this._cellHeaderContainer.innerText = "";
978
- this._editorContainer = this.templateData.editorContainer;
979
- this._editorContainer.classList.add("diff");
980
- const renderSourceEditor = () => {
981
- if (this.cell.cellFoldingState === PropertyFoldingState.Collapsed) {
982
- this._editorContainer.style.display = "none";
983
- this.cell.editorHeight = 0;
984
- return;
985
- }
986
- const lineHeight = this.notebookEditor.getLayoutInfo().fontInfo.lineHeight || 17;
987
- const editorHeight = this.cell.computeInputEditorHeight(lineHeight);
988
- this._editorContainer.style.height = `${editorHeight}px`;
989
- this._editorContainer.style.display = "block";
990
- if (this._editor) {
991
- const contentHeight = this._editor.getContentHeight();
992
- if (contentHeight >= 0) {
993
- this.cell.editorHeight = contentHeight;
994
- }
995
- return;
996
- }
997
- this._editor = this.templateData.sourceEditor;
998
- this._editor.layout({
999
- width: (this.notebookEditor.getLayoutInfo().width - 2 * DIFF_CELL_MARGIN) / 2 - 18,
1000
- height: editorHeight
1001
- });
1002
- this._editor.updateOptions({
1003
- readOnly: this.readonly
1004
- });
1005
- this.cell.editorHeight = editorHeight;
1006
- this._register(this._editor.onDidContentSizeChange(e => {
1007
- if (this.cell.cellFoldingState === PropertyFoldingState.Expanded && e.contentHeightChanged && this.cell.layoutInfo.editorHeight !== e.contentHeight) {
1008
- this.cell.editorHeight = e.contentHeight;
1009
- }
1010
- }));
1011
- this._initializeSourceDiffEditor(this.nestedCellViewModel);
1012
- };
1013
- this._cellHeader = this._register(this.instantiationService.createInstance(
1014
- PropertyHeader,
1015
- this.cell,
1016
- this._cellHeaderContainer,
1017
- this.notebookEditor,
1018
- {
1019
- updateInfoRendering: () => renderSourceEditor(),
1020
- checkIfModified: () => ({
1021
- reason: undefined
1022
- }),
1023
- getFoldingState: () => this.cell.cellFoldingState,
1024
- updateFoldingState: state => this.cell.cellFoldingState = state,
1025
- unChangedLabel: "Input",
1026
- changedLabel: "Input",
1027
- prefix: "input",
1028
- menuId: MenuId.NotebookDiffCellInputTitle
1029
- }
1030
- ));
1031
- this._cellHeader.buildHeader();
1032
- renderSourceEditor();
1033
- this._initializeSourceDiffEditor(this.nestedCellViewModel);
1034
- }
1035
- calculateDiagonalFillHeight() {
1036
- return this.cell.layoutInfo.cellStatusHeight + this.cell.layoutInfo.editorHeight + this.cell.layoutInfo.editorMargin + this.cell.layoutInfo.metadataStatusHeight + this.cell.layoutInfo.metadataHeight + this.cell.layoutInfo.outputTotalHeight + this.cell.layoutInfo.outputStatusHeight;
1037
- }
1038
- async _initializeSourceDiffEditor(modifiedCell) {
1039
- const modifiedRef = await this.textModelService.createModelReference(modifiedCell.uri);
1040
- if (this._isDisposed) {
1041
- return;
1042
- }
1043
- const modifiedTextModel = modifiedRef.object.textEditorModel;
1044
- this._register(modifiedRef);
1045
- this._editor.setModel(modifiedTextModel);
1046
- const editorViewState = this.cell.getSourceEditorViewState();
1047
- if (editorViewState) {
1048
- this._editor.restoreViewState(editorViewState);
1049
- }
1050
- const contentHeight = this._editor.getContentHeight();
1051
- this.cell.editorHeight = contentHeight;
1052
- const height = `${this.calculateDiagonalFillHeight()}px`;
1053
- if (this._diagonalFill.style.height !== height) {
1054
- this._diagonalFill.style.height = height;
1055
- }
1056
- }
1057
- _disposeMetadata() {
1058
- this.cell.metadataStatusHeight = 0;
1059
- this.cell.metadataHeight = 0;
1060
- this.templateData.cellHeaderContainer.style.display = "none";
1061
- this.templateData.metadataHeaderContainer.style.display = "none";
1062
- this.templateData.metadataInfoContainer.style.display = "none";
1063
- this._metadataEditor = undefined;
1064
- }
1065
- _buildMetadata() {
1066
- this._metadataHeaderContainer = this.templateData.metadataHeaderContainer;
1067
- this._metadataInfoContainer = this.templateData.metadataInfoContainer;
1068
- this._metadataHeaderContainer.style.display = "flex";
1069
- this._metadataInfoContainer.style.display = "block";
1070
- this._metadataHeaderContainer.innerText = "";
1071
- this._metadataInfoContainer.innerText = "";
1072
- this._metadataHeader = this.instantiationService.createInstance(
1073
- PropertyHeader,
1074
- this.cell,
1075
- this._metadataHeaderContainer,
1076
- this.notebookEditor,
1077
- {
1078
- updateInfoRendering: this.updateMetadataRendering.bind(this),
1079
- checkIfModified: () => {
1080
- return this.cell.checkMetadataIfModified();
1081
- },
1082
- getFoldingState: () => {
1083
- return this.cell.metadataFoldingState;
1084
- },
1085
- updateFoldingState: state => {
1086
- this.cell.metadataFoldingState = state;
1087
- },
1088
- unChangedLabel: "Metadata",
1089
- changedLabel: "Metadata changed",
1090
- prefix: "metadata",
1091
- menuId: MenuId.NotebookDiffCellMetadataTitle
1092
- }
1093
- );
1094
- this._metadataLocalDisposable.add(this._metadataHeader);
1095
- this._metadataHeader.buildHeader();
1096
- }
1097
- _buildOutput() {
1098
- this.templateData.outputHeaderContainer.style.display = "flex";
1099
- this.templateData.outputInfoContainer.style.display = "block";
1100
- this._outputHeaderContainer = this.templateData.outputHeaderContainer;
1101
- this._outputInfoContainer = this.templateData.outputInfoContainer;
1102
- this._outputHeaderContainer.innerText = "";
1103
- this._outputInfoContainer.innerText = "";
1104
- this._outputHeader = this.instantiationService.createInstance(
1105
- PropertyHeader,
1106
- this.cell,
1107
- this._outputHeaderContainer,
1108
- this.notebookEditor,
1109
- {
1110
- updateInfoRendering: this.updateOutputRendering.bind(this),
1111
- checkIfModified: () => {
1112
- return this.cell.checkIfOutputsModified();
1113
- },
1114
- getFoldingState: () => {
1115
- return this.cell.outputFoldingState;
1116
- },
1117
- updateFoldingState: state => {
1118
- this.cell.outputFoldingState = state;
1119
- },
1120
- unChangedLabel: "Outputs",
1121
- changedLabel: "Outputs changed",
1122
- prefix: "output",
1123
- menuId: MenuId.NotebookDiffCellOutputsTitle
1124
- }
1125
- );
1126
- this._outputLocalDisposable.add(this._outputHeader);
1127
- this._outputHeader.buildHeader();
1128
- }
1129
- _disposeOutput() {
1130
- this._hideOutputsRaw();
1131
- this._hideOutputsRenderer();
1132
- this._hideOutputsEmptyView();
1133
- this.cell.rawOutputHeight = 0;
1134
- this.cell.outputMetadataHeight = 0;
1135
- this.cell.outputStatusHeight = 0;
1136
- this.templateData.outputHeaderContainer.style.display = "none";
1137
- this.templateData.outputInfoContainer.style.display = "none";
1138
- this._outputViewContainer = undefined;
1139
- }
1140
- }
1141
- let DeletedElement = class DeletedElement extends SingleSideDiffElement {
1142
- constructor(
1143
- notebookEditor,
1144
- cell,
1145
- templateData,
1146
- languageService,
1147
- modelService,
1148
- textModelService,
1149
- instantiationService,
1150
- contextMenuService,
1151
- keybindingService,
1152
- notificationService,
1153
- menuService,
1154
- contextKeyService,
1155
- configurationService,
1156
- textConfigurationService
1157
- ) {
1158
- super(
1159
- notebookEditor,
1160
- cell,
1161
- templateData,
1162
- "left",
1163
- instantiationService,
1164
- languageService,
1165
- modelService,
1166
- textModelService,
1167
- contextMenuService,
1168
- keybindingService,
1169
- notificationService,
1170
- menuService,
1171
- contextKeyService,
1172
- configurationService,
1173
- textConfigurationService
1174
- );
1175
- }
1176
- get nestedCellViewModel() {
1177
- return this.cell.original;
1178
- }
1179
- get readonly() {
1180
- return true;
1181
- }
1182
- styleContainer(container) {
1183
- container.classList.remove("inserted");
1184
- container.classList.add("removed");
1185
- }
1186
- layout(state) {
1187
- scheduleAtNextAnimationFrame(getWindow(this._diffEditorContainer), () => {
1188
- if ((state.editorHeight || state.outerWidth) && this._editor) {
1189
- this._editorContainer.style.height = `${this.cell.layoutInfo.editorHeight}px`;
1190
- this._editor.layout({
1191
- width: this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), false, false),
1192
- height: this.cell.layoutInfo.editorHeight
1193
- });
1194
- }
1195
- if (state.outerWidth && this._editor) {
1196
- this._editorContainer.style.height = `${this.cell.layoutInfo.editorHeight}px`;
1197
- this._editor.layout();
1198
- }
1199
- if (state.metadataHeight || state.outerWidth) {
1200
- this._metadataEditor?.layout({
1201
- width: this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), false, false),
1202
- height: this.cell.layoutInfo.metadataHeight
1203
- });
1204
- }
1205
- if (state.outputTotalHeight || state.outerWidth) {
1206
- this._outputEditor?.layout({
1207
- width: this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), false, false),
1208
- height: this.cell.layoutInfo.outputTotalHeight
1209
- });
1210
- }
1211
- if (this._diagonalFill) {
1212
- this._diagonalFill.style.height = `${this.calculateDiagonalFillHeight()}px`;
1213
- }
1214
- this.layoutNotebookCell();
1215
- });
1216
- }
1217
- _buildOutputRendererContainer() {
1218
- if (!this._outputViewContainer) {
1219
- this._outputViewContainer = append(this._outputInfoContainer, $(".output-view-container"));
1220
- this._outputEmptyElement = append(this._outputViewContainer, $(".output-empty-view"));
1221
- const span = append(this._outputEmptyElement, $("span"));
1222
- span.innerText = "No outputs to render";
1223
- if (!this.cell.original?.outputs.length) {
1224
- this._outputEmptyElement.style.display = "block";
1225
- } else {
1226
- this._outputEmptyElement.style.display = "none";
1227
- }
1228
- this.cell.layoutChange();
1229
- this._outputLeftView = this.instantiationService.createInstance(
1230
- OutputContainer,
1231
- this.notebookEditor,
1232
- this.notebookEditor.textModel,
1233
- this.cell,
1234
- this.cell.original,
1235
- DiffSide.Original,
1236
- this._outputViewContainer
1237
- );
1238
- this._register(this._outputLeftView);
1239
- this._outputLeftView.render();
1240
- const removedOutputRenderListener = this.notebookEditor.onDidDynamicOutputRendered(e => {
1241
- if (( e.cell.uri.toString()) === ( this.cell.original.uri.toString())) {
1242
- this.notebookEditor.deltaCellOutputContainerClassNames(DiffSide.Original, this.cell.original.id, ["nb-cellDeleted"], []);
1243
- removedOutputRenderListener.dispose();
1244
- }
1245
- });
1246
- this._register(removedOutputRenderListener);
1247
- }
1248
- this._outputViewContainer.style.display = "block";
1249
- }
1250
- _decorate() {
1251
- this.notebookEditor.deltaCellOutputContainerClassNames(DiffSide.Original, this.cell.original.id, ["nb-cellDeleted"], []);
1252
- }
1253
- _showOutputsRenderer() {
1254
- if (this._outputViewContainer) {
1255
- this._outputViewContainer.style.display = "block";
1256
- this._outputLeftView?.showOutputs();
1257
- this._decorate();
1258
- }
1259
- }
1260
- _hideOutputsRenderer() {
1261
- if (this._outputViewContainer) {
1262
- this._outputViewContainer.style.display = "none";
1263
- this._outputLeftView?.hideOutputs();
1264
- }
1265
- }
1266
- dispose() {
1267
- if (this._editor) {
1268
- this.cell.saveSpirceEditorViewState(this._editor.saveViewState());
1269
- }
1270
- super.dispose();
1271
- }
1272
- };
1273
- DeletedElement = ( __decorate([( __param(3, ILanguageService)), ( __param(4, IModelService)), ( __param(5, ITextModelService)), ( __param(6, IInstantiationService)), ( __param(7, IContextMenuService)), ( __param(8, IKeybindingService)), ( __param(9, INotificationService)), ( __param(10, IMenuService)), ( __param(11, IContextKeyService)), ( __param(12, IConfigurationService)), ( __param(13, ITextResourceConfigurationService))], DeletedElement));
1274
- let InsertElement = class InsertElement extends SingleSideDiffElement {
1275
- constructor(
1276
- notebookEditor,
1277
- cell,
1278
- templateData,
1279
- instantiationService,
1280
- languageService,
1281
- modelService,
1282
- textModelService,
1283
- contextMenuService,
1284
- keybindingService,
1285
- notificationService,
1286
- menuService,
1287
- contextKeyService,
1288
- configurationService,
1289
- textConfigurationService
1290
- ) {
1291
- super(
1292
- notebookEditor,
1293
- cell,
1294
- templateData,
1295
- "right",
1296
- instantiationService,
1297
- languageService,
1298
- modelService,
1299
- textModelService,
1300
- contextMenuService,
1301
- keybindingService,
1302
- notificationService,
1303
- menuService,
1304
- contextKeyService,
1305
- configurationService,
1306
- textConfigurationService
1307
- );
1308
- }
1309
- get nestedCellViewModel() {
1310
- return this.cell.modified;
1311
- }
1312
- get readonly() {
1313
- return false;
1314
- }
1315
- styleContainer(container) {
1316
- container.classList.remove("removed");
1317
- container.classList.add("inserted");
1318
- }
1319
- _buildOutputRendererContainer() {
1320
- if (!this._outputViewContainer) {
1321
- this._outputViewContainer = append(this._outputInfoContainer, $(".output-view-container"));
1322
- this._outputEmptyElement = append(this._outputViewContainer, $(".output-empty-view"));
1323
- this._outputEmptyElement.innerText = "No outputs to render";
1324
- if (!this.cell.modified?.outputs.length) {
1325
- this._outputEmptyElement.style.display = "block";
1326
- } else {
1327
- this._outputEmptyElement.style.display = "none";
1328
- }
1329
- this.cell.layoutChange();
1330
- this._outputRightView = this.instantiationService.createInstance(
1331
- OutputContainer,
1332
- this.notebookEditor,
1333
- this.notebookEditor.textModel,
1334
- this.cell,
1335
- this.cell.modified,
1336
- DiffSide.Modified,
1337
- this._outputViewContainer
1338
- );
1339
- this._register(this._outputRightView);
1340
- this._outputRightView.render();
1341
- const insertOutputRenderListener = this.notebookEditor.onDidDynamicOutputRendered(e => {
1342
- if (( e.cell.uri.toString()) === ( this.cell.modified.uri.toString())) {
1343
- this.notebookEditor.deltaCellOutputContainerClassNames(DiffSide.Modified, this.cell.modified.id, ["nb-cellAdded"], []);
1344
- insertOutputRenderListener.dispose();
1345
- }
1346
- });
1347
- this._register(insertOutputRenderListener);
1348
- }
1349
- this._outputViewContainer.style.display = "block";
1350
- }
1351
- _decorate() {
1352
- this.notebookEditor.deltaCellOutputContainerClassNames(DiffSide.Modified, this.cell.modified.id, ["nb-cellAdded"], []);
1353
- }
1354
- _showOutputsRenderer() {
1355
- if (this._outputViewContainer) {
1356
- this._outputViewContainer.style.display = "block";
1357
- this._outputRightView?.showOutputs();
1358
- this._decorate();
1359
- }
1360
- }
1361
- _hideOutputsRenderer() {
1362
- if (this._outputViewContainer) {
1363
- this._outputViewContainer.style.display = "none";
1364
- this._outputRightView?.hideOutputs();
1365
- }
1366
- }
1367
- layout(state) {
1368
- scheduleAtNextAnimationFrame(getWindow(this._diffEditorContainer), () => {
1369
- if ((state.editorHeight || state.outerWidth) && this._editor) {
1370
- this._editorContainer.style.height = `${this.cell.layoutInfo.editorHeight}px`;
1371
- this._editor.layout({
1372
- width: this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), false, false),
1373
- height: this.cell.layoutInfo.editorHeight
1374
- });
1375
- }
1376
- if (state.outerWidth && this._editor) {
1377
- this._editorContainer.style.height = `${this.cell.layoutInfo.editorHeight}px`;
1378
- this._editor.layout();
1379
- }
1380
- if (state.metadataHeight || state.outerWidth) {
1381
- this._metadataEditor?.layout({
1382
- width: this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), false, true),
1383
- height: this.cell.layoutInfo.metadataHeight
1384
- });
1385
- }
1386
- if (state.outputTotalHeight || state.outerWidth) {
1387
- this._outputEditor?.layout({
1388
- width: this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), false, false),
1389
- height: this.cell.layoutInfo.outputTotalHeight
1390
- });
1391
- }
1392
- this.layoutNotebookCell();
1393
- if (this._diagonalFill) {
1394
- this._diagonalFill.style.height = `${this.calculateDiagonalFillHeight()}px`;
1395
- }
1396
- });
1397
- }
1398
- dispose() {
1399
- if (this._editor) {
1400
- this.cell.saveSpirceEditorViewState(this._editor.saveViewState());
1401
- }
1402
- super.dispose();
1403
- }
1404
- };
1405
- InsertElement = ( __decorate([( __param(3, IInstantiationService)), ( __param(4, ILanguageService)), ( __param(5, IModelService)), ( __param(6, ITextModelService)), ( __param(7, IContextMenuService)), ( __param(8, IKeybindingService)), ( __param(9, INotificationService)), ( __param(10, IMenuService)), ( __param(11, IContextKeyService)), ( __param(12, IConfigurationService)), ( __param(13, ITextResourceConfigurationService))], InsertElement));
1406
- let ModifiedElement = class ModifiedElement extends AbstractElementRenderer {
1407
- constructor(
1408
- notebookEditor,
1409
- cell,
1410
- templateData,
1411
- instantiationService,
1412
- languageService,
1413
- modelService,
1414
- textModelService,
1415
- contextMenuService,
1416
- keybindingService,
1417
- notificationService,
1418
- menuService,
1419
- contextKeyService,
1420
- configurationService,
1421
- textConfigurationService
1422
- ) {
1423
- super(
1424
- notebookEditor,
1425
- cell,
1426
- templateData,
1427
- "full",
1428
- instantiationService,
1429
- languageService,
1430
- modelService,
1431
- textModelService,
1432
- contextMenuService,
1433
- keybindingService,
1434
- notificationService,
1435
- menuService,
1436
- contextKeyService,
1437
- configurationService,
1438
- textConfigurationService
1439
- );
1440
- this.cell = cell;
1441
- this.templateData = templateData;
1442
- this._editorViewStateChanged = false;
1443
- this.updateBorders();
1444
- }
1445
- init() {}
1446
- styleContainer(container) {
1447
- container.classList.remove("inserted", "removed");
1448
- }
1449
- buildBody() {
1450
- super.buildBody();
1451
- if (this.cell.displayIconToHideUnmodifiedCells) {
1452
- this._register(
1453
- this.templateData.marginOverlay.onAction(() => this.cell.hideUnchangedCells())
1454
- );
1455
- this.templateData.marginOverlay.show();
1456
- } else {
1457
- this.templateData.marginOverlay.hide();
1458
- }
1459
- }
1460
- _disposeMetadata() {
1461
- this.cell.metadataStatusHeight = 0;
1462
- this.cell.metadataHeight = 0;
1463
- this.templateData.metadataHeaderContainer.style.display = "none";
1464
- this.templateData.metadataInfoContainer.style.display = "none";
1465
- this._metadataEditor = undefined;
1466
- }
1467
- _buildMetadata() {
1468
- this._metadataHeaderContainer = this.templateData.metadataHeaderContainer;
1469
- this._metadataInfoContainer = this.templateData.metadataInfoContainer;
1470
- this._metadataHeaderContainer.style.display = "flex";
1471
- this._metadataInfoContainer.style.display = "block";
1472
- this._metadataHeaderContainer.innerText = "";
1473
- this._metadataInfoContainer.innerText = "";
1474
- this._metadataHeader = this.instantiationService.createInstance(
1475
- PropertyHeader,
1476
- this.cell,
1477
- this._metadataHeaderContainer,
1478
- this.notebookEditor,
1479
- {
1480
- updateInfoRendering: this.updateMetadataRendering.bind(this),
1481
- checkIfModified: () => {
1482
- return this.cell.checkMetadataIfModified();
1483
- },
1484
- getFoldingState: () => {
1485
- return this.cell.metadataFoldingState;
1486
- },
1487
- updateFoldingState: state => {
1488
- this.cell.metadataFoldingState = state;
1489
- },
1490
- unChangedLabel: "Metadata",
1491
- changedLabel: "Metadata changed",
1492
- prefix: "metadata",
1493
- menuId: MenuId.NotebookDiffCellMetadataTitle
1494
- }
1495
- );
1496
- this._metadataLocalDisposable.add(this._metadataHeader);
1497
- this._metadataHeader.buildHeader();
1498
- }
1499
- _disposeOutput() {
1500
- this._hideOutputsRaw();
1501
- this._hideOutputsRenderer();
1502
- this._hideOutputsEmptyView();
1503
- this.cell.rawOutputHeight = 0;
1504
- this.cell.outputMetadataHeight = 0;
1505
- this.cell.outputStatusHeight = 0;
1506
- this.templateData.outputHeaderContainer.style.display = "none";
1507
- this.templateData.outputInfoContainer.style.display = "none";
1508
- this._outputViewContainer = undefined;
1509
- }
1510
- _buildOutput() {
1511
- this.templateData.outputHeaderContainer.style.display = "flex";
1512
- this.templateData.outputInfoContainer.style.display = "block";
1513
- this._outputHeaderContainer = this.templateData.outputHeaderContainer;
1514
- this._outputInfoContainer = this.templateData.outputInfoContainer;
1515
- this._outputHeaderContainer.innerText = "";
1516
- this._outputInfoContainer.innerText = "";
1517
- if (this.cell.checkIfOutputsModified()) {
1518
- this._outputInfoContainer.classList.add("modified");
1519
- } else {
1520
- this._outputInfoContainer.classList.remove("modified");
1521
- }
1522
- this._outputHeader = this.instantiationService.createInstance(
1523
- PropertyHeader,
1524
- this.cell,
1525
- this._outputHeaderContainer,
1526
- this.notebookEditor,
1527
- {
1528
- updateInfoRendering: this.updateOutputRendering.bind(this),
1529
- checkIfModified: () => {
1530
- return this.cell.checkIfOutputsModified();
1531
- },
1532
- getFoldingState: () => {
1533
- return this.cell.outputFoldingState;
1534
- },
1535
- updateFoldingState: state => {
1536
- this.cell.outputFoldingState = state;
1537
- },
1538
- unChangedLabel: "Outputs",
1539
- changedLabel: "Outputs changed",
1540
- prefix: "output",
1541
- menuId: MenuId.NotebookDiffCellOutputsTitle
1542
- }
1543
- );
1544
- this._outputLocalDisposable.add(this._outputHeader);
1545
- this._outputHeader.buildHeader();
1546
- }
1547
- _buildOutputRendererContainer() {
1548
- if (!this._outputViewContainer) {
1549
- this._outputViewContainer = append(this._outputInfoContainer, $(".output-view-container"));
1550
- this._outputEmptyElement = append(this._outputViewContainer, $(".output-empty-view"));
1551
- this._outputEmptyElement.innerText = "No outputs to render";
1552
- if (!this.cell.checkIfOutputsModified() && this.cell.modified.outputs.length === 0) {
1553
- this._outputEmptyElement.style.display = "block";
1554
- } else {
1555
- this._outputEmptyElement.style.display = "none";
1556
- }
1557
- this.cell.layoutChange();
1558
- this._register(this.cell.modified.textModel.onDidChangeOutputs(() => {
1559
- if (!this.cell.checkIfOutputsModified() && this.cell.modified.outputs.length === 0) {
1560
- this._outputEmptyElement.style.display = "block";
1561
- } else {
1562
- this._outputEmptyElement.style.display = "none";
1563
- }
1564
- this._decorate();
1565
- }));
1566
- this._outputLeftContainer = append(this._outputViewContainer, $(".output-view-container-left"));
1567
- this._outputRightContainer = append(this._outputViewContainer, $(".output-view-container-right"));
1568
- this._outputMetadataContainer = append(this._outputViewContainer, $(".output-view-container-metadata"));
1569
- const outputModified = this.cell.checkIfOutputsModified();
1570
- const outputMetadataChangeOnly = outputModified && outputModified.kind === OutputComparison.Metadata && this.cell.original.outputs.length === 1 && this.cell.modified.outputs.length === 1 && outputEqual(this.cell.original.outputs[0], this.cell.modified.outputs[0]) === OutputComparison.Metadata;
1571
- if (outputModified && !outputMetadataChangeOnly) {
1572
- const originalOutputRenderListener = this.notebookEditor.onDidDynamicOutputRendered(e => {
1573
- if (( e.cell.uri.toString()) === ( this.cell.original.uri.toString()) && this.cell.checkIfOutputsModified()) {
1574
- this.notebookEditor.deltaCellOutputContainerClassNames(DiffSide.Original, this.cell.original.id, ["nb-cellDeleted"], []);
1575
- originalOutputRenderListener.dispose();
1576
- }
1577
- });
1578
- const modifiedOutputRenderListener = this.notebookEditor.onDidDynamicOutputRendered(e => {
1579
- if (( e.cell.uri.toString()) === ( this.cell.modified.uri.toString()) && this.cell.checkIfOutputsModified()) {
1580
- this.notebookEditor.deltaCellOutputContainerClassNames(DiffSide.Modified, this.cell.modified.id, ["nb-cellAdded"], []);
1581
- modifiedOutputRenderListener.dispose();
1582
- }
1583
- });
1584
- this._register(originalOutputRenderListener);
1585
- this._register(modifiedOutputRenderListener);
1586
- }
1587
- this._outputLeftView = this.instantiationService.createInstance(
1588
- OutputContainer,
1589
- this.notebookEditor,
1590
- this.notebookEditor.textModel,
1591
- this.cell,
1592
- this.cell.original,
1593
- DiffSide.Original,
1594
- this._outputLeftContainer
1595
- );
1596
- this._outputLeftView.render();
1597
- this._register(this._outputLeftView);
1598
- this._outputRightView = this.instantiationService.createInstance(
1599
- OutputContainer,
1600
- this.notebookEditor,
1601
- this.notebookEditor.textModel,
1602
- this.cell,
1603
- this.cell.modified,
1604
- DiffSide.Modified,
1605
- this._outputRightContainer
1606
- );
1607
- this._outputRightView.render();
1608
- this._register(this._outputRightView);
1609
- if (outputModified && !outputMetadataChangeOnly) {
1610
- this._decorate();
1611
- }
1612
- if (outputMetadataChangeOnly) {
1613
- this._outputMetadataContainer.style.top = `${this.cell.layoutInfo.rawOutputHeight}px`;
1614
- this._outputMetadataEditor = this.instantiationService.createInstance(DiffEditorWidget, this._outputMetadataContainer, {
1615
- ...fixedDiffEditorOptions,
1616
- overflowWidgetsDomNode: this.notebookEditor.getOverflowContainerDomNode(),
1617
- readOnly: true,
1618
- ignoreTrimWhitespace: false,
1619
- automaticLayout: false,
1620
- dimension: {
1621
- height: OUTPUT_EDITOR_HEIGHT_MAGIC,
1622
- width: this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), false, true)
1623
- }
1624
- }, {
1625
- originalEditor: getOptimizedNestedCodeEditorWidgetOptions(),
1626
- modifiedEditor: getOptimizedNestedCodeEditorWidgetOptions()
1627
- });
1628
- this._register(this._outputMetadataEditor);
1629
- const originalOutputMetadataSource = JSON.stringify(this.cell.original.outputs[0].metadata ?? {}, undefined, "\t");
1630
- const modifiedOutputMetadataSource = JSON.stringify(this.cell.modified.outputs[0].metadata ?? {}, undefined, "\t");
1631
- const mode = this.languageService.createById("json");
1632
- const originalModel = this.modelService.createModel(originalOutputMetadataSource, mode, undefined, true);
1633
- const modifiedModel = this.modelService.createModel(modifiedOutputMetadataSource, mode, undefined, true);
1634
- this._outputMetadataEditor.setModel({
1635
- original: originalModel,
1636
- modified: modifiedModel
1637
- });
1638
- this.cell.outputMetadataHeight = this._outputMetadataEditor.getContentHeight();
1639
- this._register(this._outputMetadataEditor.onDidContentSizeChange(e => {
1640
- this.cell.outputMetadataHeight = e.contentHeight;
1641
- }));
1642
- }
1643
- }
1644
- this._outputViewContainer.style.display = "block";
1645
- }
1646
- _decorate() {
1647
- if (this.cell.checkIfOutputsModified()) {
1648
- this.notebookEditor.deltaCellOutputContainerClassNames(DiffSide.Original, this.cell.original.id, ["nb-cellDeleted"], []);
1649
- this.notebookEditor.deltaCellOutputContainerClassNames(DiffSide.Modified, this.cell.modified.id, ["nb-cellAdded"], []);
1650
- } else {
1651
- this.notebookEditor.deltaCellOutputContainerClassNames(DiffSide.Original, this.cell.original.id, [], ["nb-cellDeleted"]);
1652
- this.notebookEditor.deltaCellOutputContainerClassNames(DiffSide.Modified, this.cell.modified.id, [], ["nb-cellAdded"]);
1653
- }
1654
- }
1655
- _showOutputsRenderer() {
1656
- if (this._outputViewContainer) {
1657
- this._outputViewContainer.style.display = "block";
1658
- this._outputLeftView?.showOutputs();
1659
- this._outputRightView?.showOutputs();
1660
- this._outputMetadataEditor?.layout({
1661
- width: this._editor?.getViewWidth() || this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), false, true),
1662
- height: this.cell.layoutInfo.outputMetadataHeight
1663
- });
1664
- this._decorate();
1665
- }
1666
- }
1667
- _hideOutputsRenderer() {
1668
- if (this._outputViewContainer) {
1669
- this._outputViewContainer.style.display = "none";
1670
- this._outputLeftView?.hideOutputs();
1671
- this._outputRightView?.hideOutputs();
1672
- }
1673
- }
1674
- updateSourceEditor() {
1675
- this._cellHeaderContainer = this.templateData.cellHeaderContainer;
1676
- this._cellHeaderContainer.style.display = "flex";
1677
- this._cellHeaderContainer.innerText = "";
1678
- const modifiedCell = this.cell.modified;
1679
- this._editorContainer = this.templateData.editorContainer;
1680
- this._editorContainer.classList.add("diff");
1681
- const renderSourceEditor = () => {
1682
- if (this.cell.cellFoldingState === PropertyFoldingState.Collapsed) {
1683
- this._editorContainer.style.display = "none";
1684
- this.cell.editorHeight = 0;
1685
- return;
1686
- }
1687
- const lineCount = modifiedCell.textModel.textBuffer.getLineCount();
1688
- const lineHeight = this.notebookEditor.getLayoutInfo().fontInfo.lineHeight || 17;
1689
- const editorHeight = this.cell.layoutInfo.editorHeight !== 0 ? this.cell.layoutInfo.editorHeight : this.cell.computeInputEditorHeight(lineHeight);
1690
- this._editorContainer.style.height = `${editorHeight}px`;
1691
- this._editorContainer.style.display = "block";
1692
- if (this._editor) {
1693
- const contentHeight = this._editor.getContentHeight();
1694
- if (contentHeight >= 0) {
1695
- this.cell.editorHeight = contentHeight;
1696
- }
1697
- return;
1698
- }
1699
- this._editor = this.templateData.sourceEditor;
1700
- const options = {
1701
- padding: getEditorPadding(lineCount)
1702
- };
1703
- const unchangedRegions = this._register(getUnchangedRegionSettings(this.configurationService));
1704
- if (unchangedRegions.options.enabled) {
1705
- options.hideUnchangedRegions = unchangedRegions.options;
1706
- }
1707
- this._editor.updateOptions(options);
1708
- this._register(unchangedRegions.onDidChangeEnablement(() => {
1709
- options.hideUnchangedRegions = unchangedRegions.options;
1710
- this._editor?.updateOptions(options);
1711
- }));
1712
- this._editor.layout({
1713
- width: this.notebookEditor.getLayoutInfo().width - 2 * DIFF_CELL_MARGIN,
1714
- height: editorHeight
1715
- });
1716
- this._register(this._editor.onDidContentSizeChange(e => {
1717
- if (this.cell.cellFoldingState === PropertyFoldingState.Expanded && e.contentHeightChanged && this.cell.layoutInfo.editorHeight !== e.contentHeight) {
1718
- this.cell.editorHeight = e.contentHeight;
1719
- }
1720
- }));
1721
- this._initializeSourceDiffEditor();
1722
- };
1723
- this._cellHeader = this._register(this.instantiationService.createInstance(
1724
- PropertyHeader,
1725
- this.cell,
1726
- this._cellHeaderContainer,
1727
- this.notebookEditor,
1728
- {
1729
- updateInfoRendering: () => renderSourceEditor(),
1730
- checkIfModified: () => {
1731
- return this.cell.modified?.textModel.getTextBufferHash() !== this.cell.original?.textModel.getTextBufferHash() ? {
1732
- reason: undefined
1733
- } : false;
1734
- },
1735
- getFoldingState: () => this.cell.cellFoldingState,
1736
- updateFoldingState: state => this.cell.cellFoldingState = state,
1737
- unChangedLabel: "Input",
1738
- changedLabel: "Input changed",
1739
- prefix: "input",
1740
- menuId: MenuId.NotebookDiffCellInputTitle
1741
- }
1742
- ));
1743
- this._cellHeader.buildHeader();
1744
- renderSourceEditor();
1745
- const scopedContextKeyService = this.contextKeyService.createScoped(this.templateData.inputToolbarContainer);
1746
- this._register(scopedContextKeyService);
1747
- const inputChanged = NOTEBOOK_DIFF_CELL_INPUT.bindTo(scopedContextKeyService);
1748
- inputChanged.set(
1749
- this.cell.modified.textModel.getTextBufferHash() !== this.cell.original.textModel.getTextBufferHash()
1750
- );
1751
- const ignoreWhitespace = NOTEBOOK_DIFF_CELL_IGNORE_WHITESPACE.bindTo(scopedContextKeyService);
1752
- const ignore = this.textConfigurationService.getValue(this.cell.modified.uri, "diffEditor.ignoreTrimWhitespace");
1753
- ignoreWhitespace.set(ignore);
1754
- this._toolbar = this.templateData.toolbar;
1755
- this._toolbar.context = this.cell;
1756
- const refreshToolbar = () => {
1757
- const ignore = this.textConfigurationService.getValue(this.cell.modified.uri, "diffEditor.ignoreTrimWhitespace");
1758
- ignoreWhitespace.set(ignore);
1759
- const hasChanges = this.cell.modified.textModel.getTextBufferHash() !== this.cell.original.textModel.getTextBufferHash();
1760
- inputChanged.set(hasChanges);
1761
- if (hasChanges) {
1762
- const menu = this.menuService.getMenuActions(MenuId.NotebookDiffCellInputTitle, scopedContextKeyService, {
1763
- shouldForwardArgs: true
1764
- });
1765
- const actions = getFlatActionBarActions(menu);
1766
- this._toolbar.setActions(actions);
1767
- } else {
1768
- this._toolbar.setActions([]);
1769
- }
1770
- };
1771
- this._register(this.cell.modified.textModel.onDidChangeContent(() => refreshToolbar()));
1772
- this._register(this.textConfigurationService.onDidChangeConfiguration(e => {
1773
- if (e.affectsConfiguration(this.cell.modified.uri, "diffEditor") && ( e.affectedKeys.has("diffEditor.ignoreTrimWhitespace"))) {
1774
- refreshToolbar();
1775
- }
1776
- }));
1777
- refreshToolbar();
1778
- }
1779
- async _initializeSourceDiffEditor() {
1780
- const [originalRef, modifiedRef] = await Promise.all([
1781
- this.textModelService.createModelReference(this.cell.original.uri),
1782
- this.textModelService.createModelReference(this.cell.modified.uri)
1783
- ]);
1784
- this._register(originalRef);
1785
- this._register(modifiedRef);
1786
- if (this._isDisposed) {
1787
- originalRef.dispose();
1788
- modifiedRef.dispose();
1789
- return;
1790
- }
1791
- const vm = this._register(this._editor.createViewModel({
1792
- original: originalRef.object.textEditorModel,
1793
- modified: modifiedRef.object.textEditorModel
1794
- }));
1795
- await vm.waitForDiff();
1796
- this._editor.setModel(vm);
1797
- const handleViewStateChange = () => {
1798
- this._editorViewStateChanged = true;
1799
- };
1800
- const handleScrollChange = e => {
1801
- if (e.scrollTopChanged || e.scrollLeftChanged) {
1802
- this._editorViewStateChanged = true;
1803
- }
1804
- };
1805
- this.updateEditorOptionsForWhitespace();
1806
- this._register(
1807
- this._editor.getOriginalEditor().onDidChangeCursorSelection(handleViewStateChange)
1808
- );
1809
- this._register(this._editor.getOriginalEditor().onDidScrollChange(handleScrollChange));
1810
- this._register(
1811
- this._editor.getModifiedEditor().onDidChangeCursorSelection(handleViewStateChange)
1812
- );
1813
- this._register(this._editor.getModifiedEditor().onDidScrollChange(handleScrollChange));
1814
- const editorViewState = this.cell.getSourceEditorViewState();
1815
- if (editorViewState) {
1816
- this._editor.restoreViewState(editorViewState);
1817
- }
1818
- const contentHeight = this._editor.getContentHeight();
1819
- this.cell.editorHeight = contentHeight;
1820
- }
1821
- updateEditorOptionsForWhitespace() {
1822
- const editor = this._editor;
1823
- if (!editor) {
1824
- return;
1825
- }
1826
- const uri = editor.getModel()?.modified.uri || editor.getModel()?.original.uri;
1827
- if (!uri) {
1828
- return;
1829
- }
1830
- const ignoreTrimWhitespace = this.textConfigurationService.getValue(uri, "diffEditor.ignoreTrimWhitespace");
1831
- editor.updateOptions({
1832
- ignoreTrimWhitespace
1833
- });
1834
- this._register(this.textConfigurationService.onDidChangeConfiguration(e => {
1835
- if (e.affectsConfiguration(uri, "diffEditor") && ( e.affectedKeys.has("diffEditor.ignoreTrimWhitespace"))) {
1836
- const ignoreTrimWhitespace = this.textConfigurationService.getValue(uri, "diffEditor.ignoreTrimWhitespace");
1837
- editor.updateOptions({
1838
- ignoreTrimWhitespace
1839
- });
1840
- }
1841
- }));
1842
- }
1843
- layout(state) {
1844
- scheduleAtNextAnimationFrame(getWindow(this._diffEditorContainer), () => {
1845
- if (state.editorHeight && this._editor) {
1846
- this._editorContainer.style.height = `${this.cell.layoutInfo.editorHeight}px`;
1847
- this._editor.layout({
1848
- width: this._editor.getViewWidth(),
1849
- height: this.cell.layoutInfo.editorHeight
1850
- });
1851
- }
1852
- if (state.outerWidth && this._editor) {
1853
- this._editorContainer.style.height = `${this.cell.layoutInfo.editorHeight}px`;
1854
- this._editor.layout();
1855
- }
1856
- if (state.metadataHeight || state.outerWidth) {
1857
- if (this._metadataEditorContainer) {
1858
- this._metadataEditorContainer.style.height = `${this.cell.layoutInfo.metadataHeight}px`;
1859
- this._metadataEditor?.layout({
1860
- width: this._editor?.getViewWidth() || this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), false, true),
1861
- height: this.cell.layoutInfo.metadataHeight
1862
- });
1863
- }
1864
- }
1865
- if (state.outputTotalHeight || state.outerWidth) {
1866
- if (this._outputEditorContainer) {
1867
- this._outputEditorContainer.style.height = `${this.cell.layoutInfo.outputTotalHeight}px`;
1868
- this._outputEditor?.layout({
1869
- width: this._editor?.getViewWidth() || this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), false, true),
1870
- height: this.cell.layoutInfo.outputTotalHeight
1871
- });
1872
- }
1873
- if (this._outputMetadataContainer) {
1874
- this._outputMetadataContainer.style.height = `${this.cell.layoutInfo.outputMetadataHeight}px`;
1875
- this._outputMetadataContainer.style.top = `${this.cell.layoutInfo.outputTotalHeight - this.cell.layoutInfo.outputMetadataHeight}px`;
1876
- this._outputMetadataEditor?.layout({
1877
- width: this._editor?.getViewWidth() || this.cell.getComputedCellContainerWidth(this.notebookEditor.getLayoutInfo(), false, true),
1878
- height: this.cell.layoutInfo.outputMetadataHeight
1879
- });
1880
- }
1881
- }
1882
- this.layoutNotebookCell();
1883
- });
1884
- }
1885
- dispose() {
1886
- if (this._editor) {
1887
- this._editor.setModel(null);
1888
- }
1889
- if (this._editor && this._editorViewStateChanged) {
1890
- this.cell.saveSpirceEditorViewState(this._editor.saveViewState());
1891
- }
1892
- super.dispose();
1893
- }
1894
- };
1895
- ModifiedElement = ( __decorate([( __param(3, IInstantiationService)), ( __param(4, ILanguageService)), ( __param(5, IModelService)), ( __param(6, ITextModelService)), ( __param(7, IContextMenuService)), ( __param(8, IKeybindingService)), ( __param(9, INotificationService)), ( __param(10, IMenuService)), ( __param(11, IContextKeyService)), ( __param(12, IConfigurationService)), ( __param(13, ITextResourceConfigurationService))], ModifiedElement));
1896
- class CollapsedCellOverlayWidget extends Disposable {
1897
- constructor(container) {
1898
- super();
1899
- this.container = container;
1900
- this._nodes = h("div.diff-hidden-cells", [h("div.center@content", {
1901
- style: {
1902
- display: "flex"
1903
- }
1904
- }, [$("a", {
1905
- title: ( localize(11790, "Show Unchanged Cells")),
1906
- role: "button",
1907
- onclick: () => {
1908
- this._action.fire();
1909
- }
1910
- }, ...renderLabelWithIcons("$(unfold)"))])]);
1911
- this._action = this._register(( new Emitter()));
1912
- this.onAction = this._action.event;
1913
- this._nodes.root.style.display = "none";
1914
- container.appendChild(this._nodes.root);
1915
- }
1916
- show() {
1917
- this._nodes.root.style.display = "block";
1918
- }
1919
- hide() {
1920
- this._nodes.root.style.display = "none";
1921
- }
1922
- dispose() {
1923
- this.hide();
1924
- this.container.removeChild(this._nodes.root);
1925
- reset(this._nodes.root);
1926
- super.dispose();
1927
- }
1928
- }
1929
- class UnchangedCellOverlayWidget extends Disposable {
1930
- constructor(container) {
1931
- super();
1932
- this.container = container;
1933
- this._nodes = h("div.diff-hidden-cells", [h("div.center@content", {
1934
- style: {
1935
- display: "flex"
1936
- }
1937
- }, [$("a", {
1938
- title: ( localize(11791, "Hide Unchanged Cells")),
1939
- role: "button",
1940
- onclick: () => {
1941
- this._action.fire();
1942
- }
1943
- }, ...renderLabelWithIcons("$(fold)"))])]);
1944
- this._action = this._register(( new Emitter()));
1945
- this.onAction = this._action.event;
1946
- this._nodes.root.style.display = "none";
1947
- container.appendChild(this._nodes.root);
1948
- }
1949
- show() {
1950
- this._nodes.root.style.display = "block";
1951
- }
1952
- hide() {
1953
- this._nodes.root.style.display = "none";
1954
- }
1955
- dispose() {
1956
- this.hide();
1957
- this.container.removeChild(this._nodes.root);
1958
- reset(this._nodes.root);
1959
- super.dispose();
1960
- }
1961
- }
1962
-
1963
- export { CellDiffPlaceholderElement, CollapsedCellOverlayWidget, DeletedElement, InsertElement, ModifiedElement, NotebookDocumentMetadataElement, UnchangedCellOverlayWidget, getOptimizedNestedCodeEditorWidgetOptions };