@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.
Files changed (84) hide show
  1. package/external/rollup-plugin-styles/dist/runtime/inject-css.js +3 -0
  2. package/external/tslib/tslib.es6.js +11 -0
  3. package/index.d.ts +1 -0
  4. package/index.js +1 -0
  5. package/notebook.d.ts +5 -0
  6. package/notebook.js +44 -0
  7. package/override/vs/platform/dialogs/common/dialogs.js +8 -0
  8. package/package.json +32 -0
  9. package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.css.js +6 -0
  10. package/vscode/src/vs/workbench/contrib/codeEditor/browser/emptyTextEditorHint/emptyTextEditorHint.js +387 -0
  11. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellCommands/cellCommands.js +668 -0
  12. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/contributedStatusBarItemController.js +109 -0
  13. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/executionStatusBarItemController.js +319 -0
  14. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/notebookVisibleCellObserver.js +58 -0
  15. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/cellStatusBar/statusBarProviders.js +173 -0
  16. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard.js +485 -0
  17. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookBreakpoints.js +106 -0
  18. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookCellPausing.js +67 -0
  19. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/debug/notebookDebugDecorations.js +165 -0
  20. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/editorHint/emptyCellEditorHint.js +67 -0
  21. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/editorStatusBar/editorStatusBar.js +238 -0
  22. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/execute/executionEditorProgress.js +72 -0
  23. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/media/notebookFind.css.js +6 -0
  24. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFind.js +168 -0
  25. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget.js +317 -0
  26. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/format/formatting.js +209 -0
  27. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/gettingStarted/notebookGettingStarted.js +87 -0
  28. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/kernelDetection/notebookKernelDetection.js +82 -0
  29. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/layout/layoutActions.js +67 -0
  30. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider.js +93 -0
  31. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/navigation/arrow.js +383 -0
  32. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariables.js +51 -0
  33. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesTree.js +46 -0
  34. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.js +135 -0
  35. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline.js +383 -0
  36. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/profile/notebookProfile.js +117 -0
  37. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/saveParticipants/saveParticipants.js +511 -0
  38. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout.js +168 -0
  39. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/undoRedo/notebookUndoRedo.js +57 -0
  40. package/vscode/src/vs/workbench/contrib/notebook/browser/contrib/viewportWarmup/viewportWarmup.js +94 -0
  41. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/apiActions.js +51 -0
  42. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/executeActions.js +702 -0
  43. package/vscode/src/vs/workbench/contrib/notebook/browser/controller/layoutActions.js +268 -0
  44. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffCellEditorOptions.js +45 -0
  45. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffComponents.js +1297 -0
  46. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementOutputs.js +284 -0
  47. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.js +563 -0
  48. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel.js +108 -0
  49. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/eventDispatcher.js +39 -0
  50. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiff.css.js +6 -0
  51. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffActions.js +313 -0
  52. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.js +872 -0
  53. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser.js +13 -0
  54. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffList.js +393 -0
  55. package/vscode/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffOverviewRuler.js +175 -0
  56. package/vscode/src/vs/workbench/contrib/notebook/browser/notebook.contribution.js +1121 -0
  57. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookAccessibility.js +159 -0
  58. package/vscode/src/vs/workbench/contrib/notebook/browser/notebookExtensionPoint.js +339 -0
  59. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookCellStatusBarServiceImpl.js +41 -0
  60. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookEditorServiceImpl.js +182 -0
  61. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionServiceImpl.js +106 -0
  62. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookExecutionStateServiceImpl.js +509 -0
  63. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelHistoryServiceImpl.js +133 -0
  64. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl.js +342 -0
  65. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookKeymapServiceImpl.js +111 -0
  66. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookLoggingServiceImpl.js +28 -0
  67. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookRendererMessagingServiceImpl.js +65 -0
  68. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookServiceImpl.js +666 -0
  69. package/vscode/src/vs/workbench/contrib/notebook/browser/services/notebookWorkerServiceImpl.js +200 -0
  70. package/vscode/src/vs/workbench/contrib/notebook/common/model/cellEdit.js +80 -0
  71. package/vscode/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.js +1001 -0
  72. package/vscode/src/vs/workbench/contrib/notebook/common/notebookDiffEditorInput.js +103 -0
  73. package/vscode/src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverServiceImpl.js +202 -0
  74. package/vscode/src/vs/workbench/contrib/notebook/common/notebookOutputRenderer.js +80 -0
  75. package/vscode/src/vs/workbench/contrib/notebook/common/notebookProvider.js +98 -0
  76. package/vscode/src/vs/workbench/contrib/notebook/common/services/notebookSimpleWorker.js +217 -0
  77. package/vscode/src/vs/workbench/services/workingCopy/common/abstractFileWorkingCopyManager.js +89 -0
  78. package/vscode/src/vs/workbench/services/workingCopy/common/fileWorkingCopyManager.js +372 -0
  79. package/vscode/src/vs/workbench/services/workingCopy/common/storedFileWorkingCopy.js +706 -0
  80. package/vscode/src/vs/workbench/services/workingCopy/common/storedFileWorkingCopyManager.js +407 -0
  81. package/vscode/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopy.js +144 -0
  82. package/vscode/src/vs/workbench/services/workingCopy/common/untitledFileWorkingCopyManager.js +129 -0
  83. package/worker.js +1 -0
  84. package/workers/notebook.worker.js +9 -0
