@theia/notebook 1.53.0-next.5 → 1.53.0-next.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -30
- package/lib/browser/contributions/notebook-actions-contribution.d.ts +1 -0
- package/lib/browser/contributions/notebook-actions-contribution.d.ts.map +1 -1
- package/lib/browser/contributions/notebook-actions-contribution.js +31 -5
- package/lib/browser/contributions/notebook-actions-contribution.js.map +1 -1
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts +2 -0
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts.map +1 -1
- package/lib/browser/contributions/notebook-cell-actions-contribution.js +41 -7
- package/lib/browser/contributions/notebook-cell-actions-contribution.js.map +1 -1
- package/lib/browser/contributions/notebook-status-bar-contribution.d.ts +14 -0
- package/lib/browser/contributions/notebook-status-bar-contribution.d.ts.map +1 -0
- package/lib/browser/contributions/notebook-status-bar-contribution.js +75 -0
- package/lib/browser/contributions/notebook-status-bar-contribution.js.map +1 -0
- package/lib/browser/notebook-editor-widget.d.ts.map +1 -1
- package/lib/browser/notebook-editor-widget.js +3 -5
- package/lib/browser/notebook-editor-widget.js.map +1 -1
- package/lib/browser/notebook-frontend-module.d.ts.map +1 -1
- package/lib/browser/notebook-frontend-module.js +3 -0
- package/lib/browser/notebook-frontend-module.js.map +1 -1
- package/lib/browser/notebook-open-handler.d.ts +3 -2
- package/lib/browser/notebook-open-handler.d.ts.map +1 -1
- package/lib/browser/notebook-open-handler.js +12 -5
- package/lib/browser/notebook-open-handler.js.map +1 -1
- package/lib/browser/view/notebook-cell-editor.d.ts +1 -0
- package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-editor.js +30 -16
- package/lib/browser/view/notebook-cell-editor.js.map +1 -1
- package/lib/browser/view/notebook-cell-list-view.d.ts +6 -4
- package/lib/browser/view/notebook-cell-list-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-list-view.js +20 -13
- package/lib/browser/view/notebook-cell-list-view.js.map +1 -1
- package/lib/browser/view-model/notebook-cell-model.d.ts +3 -0
- package/lib/browser/view-model/notebook-cell-model.d.ts.map +1 -1
- package/lib/browser/view-model/notebook-cell-model.js +5 -0
- package/lib/browser/view-model/notebook-cell-model.js.map +1 -1
- package/package.json +8 -8
- package/src/browser/contributions/cell-operations.ts +44 -44
- package/src/browser/contributions/notebook-actions-contribution.ts +379 -350
- package/src/browser/contributions/notebook-cell-actions-contribution.ts +525 -487
- package/src/browser/contributions/notebook-color-contribution.ts +268 -268
- package/src/browser/contributions/notebook-context-keys.ts +113 -113
- package/src/browser/contributions/notebook-label-provider-contribution.ts +85 -85
- package/src/browser/contributions/notebook-outline-contribution.ts +114 -114
- package/src/browser/contributions/notebook-output-action-contribution.ts +82 -82
- package/src/browser/contributions/notebook-preferences.ts +92 -92
- package/src/browser/contributions/notebook-status-bar-contribution.ts +77 -0
- package/src/browser/contributions/notebook-undo-redo-handler.ts +41 -41
- package/src/browser/index.ts +27 -27
- package/src/browser/notebook-cell-resource-resolver.ts +130 -130
- package/src/browser/notebook-editor-widget-factory.ts +82 -82
- package/src/browser/notebook-editor-widget.tsx +330 -331
- package/src/browser/notebook-frontend-module.ts +119 -115
- package/src/browser/notebook-open-handler.ts +120 -114
- package/src/browser/notebook-output-utils.ts +119 -119
- package/src/browser/notebook-renderer-registry.ts +85 -85
- package/src/browser/notebook-type-registry.ts +54 -54
- package/src/browser/notebook-types.ts +186 -186
- package/src/browser/renderers/cell-output-webview.ts +33 -33
- package/src/browser/service/notebook-clipboard-service.ts +43 -43
- package/src/browser/service/notebook-context-manager.ts +162 -162
- package/src/browser/service/notebook-editor-widget-service.ts +101 -101
- package/src/browser/service/notebook-execution-service.ts +139 -139
- package/src/browser/service/notebook-execution-state-service.ts +311 -311
- package/src/browser/service/notebook-kernel-history-service.ts +124 -124
- package/src/browser/service/notebook-kernel-quick-pick-service.ts +479 -479
- package/src/browser/service/notebook-kernel-service.ts +357 -357
- package/src/browser/service/notebook-model-resolver-service.ts +160 -160
- package/src/browser/service/notebook-monaco-text-model-service.ts +48 -48
- package/src/browser/service/notebook-options.ts +155 -155
- package/src/browser/service/notebook-renderer-messaging-service.ts +121 -121
- package/src/browser/service/notebook-service.ts +215 -215
- package/src/browser/style/index.css +483 -471
- package/src/browser/view/notebook-cell-editor.tsx +263 -247
- package/src/browser/view/notebook-cell-list-view.tsx +279 -262
- package/src/browser/view/notebook-cell-toolbar-factory.tsx +102 -102
- package/src/browser/view/notebook-cell-toolbar.tsx +74 -74
- package/src/browser/view/notebook-code-cell-view.tsx +350 -350
- package/src/browser/view/notebook-find-widget.tsx +335 -335
- package/src/browser/view/notebook-main-toolbar.tsx +235 -235
- package/src/browser/view/notebook-markdown-cell-view.tsx +208 -208
- package/src/browser/view/notebook-viewport-service.ts +61 -61
- package/src/browser/view-model/notebook-cell-model.ts +473 -466
- package/src/browser/view-model/notebook-cell-output-model.ts +100 -100
- package/src/browser/view-model/notebook-model.ts +550 -550
- package/src/common/index.ts +18 -18
- package/src/common/notebook-common.ts +337 -337
- package/src/common/notebook-protocol.ts +35 -35
- package/src/common/notebook-range.ts +30 -30
|
@@ -1,350 +1,379 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2023 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { Command, CommandContribution, CommandHandler, CommandRegistry, CompoundMenuNodeRole, MenuContribution, MenuModelRegistry, nls, URI } from '@theia/core';
|
|
18
|
-
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
19
|
-
import { ApplicationShell, codicon, KeybindingContribution, KeybindingRegistry } from '@theia/core/lib/browser';
|
|
20
|
-
import { NotebookModel } from '../view-model/notebook-model';
|
|
21
|
-
import { NotebookService } from '../service/notebook-service';
|
|
22
|
-
import { CellEditType, CellKind, NotebookCommand } from '../../common';
|
|
23
|
-
import { NotebookKernelQuickPickService } from '../service/notebook-kernel-quick-pick-service';
|
|
24
|
-
import { NotebookExecutionService } from '../service/notebook-execution-service';
|
|
25
|
-
import { NotebookEditorWidgetService } from '../service/notebook-editor-widget-service';
|
|
26
|
-
import { NOTEBOOK_CELL_CURSOR_FIRST_LINE, NOTEBOOK_CELL_CURSOR_LAST_LINE, NOTEBOOK_CELL_FOCUSED, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_HAS_OUTPUTS } from './notebook-context-keys';
|
|
27
|
-
import { NotebookClipboardService } from '../service/notebook-clipboard-service';
|
|
28
|
-
import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
export
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
@inject(
|
|
107
|
-
protected
|
|
108
|
-
|
|
109
|
-
@inject(
|
|
110
|
-
protected
|
|
111
|
-
|
|
112
|
-
@inject(
|
|
113
|
-
protected
|
|
114
|
-
|
|
115
|
-
@inject(
|
|
116
|
-
protected
|
|
117
|
-
|
|
118
|
-
@inject(
|
|
119
|
-
protected
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
commands.registerCommand(
|
|
220
|
-
execute: () =>
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2023 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { Command, CommandContribution, CommandHandler, CommandRegistry, CompoundMenuNodeRole, MenuContribution, MenuModelRegistry, nls, URI } from '@theia/core';
|
|
18
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
19
|
+
import { ApplicationShell, codicon, KeybindingContribution, KeybindingRegistry } from '@theia/core/lib/browser';
|
|
20
|
+
import { NotebookModel } from '../view-model/notebook-model';
|
|
21
|
+
import { NotebookService } from '../service/notebook-service';
|
|
22
|
+
import { CellEditType, CellKind, NotebookCommand } from '../../common';
|
|
23
|
+
import { NotebookKernelQuickPickService } from '../service/notebook-kernel-quick-pick-service';
|
|
24
|
+
import { NotebookExecutionService } from '../service/notebook-execution-service';
|
|
25
|
+
import { NotebookEditorWidgetService } from '../service/notebook-editor-widget-service';
|
|
26
|
+
import { NOTEBOOK_CELL_CURSOR_FIRST_LINE, NOTEBOOK_CELL_CURSOR_LAST_LINE, NOTEBOOK_CELL_FOCUSED, NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_HAS_OUTPUTS } from './notebook-context-keys';
|
|
27
|
+
import { NotebookClipboardService } from '../service/notebook-clipboard-service';
|
|
28
|
+
import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
|
|
29
|
+
import { NotebookEditorWidget } from '../notebook-editor-widget';
|
|
30
|
+
|
|
31
|
+
export namespace NotebookCommands {
|
|
32
|
+
export const ADD_NEW_CELL_COMMAND = Command.toDefaultLocalizedCommand({
|
|
33
|
+
id: 'notebook.add-new-cell',
|
|
34
|
+
iconClass: codicon('add')
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export const ADD_NEW_MARKDOWN_CELL_COMMAND = Command.toDefaultLocalizedCommand({
|
|
38
|
+
id: 'notebook.add-new-markdown-cell',
|
|
39
|
+
iconClass: codicon('add'),
|
|
40
|
+
tooltip: nls.localizeByDefault('Add Markdown Cell')
|
|
41
|
+
} as NotebookCommand);
|
|
42
|
+
|
|
43
|
+
export const ADD_NEW_CODE_CELL_COMMAND = Command.toDefaultLocalizedCommand({
|
|
44
|
+
id: 'notebook.add-new-code-cell',
|
|
45
|
+
iconClass: codicon('add'),
|
|
46
|
+
tooltip: nls.localizeByDefault('Add Code Cell')
|
|
47
|
+
} as NotebookCommand);
|
|
48
|
+
|
|
49
|
+
export const SELECT_KERNEL_COMMAND = Command.toDefaultLocalizedCommand({
|
|
50
|
+
id: 'notebook.selectKernel',
|
|
51
|
+
category: 'Notebook',
|
|
52
|
+
iconClass: codicon('server-environment')
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const EXECUTE_NOTEBOOK_COMMAND = Command.toDefaultLocalizedCommand({
|
|
56
|
+
id: 'notebook.execute',
|
|
57
|
+
category: 'Notebook',
|
|
58
|
+
iconClass: codicon('run-all')
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export const CLEAR_ALL_OUTPUTS_COMMAND = Command.toDefaultLocalizedCommand({
|
|
62
|
+
id: 'notebook.clear-all-outputs',
|
|
63
|
+
category: 'Notebook',
|
|
64
|
+
iconClass: codicon('clear-all')
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export const CHANGE_SELECTED_CELL = Command.toDefaultLocalizedCommand({
|
|
68
|
+
id: 'notebook.change-selected-cell',
|
|
69
|
+
category: 'Notebook',
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const CUT_SELECTED_CELL = Command.toDefaultLocalizedCommand({
|
|
73
|
+
id: 'notebook.cell.cut',
|
|
74
|
+
category: 'Notebook',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export const COPY_SELECTED_CELL = Command.toDefaultLocalizedCommand({
|
|
78
|
+
id: 'notebook.cell.copy',
|
|
79
|
+
category: 'Notebook',
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export const PASTE_CELL = Command.toDefaultLocalizedCommand({
|
|
83
|
+
id: 'notebook.cell.paste',
|
|
84
|
+
category: 'Notebook',
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
export const NOTEBOOK_FIND = Command.toDefaultLocalizedCommand({
|
|
88
|
+
id: 'notebook.find',
|
|
89
|
+
category: 'Notebook',
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export const CENTER_ACTIVE_CELL = Command.toDefaultLocalizedCommand({
|
|
93
|
+
id: 'notebook.centerActiveCell',
|
|
94
|
+
category: 'Notebook',
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export enum CellChangeDirection {
|
|
99
|
+
Up = 'up',
|
|
100
|
+
Down = 'down'
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@injectable()
|
|
104
|
+
export class NotebookActionsContribution implements CommandContribution, MenuContribution, KeybindingContribution {
|
|
105
|
+
|
|
106
|
+
@inject(NotebookService)
|
|
107
|
+
protected notebookService: NotebookService;
|
|
108
|
+
|
|
109
|
+
@inject(NotebookKernelQuickPickService)
|
|
110
|
+
protected notebookKernelQuickPickService: NotebookKernelQuickPickService;
|
|
111
|
+
|
|
112
|
+
@inject(NotebookExecutionService)
|
|
113
|
+
protected notebookExecutionService: NotebookExecutionService;
|
|
114
|
+
|
|
115
|
+
@inject(ApplicationShell)
|
|
116
|
+
protected shell: ApplicationShell;
|
|
117
|
+
|
|
118
|
+
@inject(NotebookEditorWidgetService)
|
|
119
|
+
protected notebookEditorWidgetService: NotebookEditorWidgetService;
|
|
120
|
+
|
|
121
|
+
@inject(NotebookClipboardService)
|
|
122
|
+
protected notebookClipboardService: NotebookClipboardService;
|
|
123
|
+
|
|
124
|
+
@inject(ContextKeyService)
|
|
125
|
+
protected contextKeyService: ContextKeyService;
|
|
126
|
+
|
|
127
|
+
registerCommands(commands: CommandRegistry): void {
|
|
128
|
+
commands.registerCommand(NotebookCommands.ADD_NEW_CELL_COMMAND, {
|
|
129
|
+
execute: (notebookModel: NotebookModel, cellKind: CellKind = CellKind.Markup, index?: number | 'above' | 'below', focusContainer?: boolean) => {
|
|
130
|
+
notebookModel = notebookModel ?? this.notebookEditorWidgetService.focusedEditor?.model;
|
|
131
|
+
|
|
132
|
+
let insertIndex: number = 0;
|
|
133
|
+
if (typeof index === 'number' && index >= 0) {
|
|
134
|
+
insertIndex = index;
|
|
135
|
+
} else if (notebookModel.selectedCell && typeof index === 'string') {
|
|
136
|
+
// if index is -1 insert below otherwise at the index of the selected cell which is above the selected.
|
|
137
|
+
insertIndex = notebookModel.cells.indexOf(notebookModel.selectedCell) + (index === 'below' ? 1 : 0);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let cellLanguage: string = 'markdown';
|
|
141
|
+
if (cellKind === CellKind.Code) {
|
|
142
|
+
cellLanguage = this.notebookService.getCodeCellLanguage(notebookModel);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
notebookModel.applyEdits([{
|
|
146
|
+
editType: CellEditType.Replace,
|
|
147
|
+
index: insertIndex,
|
|
148
|
+
count: 0,
|
|
149
|
+
cells: [{
|
|
150
|
+
cellKind,
|
|
151
|
+
language: cellLanguage,
|
|
152
|
+
source: '',
|
|
153
|
+
outputs: [],
|
|
154
|
+
metadata: {},
|
|
155
|
+
}]
|
|
156
|
+
}], true);
|
|
157
|
+
if (focusContainer) {
|
|
158
|
+
notebookModel.selectedCell?.requestBlurEditor();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
commands.registerCommand(NotebookCommands.ADD_NEW_MARKDOWN_CELL_COMMAND, this.editableCommandHandler(
|
|
164
|
+
notebookModel => commands.executeCommand(NotebookCommands.ADD_NEW_CELL_COMMAND.id, notebookModel, CellKind.Markup, 'below')
|
|
165
|
+
));
|
|
166
|
+
|
|
167
|
+
commands.registerCommand(NotebookCommands.ADD_NEW_CODE_CELL_COMMAND, this.editableCommandHandler(
|
|
168
|
+
notebookModel => commands.executeCommand(NotebookCommands.ADD_NEW_CELL_COMMAND.id, notebookModel, CellKind.Code, 'below')
|
|
169
|
+
));
|
|
170
|
+
|
|
171
|
+
commands.registerCommand(NotebookCommands.SELECT_KERNEL_COMMAND, this.editableCommandHandler(
|
|
172
|
+
notebookModel => this.notebookKernelQuickPickService.showQuickPick(notebookModel)
|
|
173
|
+
));
|
|
174
|
+
|
|
175
|
+
commands.registerCommand(NotebookCommands.EXECUTE_NOTEBOOK_COMMAND, this.editableCommandHandler(
|
|
176
|
+
notebookModel => this.notebookExecutionService.executeNotebookCells(notebookModel, notebookModel.cells)
|
|
177
|
+
));
|
|
178
|
+
|
|
179
|
+
commands.registerCommand(NotebookCommands.CLEAR_ALL_OUTPUTS_COMMAND, this.editableCommandHandler(
|
|
180
|
+
notebookModel => notebookModel.applyEdits(notebookModel.cells.map(cell => ({
|
|
181
|
+
editType: CellEditType.Output,
|
|
182
|
+
handle: cell.handle, deleteCount: cell.outputs.length, outputs: []
|
|
183
|
+
})), false)
|
|
184
|
+
));
|
|
185
|
+
|
|
186
|
+
commands.registerCommand(NotebookCommands.CHANGE_SELECTED_CELL,
|
|
187
|
+
{
|
|
188
|
+
execute: (change: number | CellChangeDirection) => {
|
|
189
|
+
const focusedEditor = this.notebookEditorWidgetService.focusedEditor;
|
|
190
|
+
const model = focusedEditor?.model;
|
|
191
|
+
if (model && typeof change === 'number') {
|
|
192
|
+
model.setSelectedCell(model.cells[change]);
|
|
193
|
+
} else if (model && model.selectedCell) {
|
|
194
|
+
const currentIndex = model.cells.indexOf(model.selectedCell);
|
|
195
|
+
const shouldFocusEditor = this.contextKeyService.match('editorTextFocus');
|
|
196
|
+
|
|
197
|
+
if (change === CellChangeDirection.Up && currentIndex > 0) {
|
|
198
|
+
model.setSelectedCell(model.cells[currentIndex - 1]);
|
|
199
|
+
if ((model.selectedCell?.cellKind === CellKind.Code
|
|
200
|
+
|| (model.selectedCell?.cellKind === CellKind.Markup && model.selectedCell?.editing)) && shouldFocusEditor) {
|
|
201
|
+
model.selectedCell.requestFocusEditor('lastLine');
|
|
202
|
+
}
|
|
203
|
+
} else if (change === CellChangeDirection.Down && currentIndex < model.cells.length - 1) {
|
|
204
|
+
model.setSelectedCell(model.cells[currentIndex + 1]);
|
|
205
|
+
if ((model.selectedCell?.cellKind === CellKind.Code
|
|
206
|
+
|| (model.selectedCell?.cellKind === CellKind.Markup && model.selectedCell?.editing)) && shouldFocusEditor) {
|
|
207
|
+
model.selectedCell.requestFocusEditor();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (model.selectedCell.cellKind === CellKind.Markup) {
|
|
212
|
+
// since were losing focus from the cell editor, we need to focus the notebook editor again
|
|
213
|
+
focusedEditor?.node.focus();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
commands.registerCommand({ id: 'list.focusUp' }, {
|
|
220
|
+
execute: () => commands.executeCommand(NotebookCommands.CHANGE_SELECTED_CELL.id, CellChangeDirection.Up)
|
|
221
|
+
});
|
|
222
|
+
commands.registerCommand({ id: 'list.focusDown' }, {
|
|
223
|
+
execute: () => commands.executeCommand(NotebookCommands.CHANGE_SELECTED_CELL.id, CellChangeDirection.Down)
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
commands.registerCommand(NotebookCommands.CUT_SELECTED_CELL, this.editableCommandHandler(
|
|
227
|
+
() => {
|
|
228
|
+
const model = this.notebookEditorWidgetService.focusedEditor?.model;
|
|
229
|
+
const selectedCell = model?.selectedCell;
|
|
230
|
+
if (selectedCell) {
|
|
231
|
+
model.applyEdits([{ editType: CellEditType.Replace, index: model.cells.indexOf(selectedCell), count: 1, cells: [] }], true);
|
|
232
|
+
this.notebookClipboardService.copyCell(selectedCell);
|
|
233
|
+
}
|
|
234
|
+
}));
|
|
235
|
+
|
|
236
|
+
commands.registerCommand(NotebookCommands.COPY_SELECTED_CELL, {
|
|
237
|
+
execute: () => {
|
|
238
|
+
const model = this.notebookEditorWidgetService.focusedEditor?.model;
|
|
239
|
+
const selectedCell = model?.selectedCell;
|
|
240
|
+
if (selectedCell) {
|
|
241
|
+
this.notebookClipboardService.copyCell(selectedCell);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
commands.registerCommand(NotebookCommands.PASTE_CELL, {
|
|
247
|
+
isEnabled: () => !Boolean(this.notebookEditorWidgetService.focusedEditor?.model?.readOnly),
|
|
248
|
+
isVisible: () => !Boolean(this.notebookEditorWidgetService.focusedEditor?.model?.readOnly),
|
|
249
|
+
execute: (position?: 'above') => {
|
|
250
|
+
const copiedCell = this.notebookClipboardService.getCell();
|
|
251
|
+
if (copiedCell) {
|
|
252
|
+
const model = this.notebookEditorWidgetService.focusedEditor?.model;
|
|
253
|
+
const insertIndex = model?.selectedCell ? model.cells.indexOf(model.selectedCell) + (position === 'above' ? 0 : 1) : 0;
|
|
254
|
+
model?.applyEdits([{ editType: CellEditType.Replace, index: insertIndex, count: 0, cells: [copiedCell] }], true);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
commands.registerCommand(NotebookCommands.NOTEBOOK_FIND, {
|
|
260
|
+
execute: () => {
|
|
261
|
+
this.notebookEditorWidgetService.focusedEditor?.showFindWidget();
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
commands.registerCommand(NotebookCommands.CENTER_ACTIVE_CELL, {
|
|
266
|
+
execute: (editor?: NotebookEditorWidget) => {
|
|
267
|
+
const model = editor ? editor.model : this.notebookEditorWidgetService.focusedEditor?.model;
|
|
268
|
+
model?.selectedCell?.requestCenterEditor();
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
protected editableCommandHandler(execute: (notebookModel: NotebookModel) => void): CommandHandler {
|
|
275
|
+
return {
|
|
276
|
+
isEnabled: (item: URI | NotebookModel) => this.withModel(item, model => !Boolean(model?.readOnly), false),
|
|
277
|
+
isVisible: (item: URI | NotebookModel) => this.withModel(item, model => !Boolean(model?.readOnly), false),
|
|
278
|
+
execute: (uri: URI | NotebookModel) => {
|
|
279
|
+
this.withModel(uri, execute, undefined);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
protected withModel<T>(item: URI | NotebookModel, execute: (notebookModel: NotebookModel) => T, defaultValue: T): T {
|
|
285
|
+
if (item instanceof URI) {
|
|
286
|
+
const model = this.notebookService.getNotebookEditorModel(item);
|
|
287
|
+
if (!model) {
|
|
288
|
+
return defaultValue;
|
|
289
|
+
}
|
|
290
|
+
item = model;
|
|
291
|
+
}
|
|
292
|
+
return execute(item);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
registerMenus(menus: MenuModelRegistry): void {
|
|
296
|
+
// independent submenu for plugins to add commands
|
|
297
|
+
menus.registerIndependentSubmenu(NotebookMenus.NOTEBOOK_MAIN_TOOLBAR, 'Notebook Main Toolbar');
|
|
298
|
+
// Add Notebook Cell items
|
|
299
|
+
menus.registerSubmenu(NotebookMenus.NOTEBOOK_MAIN_TOOLBAR_CELL_ADD_GROUP, 'Add Notebook Cell', { role: CompoundMenuNodeRole.Group });
|
|
300
|
+
menus.registerMenuAction(NotebookMenus.NOTEBOOK_MAIN_TOOLBAR_CELL_ADD_GROUP, {
|
|
301
|
+
commandId: NotebookCommands.ADD_NEW_CODE_CELL_COMMAND.id,
|
|
302
|
+
label: nls.localizeByDefault('Code'),
|
|
303
|
+
icon: codicon('add'),
|
|
304
|
+
});
|
|
305
|
+
menus.registerMenuAction(NotebookMenus.NOTEBOOK_MAIN_TOOLBAR_CELL_ADD_GROUP, {
|
|
306
|
+
commandId: NotebookCommands.ADD_NEW_MARKDOWN_CELL_COMMAND.id,
|
|
307
|
+
label: nls.localizeByDefault('Markdown'),
|
|
308
|
+
icon: codicon('add'),
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
// Execution related items
|
|
312
|
+
menus.registerSubmenu(NotebookMenus.NOTEBOOK_MAIN_TOOLBAR_EXECUTION_GROUP, 'Cell Execution', { role: CompoundMenuNodeRole.Group });
|
|
313
|
+
menus.registerMenuAction(NotebookMenus.NOTEBOOK_MAIN_TOOLBAR_EXECUTION_GROUP, {
|
|
314
|
+
commandId: NotebookCommands.EXECUTE_NOTEBOOK_COMMAND.id,
|
|
315
|
+
label: nls.localizeByDefault('Run All'),
|
|
316
|
+
icon: codicon('run-all'),
|
|
317
|
+
order: '10'
|
|
318
|
+
});
|
|
319
|
+
menus.registerMenuAction(NotebookMenus.NOTEBOOK_MAIN_TOOLBAR_EXECUTION_GROUP, {
|
|
320
|
+
commandId: NotebookCommands.CLEAR_ALL_OUTPUTS_COMMAND.id,
|
|
321
|
+
label: nls.localizeByDefault('Clear All Outputs'),
|
|
322
|
+
icon: codicon('clear-all'),
|
|
323
|
+
order: '30',
|
|
324
|
+
when: NOTEBOOK_HAS_OUTPUTS
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
menus.registerIndependentSubmenu(NotebookMenus.NOTEBOOK_MAIN_TOOLBAR_HIDDEN_ITEMS_CONTEXT_MENU, '');
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
registerKeybindings(keybindings: KeybindingRegistry): void {
|
|
331
|
+
keybindings.registerKeybindings(
|
|
332
|
+
{
|
|
333
|
+
command: NotebookCommands.CHANGE_SELECTED_CELL.id,
|
|
334
|
+
keybinding: 'up',
|
|
335
|
+
args: CellChangeDirection.Up,
|
|
336
|
+
when: `(!editorTextFocus || ${NOTEBOOK_CELL_CURSOR_FIRST_LINE}) && !suggestWidgetVisible && ${NOTEBOOK_EDITOR_FOCUSED} && ${NOTEBOOK_CELL_FOCUSED}`
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
command: NotebookCommands.CHANGE_SELECTED_CELL.id,
|
|
340
|
+
keybinding: 'down',
|
|
341
|
+
args: CellChangeDirection.Down,
|
|
342
|
+
when: `(!editorTextFocus || ${NOTEBOOK_CELL_CURSOR_LAST_LINE}) && !suggestWidgetVisible && ${NOTEBOOK_EDITOR_FOCUSED} && ${NOTEBOOK_CELL_FOCUSED}`
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
command: NotebookCommands.CUT_SELECTED_CELL.id,
|
|
346
|
+
keybinding: 'ctrlcmd+x',
|
|
347
|
+
when: `${NOTEBOOK_EDITOR_FOCUSED} && !inputFocus`
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
command: NotebookCommands.COPY_SELECTED_CELL.id,
|
|
351
|
+
keybinding: 'ctrlcmd+c',
|
|
352
|
+
when: `${NOTEBOOK_EDITOR_FOCUSED} && !inputFocus`
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
command: NotebookCommands.PASTE_CELL.id,
|
|
356
|
+
keybinding: 'ctrlcmd+v',
|
|
357
|
+
when: `${NOTEBOOK_EDITOR_FOCUSED} && !inputFocus`
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
command: NotebookCommands.NOTEBOOK_FIND.id,
|
|
361
|
+
keybinding: 'ctrlcmd+f',
|
|
362
|
+
when: `${NOTEBOOK_EDITOR_FOCUSED}`
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
command: NotebookCommands.CENTER_ACTIVE_CELL.id,
|
|
366
|
+
keybinding: 'ctrlcmd+l',
|
|
367
|
+
when: `${NOTEBOOK_EDITOR_FOCUSED}`
|
|
368
|
+
}
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export namespace NotebookMenus {
|
|
375
|
+
export const NOTEBOOK_MAIN_TOOLBAR = 'notebook/toolbar';
|
|
376
|
+
export const NOTEBOOK_MAIN_TOOLBAR_CELL_ADD_GROUP = [NOTEBOOK_MAIN_TOOLBAR, 'cell-add-group'];
|
|
377
|
+
export const NOTEBOOK_MAIN_TOOLBAR_EXECUTION_GROUP = [NOTEBOOK_MAIN_TOOLBAR, 'cell-execution-group'];
|
|
378
|
+
export const NOTEBOOK_MAIN_TOOLBAR_HIDDEN_ITEMS_CONTEXT_MENU = 'notebook-main-toolbar-hidden-items-context-menu';
|
|
379
|
+
}
|