@@ -0,0 +1,485 @@
1
+ import { __decorate, __param } from '../../../../../../../../../external/tslib/tslib.es6.js';
2
+ import { localizeWithPath } from 'monaco-editor/esm/vs/nls.js';
3
+ import { Disposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
4
+ import { Registry } from 'monaco-editor/esm/vs/platform/registry/common/platform.js';
5
+ import { Extensions } from 'vscode/vscode/vs/workbench/common/contributions';
6
+ import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
7
+ import { NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_CELL_EDITABLE } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookContextKeys';
8
+ import { expandCellRangesWithHiddenCells, cellRangeToViewCells, getNotebookEditorFromEditorPane } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser';
9
+ import { CopyAction, PasteAction, CutAction } from 'monaco-editor/esm/vs/editor/contrib/clipboard/browser/clipboard.js';
10
+ import { IClipboardService } from 'monaco-editor/esm/vs/platform/clipboard/common/clipboardService.js';
11
+ import { cloneNotebookCellTextModel } from 'vscode/vscode/vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
12
+ import { SelectionStateType } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
13
+ import { INotebookService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookService';
14
+ import * as platform from 'monaco-editor/esm/vs/base/common/platform.js';
15
+ import { registerAction2, MenuId, Action2 } from 'monaco-editor/esm/vs/platform/actions/common/actions.js';
16
+ import { NotebookCellAction, NotebookAction, NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/controller/coreActions';
17
+ import { ContextKeyExpr } from 'monaco-editor/esm/vs/platform/contextkey/common/contextkey.js';
18
+ import { InputFocusedContextKey } from 'monaco-editor/esm/vs/platform/contextkey/common/contextkeys.js';
19
+ import { UndoCommand, RedoCommand } from 'monaco-editor/esm/vs/editor/browser/editorExtensions.js';
20
+ import { Categories } from 'monaco-editor/esm/vs/platform/action/common/actionCommonCategories.js';
21
+ import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
22
+ import { ICommandService } from 'monaco-editor/esm/vs/platform/commands/common/commands.js';
23
+ import { showWindowLogActionId } from 'vscode/vscode/vs/workbench/services/log/common/logConstants';
24
+ import { getWindow, getActiveElement } from 'monaco-editor/esm/vs/base/browser/dom.js';
25
+
26
+ let _logging = false;
27
+ function toggleLogging() {
28
+ _logging = !_logging;
29
+ }
30
+ function _log(loggerService, str) {
31
+ if (_logging) {
32
+ loggerService.info(`[NotebookClipboard]: ${str}`);
33
+ }
34
+ }
35
+ function getFocusedWebviewDelegate(accessor) {
36
+ const loggerService = accessor.get(ILogService);
37
+ const editorService = accessor.get(IEditorService);
38
+ const editor = getNotebookEditorFromEditorPane(editorService.activeEditorPane);
39
+ if (!editor) {
40
+ _log(loggerService, '[Revive Webview] No notebook editor found for active editor pane, bypass');
41
+ return;
42
+ }
43
+ if (!editor.hasEditorFocus()) {
44
+ _log(loggerService, '[Revive Webview] Notebook editor is not focused, bypass');
45
+ return;
46
+ }
47
+ if (!editor.hasWebviewFocus()) {
48
+ _log(loggerService, '[Revive Webview] Notebook editor backlayer webview is not focused, bypass');
49
+ return;
50
+ }
51
+ const webview = editor.getInnerWebview();
52
+ _log(loggerService, '[Revive Webview] Notebook editor backlayer webview is focused');
53
+ return webview;
54
+ }
55
+ function withWebview(accessor, f) {
56
+ const webview = getFocusedWebviewDelegate(accessor);
57
+ if (webview) {
58
+ f(webview);
59
+ return true;
60
+ }
61
+ return false;
62
+ }
63
+ const PRIORITY = 105;
64
+ UndoCommand.addImplementation(PRIORITY, 'notebook-webview', accessor => {
65
+ return withWebview(accessor, webview => webview.undo());
66
+ });
67
+ RedoCommand.addImplementation(PRIORITY, 'notebook-webview', accessor => {
68
+ return withWebview(accessor, webview => webview.redo());
69
+ });
70
+ CopyAction?.addImplementation(PRIORITY, 'notebook-webview', accessor => {
71
+ return withWebview(accessor, webview => webview.copy());
72
+ });
73
+ PasteAction?.addImplementation(PRIORITY, 'notebook-webview', accessor => {
74
+ return withWebview(accessor, webview => webview.paste());
75
+ });
76
+ CutAction?.addImplementation(PRIORITY, 'notebook-webview', accessor => {
77
+ return withWebview(accessor, webview => webview.cut());
78
+ });
79
+ function runPasteCells(editor, activeCell, pasteCells) {
80
+ if (!editor.hasModel()) {
81
+ return false;
82
+ }
83
+ const textModel = editor.textModel;
84
+ if (editor.isReadOnly) {
85
+ return false;
86
+ }
87
+ const originalState = {
88
+ kind: SelectionStateType.Index,
89
+ focus: editor.getFocus(),
90
+ selections: editor.getSelections()
91
+ };
92
+ if (activeCell) {
93
+ const currCellIndex = editor.getCellIndex(activeCell);
94
+ const newFocusIndex = typeof currCellIndex === 'number' ? currCellIndex + 1 : 0;
95
+ textModel.applyEdits([
96
+ {
97
+ editType: 1 ,
98
+ index: newFocusIndex,
99
+ count: 0,
100
+ cells: ( pasteCells.items.map(cell => cloneNotebookCellTextModel(cell)))
101
+ }
102
+ ], true, originalState, () => ({
103
+ kind: SelectionStateType.Index,
104
+ focus: { start: newFocusIndex, end: newFocusIndex + 1 },
105
+ selections: [{ start: newFocusIndex, end: newFocusIndex + pasteCells.items.length }]
106
+ }), undefined, true);
107
+ }
108
+ else {
109
+ if (editor.getLength() !== 0) {
110
+ return false;
111
+ }
112
+ textModel.applyEdits([
113
+ {
114
+ editType: 1 ,
115
+ index: 0,
116
+ count: 0,
117
+ cells: ( pasteCells.items.map(cell => cloneNotebookCellTextModel(cell)))
118
+ }
119
+ ], true, originalState, () => ({
120
+ kind: SelectionStateType.Index,
121
+ focus: { start: 0, end: 1 },
122
+ selections: [{ start: 1, end: pasteCells.items.length + 1 }]
123
+ }), undefined, true);
124
+ }
125
+ return true;
126
+ }
127
+ function runCopyCells(accessor, editor, targetCell) {
128
+ if (!editor.hasModel()) {
129
+ return false;
130
+ }
131
+ if (editor.hasOutputTextSelection()) {
132
+ getWindow(editor.getDomNode()).document.execCommand('copy');
133
+ return true;
134
+ }
135
+ const clipboardService = accessor.get(IClipboardService);
136
+ const notebookService = accessor.get(INotebookService);
137
+ const selections = editor.getSelections();
138
+ if (targetCell) {
139
+ const targetCellIndex = editor.getCellIndex(targetCell);
140
+ const containingSelection = selections.find(selection => selection.start <= targetCellIndex && targetCellIndex < selection.end);
141
+ if (!containingSelection) {
142
+ clipboardService.writeText(targetCell.getText());
143
+ notebookService.setToCopy([targetCell.model], true);
144
+ return true;
145
+ }
146
+ }
147
+ const selectionRanges = expandCellRangesWithHiddenCells(editor, editor.getSelections());
148
+ const selectedCells = cellRangeToViewCells(editor, selectionRanges);
149
+ if (!selectedCells.length) {
150
+ return false;
151
+ }
152
+ clipboardService.writeText(( selectedCells.map(cell => cell.getText())).join('\n'));
153
+ notebookService.setToCopy(( selectedCells.map(cell => cell.model)), true);
154
+ return true;
155
+ }
156
+ function runCutCells(accessor, editor, targetCell) {
157
+ if (!editor.hasModel() || editor.isReadOnly) {
158
+ return false;
159
+ }
160
+ const textModel = editor.textModel;
161
+ const clipboardService = accessor.get(IClipboardService);
162
+ const notebookService = accessor.get(INotebookService);
163
+ const selections = editor.getSelections();
164
+ if (targetCell) {
165
+ const targetCellIndex = editor.getCellIndex(targetCell);
166
+ const containingSelection = selections.find(selection => selection.start <= targetCellIndex && targetCellIndex < selection.end);
167
+ if (!containingSelection) {
168
+ clipboardService.writeText(targetCell.getText());
169
+ const focus = editor.getFocus();
170
+ const newFocus = focus.end <= targetCellIndex ? focus : { start: focus.start - 1, end: focus.end - 1 };
171
+ const newSelections = ( selections.map(
172
+ selection => (selection.end <= targetCellIndex ? selection : { start: selection.start - 1, end: selection.end - 1 })
173
+ ));
174
+ textModel.applyEdits([
175
+ { editType: 1 , index: targetCellIndex, count: 1, cells: [] }
176
+ ], true, { kind: SelectionStateType.Index, focus: editor.getFocus(), selections: selections }, () => ({ kind: SelectionStateType.Index, focus: newFocus, selections: newSelections }), undefined, true);
177
+ notebookService.setToCopy([targetCell.model], false);
178
+ return true;
179
+ }
180
+ }
181
+ const focus = editor.getFocus();
182
+ const containingSelection = selections.find(selection => selection.start <= focus.start && focus.end <= selection.end);
183
+ if (!containingSelection) {
184
+ const targetCell = editor.cellAt(focus.start);
185
+ clipboardService.writeText(targetCell.getText());
186
+ const newFocus = focus.end === editor.getLength() ? { start: focus.start - 1, end: focus.end - 1 } : focus;
187
+ const newSelections = ( selections.map(
188
+ selection => (selection.end <= focus.start ? selection : { start: selection.start - 1, end: selection.end - 1 })
189
+ ));
190
+ textModel.applyEdits([
191
+ { editType: 1 , index: focus.start, count: 1, cells: [] }
192
+ ], true, { kind: SelectionStateType.Index, focus: editor.getFocus(), selections: selections }, () => ({ kind: SelectionStateType.Index, focus: newFocus, selections: newSelections }), undefined, true);
193
+ notebookService.setToCopy([targetCell.model], false);
194
+ return true;
195
+ }
196
+ const selectionRanges = expandCellRangesWithHiddenCells(editor, editor.getSelections());
197
+ const selectedCells = cellRangeToViewCells(editor, selectionRanges);
198
+ if (!selectedCells.length) {
199
+ return false;
200
+ }
201
+ clipboardService.writeText(( selectedCells.map(cell => cell.getText())).join('\n'));
202
+ const edits = ( selectionRanges.map(
203
+ range => ({ editType: 1 , index: range.start, count: range.end - range.start, cells: [] })
204
+ ));
205
+ const firstSelectIndex = selectionRanges[0].start;
206
+ const newFocusedCellIndex = firstSelectIndex < textModel.cells.length - 1
207
+ ? firstSelectIndex
208
+ : Math.max(textModel.cells.length - 2, 0);
209
+ textModel.applyEdits(edits, true, { kind: SelectionStateType.Index, focus: editor.getFocus(), selections: selectionRanges }, () => {
210
+ return {
211
+ kind: SelectionStateType.Index,
212
+ focus: { start: newFocusedCellIndex, end: newFocusedCellIndex + 1 },
213
+ selections: [{ start: newFocusedCellIndex, end: newFocusedCellIndex + 1 }]
214
+ };
215
+ }, undefined, true);
216
+ notebookService.setToCopy(( selectedCells.map(cell => cell.model)), false);
217
+ return true;
218
+ }
219
+ let NotebookClipboardContribution = class NotebookClipboardContribution extends Disposable {
220
+ constructor(_editorService) {
221
+ super();
222
+ this._editorService = _editorService;
223
+ const PRIORITY = 105;
224
+ if (CopyAction) {
225
+ this._register(CopyAction.addImplementation(PRIORITY, 'notebook-clipboard', accessor => {
226
+ return this.runCopyAction(accessor);
227
+ }));
228
+ }
229
+ if (PasteAction) {
230
+ this._register(PasteAction.addImplementation(PRIORITY, 'notebook-clipboard', accessor => {
231
+ return this.runPasteAction(accessor);
232
+ }));
233
+ }
234
+ if (CutAction) {
235
+ this._register(CutAction.addImplementation(PRIORITY, 'notebook-clipboard', accessor => {
236
+ return this.runCutAction(accessor);
237
+ }));
238
+ }
239
+ }
240
+ _getContext() {
241
+ const editor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane);
242
+ const activeCell = editor?.getActiveCell();
243
+ return {
244
+ editor,
245
+ activeCell
246
+ };
247
+ }
248
+ _focusInsideEmebedMonaco(editor) {
249
+ const windowSelection = getWindow(editor.getDomNode()).getSelection();
250
+ if (windowSelection?.rangeCount !== 1) {
251
+ return false;
252
+ }
253
+ const activeSelection = windowSelection.getRangeAt(0);
254
+ if (activeSelection.startContainer === activeSelection.endContainer && activeSelection.endOffset - activeSelection.startOffset === 0) {
255
+ return false;
256
+ }
257
+ let container = activeSelection.commonAncestorContainer;
258
+ const body = editor.getDomNode();
259
+ if (!body.contains(container)) {
260
+ return false;
261
+ }
262
+ while (container
263
+ &&
264
+ container !== body) {
265
+ if (container.classList && container.classList.contains('monaco-editor')) {
266
+ return true;
267
+ }
268
+ container = container.parentNode;
269
+ }
270
+ return false;
271
+ }
272
+ runCopyAction(accessor) {
273
+ const loggerService = accessor.get(ILogService);
274
+ const activeElement = getActiveElement();
275
+ if (activeElement && ['input', 'textarea'].indexOf(activeElement.tagName.toLowerCase()) >= 0) {
276
+ _log(loggerService, '[NotebookEditor] focus is on input or textarea element, bypass');
277
+ return false;
278
+ }
279
+ const { editor } = this._getContext();
280
+ if (!editor) {
281
+ _log(loggerService, '[NotebookEditor] no active notebook editor, bypass');
282
+ return false;
283
+ }
284
+ if (this._focusInsideEmebedMonaco(editor)) {
285
+ _log(loggerService, '[NotebookEditor] focus is on embed monaco editor, bypass');
286
+ return false;
287
+ }
288
+ _log(loggerService, '[NotebookEditor] run copy actions on notebook model');
289
+ return runCopyCells(accessor, editor, undefined);
290
+ }
291
+ runPasteAction(accessor) {
292
+ const activeElement = getActiveElement();
293
+ if (activeElement && ['input', 'textarea'].indexOf(activeElement.tagName.toLowerCase()) >= 0) {
294
+ return false;
295
+ }
296
+ const notebookService = accessor.get(INotebookService);
297
+ const pasteCells = notebookService.getToCopy();
298
+ if (!pasteCells) {
299
+ return false;
300
+ }
301
+ const { editor, activeCell } = this._getContext();
302
+ if (!editor) {
303
+ return false;
304
+ }
305
+ return runPasteCells(editor, activeCell, pasteCells);
306
+ }
307
+ runCutAction(accessor) {
308
+ const activeElement = getActiveElement();
309
+ if (activeElement && ['input', 'textarea'].indexOf(activeElement.tagName.toLowerCase()) >= 0) {
310
+ return false;
311
+ }
312
+ const { editor } = this._getContext();
313
+ if (!editor) {
314
+ return false;
315
+ }
316
+ return runCutCells(accessor, editor, undefined);
317
+ }
318
+ };
319
+ NotebookClipboardContribution = ( __decorate([
320
+ ( __param(0, IEditorService))
321
+ ], NotebookClipboardContribution));
322
+ const workbenchContributionsRegistry = ( Registry.as(Extensions.Workbench));
323
+ workbenchContributionsRegistry.registerWorkbenchContribution(NotebookClipboardContribution, 2 );
324
+ const COPY_CELL_COMMAND_ID = 'notebook.cell.copy';
325
+ const CUT_CELL_COMMAND_ID = 'notebook.cell.cut';
326
+ const PASTE_CELL_COMMAND_ID = 'notebook.cell.paste';
327
+ const PASTE_CELL_ABOVE_COMMAND_ID = 'notebook.cell.pasteAbove';
328
+ registerAction2(class extends NotebookCellAction {
329
+ constructor() {
330
+ super({
331
+ id: COPY_CELL_COMMAND_ID,
332
+ title: ( localizeWithPath(
333
+ 'vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard',
334
+ 'notebookActions.copy',
335
+ "Copy Cell"
336
+ )),
337
+ menu: {
338
+ id: MenuId.NotebookCellTitle,
339
+ when: NOTEBOOK_EDITOR_FOCUSED,
340
+ group: "1_copy" ,
341
+ },
342
+ keybinding: platform.isNative ? undefined : {
343
+ primary: 2048 | 33 ,
344
+ win: { primary: 2048 | 33 , secondary: [2048 | 19 ] },
345
+ when: ( ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey))),
346
+ weight: 200
347
+ }
348
+ });
349
+ }
350
+ async runWithContext(accessor, context) {
351
+ runCopyCells(accessor, context.notebookEditor, context.cell);
352
+ }
353
+ });
354
+ registerAction2(class extends NotebookCellAction {
355
+ constructor() {
356
+ super({
357
+ id: CUT_CELL_COMMAND_ID,
358
+ title: ( localizeWithPath(
359
+ 'vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard',
360
+ 'notebookActions.cut',
361
+ "Cut Cell"
362
+ )),
363
+ menu: {
364
+ id: MenuId.NotebookCellTitle,
365
+ when: ( ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_CELL_EDITABLE)),
366
+ group: "1_copy" ,
367
+ },
368
+ keybinding: platform.isNative ? undefined : {
369
+ when: ( ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey))),
370
+ primary: 2048 | 54 ,
371
+ win: { primary: 2048 | 54 , secondary: [1024 | 20 ] },
372
+ weight: 200
373
+ }
374
+ });
375
+ }
376
+ async runWithContext(accessor, context) {
377
+ runCutCells(accessor, context.notebookEditor, context.cell);
378
+ }
379
+ });
380
+ registerAction2(class extends NotebookAction {
381
+ constructor() {
382
+ super({
383
+ id: PASTE_CELL_COMMAND_ID,
384
+ title: ( localizeWithPath(
385
+ 'vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard',
386
+ 'notebookActions.paste',
387
+ "Paste Cell"
388
+ )),
389
+ menu: {
390
+ id: MenuId.NotebookCellTitle,
391
+ when: ( ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_EDITABLE)),
392
+ group: "1_copy" ,
393
+ },
394
+ keybinding: platform.isNative ? undefined : {
395
+ when: ( ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey))),
396
+ primary: 2048 | 52 ,
397
+ win: { primary: 2048 | 52 , secondary: [1024 | 19 ] },
398
+ linux: { primary: 2048 | 52 , secondary: [1024 | 19 ] },
399
+ weight: 100
400
+ }
401
+ });
402
+ }
403
+ async runWithContext(accessor, context) {
404
+ const notebookService = accessor.get(INotebookService);
405
+ const pasteCells = notebookService.getToCopy();
406
+ if (!context.notebookEditor.hasModel() || context.notebookEditor.isReadOnly) {
407
+ return;
408
+ }
409
+ if (!pasteCells) {
410
+ return;
411
+ }
412
+ runPasteCells(context.notebookEditor, context.cell, pasteCells);
413
+ }
414
+ });
415
+ registerAction2(class extends NotebookCellAction {
416
+ constructor() {
417
+ super({
418
+ id: PASTE_CELL_ABOVE_COMMAND_ID,
419
+ title: ( localizeWithPath(
420
+ 'vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard',
421
+ 'notebookActions.pasteAbove',
422
+ "Paste Cell Above"
423
+ )),
424
+ keybinding: {
425
+ when: ( ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey))),
426
+ primary: 2048 | 1024 | 52 ,
427
+ weight: NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT
428
+ },
429
+ });
430
+ }
431
+ async runWithContext(accessor, context) {
432
+ const notebookService = accessor.get(INotebookService);
433
+ const pasteCells = notebookService.getToCopy();
434
+ const editor = context.notebookEditor;
435
+ const textModel = editor.textModel;
436
+ if (editor.isReadOnly) {
437
+ return;
438
+ }
439
+ if (!pasteCells) {
440
+ return;
441
+ }
442
+ const originalState = {
443
+ kind: SelectionStateType.Index,
444
+ focus: editor.getFocus(),
445
+ selections: editor.getSelections()
446
+ };
447
+ const currCellIndex = context.notebookEditor.getCellIndex(context.cell);
448
+ const newFocusIndex = currCellIndex;
449
+ textModel.applyEdits([
450
+ {
451
+ editType: 1 ,
452
+ index: currCellIndex,
453
+ count: 0,
454
+ cells: ( pasteCells.items.map(cell => cloneNotebookCellTextModel(cell)))
455
+ }
456
+ ], true, originalState, () => ({
457
+ kind: SelectionStateType.Index,
458
+ focus: { start: newFocusIndex, end: newFocusIndex + 1 },
459
+ selections: [{ start: newFocusIndex, end: newFocusIndex + pasteCells.items.length }]
460
+ }), undefined, true);
461
+ }
462
+ });
463
+ registerAction2(class extends Action2 {
464
+ constructor() {
465
+ super({
466
+ id: 'workbench.action.toggleNotebookClipboardLog',
467
+ title: { value: ( localizeWithPath(
468
+ 'vs/workbench/contrib/notebook/browser/contrib/clipboard/notebookClipboard',
469
+ 'toggleNotebookClipboardLog',
470
+ "Toggle Notebook Clipboard Troubleshooting"
471
+ )), original: 'Toggle Notebook Clipboard Troubleshooting' },
472
+ category: Categories.Developer,
473
+ f1: true
474
+ });
475
+ }
476
+ run(accessor) {
477
+ toggleLogging();
478
+ if (_logging) {
479
+ const commandService = accessor.get(ICommandService);
480
+ commandService.executeCommand(showWindowLogActionId);
481
+ }
482
+ }
483
+ });
484
+
485
+ export { NotebookClipboardContribution, runCopyCells, runCutCells, runPasteCells };
@@ -0,0 +1,106 @@
1
+ import { __decorate, __param } from '../../../../../../../../../external/tslib/tslib.es6.js';
2
+ import { Disposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
3
+ import { ResourceMap } from 'monaco-editor/esm/vs/base/common/map.js';
4
+ import { Schemas } from 'monaco-editor/esm/vs/base/common/network.js';
5
+ import { isEqual } from 'monaco-editor/esm/vs/base/common/resources.js';
6
+ import { Registry } from 'monaco-editor/esm/vs/platform/registry/common/platform.js';
7
+ import { Extensions } from 'vscode/vscode/vs/workbench/common/contributions';
8
+ import { IDebugService } from 'vscode/vscode/vs/workbench/contrib/debug/common/debug';
9
+ import { getNotebookEditorFromEditorPane } from 'vscode/vscode/vs/workbench/contrib/notebook/browser/notebookBrowser';
10
+ import { NotebookCellsChangeType, CellUri } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
11
+ import { INotebookService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookService';
12
+ import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
13
+
14
+ let NotebookBreakpoints = class NotebookBreakpoints extends Disposable {
15
+ constructor(_debugService, _notebookService, _editorService) {
16
+ super();
17
+ this._debugService = _debugService;
18
+ this._editorService = _editorService;
19
+ const listeners = ( new ResourceMap());
20
+ this._register(_notebookService.onWillAddNotebookDocument(model => {
21
+ listeners.set(model.uri, model.onWillAddRemoveCells(e => {
22
+ const debugModel = this._debugService.getModel();
23
+ if (!debugModel.getBreakpoints().length) {
24
+ return;
25
+ }
26
+ if (e.rawEvent.kind !== NotebookCellsChangeType.ModelChange) {
27
+ return;
28
+ }
29
+ for (const change of e.rawEvent.changes) {
30
+ const [start, deleteCount] = change;
31
+ if (deleteCount > 0) {
32
+ const deleted = model.cells.slice(start, start + deleteCount);
33
+ for (const deletedCell of deleted) {
34
+ const cellBps = debugModel.getBreakpoints({ uri: deletedCell.uri });
35
+ cellBps.forEach(cellBp => this._debugService.removeBreakpoints(cellBp.getId()));
36
+ }
37
+ }
38
+ }
39
+ }));
40
+ }));
41
+ this._register(_notebookService.onWillRemoveNotebookDocument(model => {
42
+ this.updateBreakpoints(model);
43
+ listeners.get(model.uri)?.dispose();
44
+ listeners.delete(model.uri);
45
+ }));
46
+ this._register(this._debugService.getModel().onDidChangeBreakpoints(e => {
47
+ const newCellBp = e?.added?.find(bp => 'uri' in bp && bp.uri.scheme === Schemas.vscodeNotebookCell);
48
+ if (newCellBp) {
49
+ const parsed = CellUri.parse(newCellBp.uri);
50
+ if (!parsed) {
51
+ return;
52
+ }
53
+ const editor = getNotebookEditorFromEditorPane(this._editorService.activeEditorPane);
54
+ if (!editor || !editor.hasModel() || ( editor.textModel.uri.toString()) !== ( parsed.notebook.toString())) {
55
+ return;
56
+ }
57
+ const cell = editor.getCellByHandle(parsed.handle);
58
+ if (!cell) {
59
+ return;
60
+ }
61
+ editor.focusElement(cell);
62
+ }
63
+ }));
64
+ }
65
+ updateBreakpoints(model) {
66
+ const bps = this._debugService.getModel().getBreakpoints();
67
+ if (!bps.length || !model.cells.length) {
68
+ return;
69
+ }
70
+ const idxMap = ( new ResourceMap());
71
+ model.cells.forEach((cell, i) => {
72
+ idxMap.set(cell.uri, i);
73
+ });
74
+ bps.forEach(bp => {
75
+ const idx = idxMap.get(bp.uri);
76
+ if (typeof idx !== 'number') {
77
+ return;
78
+ }
79
+ const notebook = CellUri.parse(bp.uri)?.notebook;
80
+ if (!notebook) {
81
+ return;
82
+ }
83
+ const newUri = CellUri.generate(notebook, idx);
84
+ if (isEqual(newUri, bp.uri)) {
85
+ return;
86
+ }
87
+ this._debugService.removeBreakpoints(bp.getId());
88
+ this._debugService.addBreakpoints(newUri, [
89
+ {
90
+ column: bp.column,
91
+ condition: bp.condition,
92
+ enabled: bp.enabled,
93
+ hitCondition: bp.hitCondition,
94
+ logMessage: bp.logMessage,
95
+ lineNumber: bp.lineNumber
96
+ }
97
+ ]);
98
+ });
99
+ }
100
+ };
101
+ NotebookBreakpoints = ( __decorate([
102
+ ( __param(0, IDebugService)),
103
+ ( __param(1, INotebookService)),
104
+ ( __param(2, IEditorService))
105
+ ], NotebookBreakpoints));
106
+ ( Registry.as(Extensions.Workbench)).registerWorkbenchContribution(NotebookBreakpoints, 3 );
@@ -0,0 +1,67 @@
1
+ import { __decorate, __param } from '../../../../../../../../../external/tslib/tslib.es6.js';
2
+ import { RunOnceScheduler } from 'monaco-editor/esm/vs/base/common/async.js';
3
+ import { Disposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
4
+ import { URI } from 'monaco-editor/esm/vs/base/common/uri.js';
5
+ import { Registry } from 'monaco-editor/esm/vs/platform/registry/common/platform.js';
6
+ import { Extensions } from 'vscode/vscode/vs/workbench/common/contributions';
7
+ import { IDebugService } from 'vscode/vscode/vs/workbench/contrib/debug/common/debug';
8
+ import { CellUri } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookCommon';
9
+ import { CellExecutionUpdateType } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookExecutionService';
10
+ import { INotebookExecutionStateService } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookExecutionStateService';
11
+
12
+ let NotebookCellPausing = class NotebookCellPausing extends Disposable {
13
+ constructor(_debugService, _notebookExecutionStateService) {
14
+ super();
15
+ this._debugService = _debugService;
16
+ this._notebookExecutionStateService = _notebookExecutionStateService;
17
+ this._pausedCells = ( new Set());
18
+ this._register(_debugService.getModel().onDidChangeCallStack(() => {
19
+ this.onDidChangeCallStack(true);
20
+ this._scheduler.schedule();
21
+ }));
22
+ this._scheduler = this._register(( new RunOnceScheduler(() => this.onDidChangeCallStack(false), 2000)));
23
+ }
24
+ async onDidChangeCallStack(fallBackOnStaleCallstack) {
25
+ const newPausedCells = ( new Set());
26
+ for (const session of this._debugService.getModel().getSessions()) {
27
+ for (const thread of session.getAllThreads()) {
28
+ let callStack = thread.getCallStack();
29
+ if (fallBackOnStaleCallstack && !callStack.length) {
30
+ callStack = thread.getStaleCallStack();
31
+ }
32
+ callStack.forEach(sf => {
33
+ const parsed = CellUri.parse(sf.source.uri);
34
+ if (parsed) {
35
+ newPausedCells.add(( sf.source.uri.toString()));
36
+ this.editIsPaused(sf.source.uri, true);
37
+ }
38
+ });
39
+ }
40
+ }
41
+ for (const uri of this._pausedCells) {
42
+ if (!( newPausedCells.has(uri))) {
43
+ this.editIsPaused(( URI.parse(uri)), false);
44
+ this._pausedCells.delete(uri);
45
+ }
46
+ }
47
+ newPausedCells.forEach(cell => this._pausedCells.add(cell));
48
+ }
49
+ editIsPaused(cellUri, isPaused) {
50
+ const parsed = CellUri.parse(cellUri);
51
+ if (parsed) {
52
+ const exeState = this._notebookExecutionStateService.getCellExecution(cellUri);
53
+ if (exeState && (exeState.isPaused !== isPaused || !exeState.didPause)) {
54
+ exeState.update([{
55
+ editType: CellExecutionUpdateType.ExecutionState,
56
+ didPause: true,
57
+ isPaused
58
+ }]);
59
+ }
60
+ }
61
+ }
62
+ };
63
+ NotebookCellPausing = ( __decorate([
64
+ ( __param(0, IDebugService)),
65
+ ( __param(1, INotebookExecutionStateService))
66
+ ], NotebookCellPausing));
67
+ ( Registry.as(Extensions.Workbench)).registerWorkbenchContribution(NotebookCellPausing, 3 );