@theia/notebook 1.53.0-next.4 → 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/cell-operations.d.ts.map +1 -1
- package/lib/browser/contributions/cell-operations.js +8 -1
- package/lib/browser/contributions/cell-operations.js.map +1 -1
- 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 -6
- package/lib/browser/contributions/notebook-actions-contribution.js.map +1 -1
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts +4 -0
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts.map +1 -1
- package/lib/browser/contributions/notebook-cell-actions-contribution.js +49 -12
- 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/service/notebook-options.d.ts +1 -0
- package/lib/browser/service/notebook-options.d.ts.map +1 -1
- package/lib/browser/service/notebook-options.js +1 -0
- package/lib/browser/service/notebook-options.js.map +1 -1
- package/lib/browser/service/notebook-service.d.ts +1 -0
- package/lib/browser/service/notebook-service.d.ts.map +1 -1
- package/lib/browser/service/notebook-service.js +7 -0
- package/lib/browser/service/notebook-service.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 +7 -4
- package/lib/browser/view/notebook-cell-list-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-list-view.js +39 -29
- 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 -39
- package/src/browser/contributions/notebook-actions-contribution.ts +379 -351
- package/src/browser/contributions/notebook-cell-actions-contribution.ts +525 -485
- 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 -154
- package/src/browser/service/notebook-renderer-messaging-service.ts +121 -121
- package/src/browser/service/notebook-service.ts +215 -209
- package/src/browser/style/index.css +483 -467
- package/src/browser/view/notebook-cell-editor.tsx +263 -247
- package/src/browser/view/notebook-cell-list-view.tsx +279 -259
- 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,247 +1,263 @@
|
|
|
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 * as React from '@theia/core/shared/react';
|
|
18
|
-
import { NotebookModel } from '../view-model/notebook-model';
|
|
19
|
-
import { NotebookCellModel, NotebookCodeEditorFindMatch } from '../view-model/notebook-cell-model';
|
|
20
|
-
import { SimpleMonacoEditor } from '@theia/monaco/lib/browser/simple-monaco-editor';
|
|
21
|
-
import { MonacoEditor, MonacoEditorServices } from '@theia/monaco/lib/browser/monaco-editor';
|
|
22
|
-
import { MonacoEditorProvider } from '@theia/monaco/lib/browser/monaco-editor-provider';
|
|
23
|
-
import { IContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/common/contextkey';
|
|
24
|
-
import { NotebookContextManager } from '../service/notebook-context-manager';
|
|
25
|
-
import { DisposableCollection, OS } from '@theia/core';
|
|
26
|
-
import { NotebookViewportService } from './notebook-viewport-service';
|
|
27
|
-
import { BareFontInfo } from '@theia/monaco-editor-core/esm/vs/editor/common/config/fontInfo';
|
|
28
|
-
import { NOTEBOOK_CELL_CURSOR_FIRST_LINE, NOTEBOOK_CELL_CURSOR_LAST_LINE } from '../contributions/notebook-context-keys';
|
|
29
|
-
import { EditorExtensionsRegistry } from '@theia/monaco-editor-core/esm/vs/editor/browser/editorExtensions';
|
|
30
|
-
import { ModelDecorationOptions } from '@theia/monaco-editor-core/esm/vs/editor/common/model/textModel';
|
|
31
|
-
import { IModelDeltaDecoration, OverviewRulerLane, TrackedRangeStickiness } from '@theia/monaco-editor-core/esm/vs/editor/common/model';
|
|
32
|
-
import { animationFrame } from '@theia/core/lib/browser';
|
|
33
|
-
|
|
34
|
-
interface CellEditorProps {
|
|
35
|
-
notebookModel: NotebookModel,
|
|
36
|
-
cell: NotebookCellModel,
|
|
37
|
-
monacoServices: MonacoEditorServices,
|
|
38
|
-
notebookContextManager: NotebookContextManager;
|
|
39
|
-
notebookViewportService?: NotebookViewportService,
|
|
40
|
-
fontInfo?: BareFontInfo;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const DEFAULT_EDITOR_OPTIONS: MonacoEditor.IOptions = {
|
|
44
|
-
...MonacoEditorProvider.inlineOptions,
|
|
45
|
-
minHeight: -1,
|
|
46
|
-
maxHeight: -1,
|
|
47
|
-
scrollbar: {
|
|
48
|
-
...MonacoEditorProvider.inlineOptions.scrollbar,
|
|
49
|
-
alwaysConsumeMouseWheel: false
|
|
50
|
-
},
|
|
51
|
-
lineDecorationsWidth: 10,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const CURRENT_FIND_MATCH_DECORATION = ModelDecorationOptions.register({
|
|
55
|
-
description: 'current-find-match',
|
|
56
|
-
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
|
|
57
|
-
zIndex: 13,
|
|
58
|
-
className: 'currentFindMatch',
|
|
59
|
-
inlineClassName: 'currentFindMatchInline',
|
|
60
|
-
showIfCollapsed: true,
|
|
61
|
-
overviewRuler: {
|
|
62
|
-
color: 'editorOverviewRuler.findMatchForeground',
|
|
63
|
-
position: OverviewRulerLane.Center
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
export const FIND_MATCH_DECORATION = ModelDecorationOptions.register({
|
|
68
|
-
description: 'find-match',
|
|
69
|
-
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
|
|
70
|
-
zIndex: 10,
|
|
71
|
-
className: 'findMatch',
|
|
72
|
-
inlineClassName: 'findMatchInline',
|
|
73
|
-
showIfCollapsed: true,
|
|
74
|
-
overviewRuler: {
|
|
75
|
-
color: 'editorOverviewRuler.findMatchForeground',
|
|
76
|
-
position: OverviewRulerLane.Center
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
export class CellEditor extends React.Component<CellEditorProps, {}> {
|
|
81
|
-
|
|
82
|
-
protected editor?: SimpleMonacoEditor;
|
|
83
|
-
protected toDispose = new DisposableCollection();
|
|
84
|
-
protected container?: HTMLDivElement;
|
|
85
|
-
protected matches: NotebookCodeEditorFindMatch[] = [];
|
|
86
|
-
protected oldMatchDecorations: string[] = [];
|
|
87
|
-
|
|
88
|
-
override componentDidMount(): void {
|
|
89
|
-
this.disposeEditor();
|
|
90
|
-
this.toDispose.push(this.props.cell.onWillFocusCellEditor(focusRequest => {
|
|
91
|
-
this.editor?.getControl().focus();
|
|
92
|
-
const lineCount = this.editor?.getControl().getModel()?.getLineCount();
|
|
93
|
-
if (focusRequest && lineCount !== undefined) {
|
|
94
|
-
this.editor?.getControl().setPosition(focusRequest === 'lastLine' ?
|
|
95
|
-
{ lineNumber: lineCount, column: 1 } :
|
|
96
|
-
{ lineNumber: focusRequest, column: 1 },
|
|
97
|
-
'keyboard');
|
|
98
|
-
}
|
|
99
|
-
const currentLine = this.editor?.getControl().getPosition()?.lineNumber;
|
|
100
|
-
this.props.notebookContextManager.scopedStore.setContext(NOTEBOOK_CELL_CURSOR_FIRST_LINE, currentLine === 1);
|
|
101
|
-
this.props.notebookContextManager.scopedStore.setContext(NOTEBOOK_CELL_CURSOR_LAST_LINE, currentLine === lineCount);
|
|
102
|
-
}));
|
|
103
|
-
|
|
104
|
-
this.toDispose.push(this.props.cell.
|
|
105
|
-
this.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
this.toDispose
|
|
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
|
-
this.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
this.props.
|
|
188
|
-
|
|
189
|
-
this.toDispose.push(this.editor
|
|
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
|
-
|
|
220
|
-
|
|
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
|
-
|
|
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 * as React from '@theia/core/shared/react';
|
|
18
|
+
import { NotebookModel } from '../view-model/notebook-model';
|
|
19
|
+
import { NotebookCellModel, NotebookCodeEditorFindMatch } from '../view-model/notebook-cell-model';
|
|
20
|
+
import { SimpleMonacoEditor } from '@theia/monaco/lib/browser/simple-monaco-editor';
|
|
21
|
+
import { MonacoEditor, MonacoEditorServices } from '@theia/monaco/lib/browser/monaco-editor';
|
|
22
|
+
import { MonacoEditorProvider } from '@theia/monaco/lib/browser/monaco-editor-provider';
|
|
23
|
+
import { IContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/common/contextkey';
|
|
24
|
+
import { NotebookContextManager } from '../service/notebook-context-manager';
|
|
25
|
+
import { DisposableCollection, OS } from '@theia/core';
|
|
26
|
+
import { NotebookViewportService } from './notebook-viewport-service';
|
|
27
|
+
import { BareFontInfo } from '@theia/monaco-editor-core/esm/vs/editor/common/config/fontInfo';
|
|
28
|
+
import { NOTEBOOK_CELL_CURSOR_FIRST_LINE, NOTEBOOK_CELL_CURSOR_LAST_LINE } from '../contributions/notebook-context-keys';
|
|
29
|
+
import { EditorExtensionsRegistry } from '@theia/monaco-editor-core/esm/vs/editor/browser/editorExtensions';
|
|
30
|
+
import { ModelDecorationOptions } from '@theia/monaco-editor-core/esm/vs/editor/common/model/textModel';
|
|
31
|
+
import { IModelDeltaDecoration, OverviewRulerLane, TrackedRangeStickiness } from '@theia/monaco-editor-core/esm/vs/editor/common/model';
|
|
32
|
+
import { animationFrame } from '@theia/core/lib/browser';
|
|
33
|
+
|
|
34
|
+
interface CellEditorProps {
|
|
35
|
+
notebookModel: NotebookModel,
|
|
36
|
+
cell: NotebookCellModel,
|
|
37
|
+
monacoServices: MonacoEditorServices,
|
|
38
|
+
notebookContextManager: NotebookContextManager;
|
|
39
|
+
notebookViewportService?: NotebookViewportService,
|
|
40
|
+
fontInfo?: BareFontInfo;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const DEFAULT_EDITOR_OPTIONS: MonacoEditor.IOptions = {
|
|
44
|
+
...MonacoEditorProvider.inlineOptions,
|
|
45
|
+
minHeight: -1,
|
|
46
|
+
maxHeight: -1,
|
|
47
|
+
scrollbar: {
|
|
48
|
+
...MonacoEditorProvider.inlineOptions.scrollbar,
|
|
49
|
+
alwaysConsumeMouseWheel: false
|
|
50
|
+
},
|
|
51
|
+
lineDecorationsWidth: 10,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const CURRENT_FIND_MATCH_DECORATION = ModelDecorationOptions.register({
|
|
55
|
+
description: 'current-find-match',
|
|
56
|
+
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
|
|
57
|
+
zIndex: 13,
|
|
58
|
+
className: 'currentFindMatch',
|
|
59
|
+
inlineClassName: 'currentFindMatchInline',
|
|
60
|
+
showIfCollapsed: true,
|
|
61
|
+
overviewRuler: {
|
|
62
|
+
color: 'editorOverviewRuler.findMatchForeground',
|
|
63
|
+
position: OverviewRulerLane.Center
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export const FIND_MATCH_DECORATION = ModelDecorationOptions.register({
|
|
68
|
+
description: 'find-match',
|
|
69
|
+
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
|
|
70
|
+
zIndex: 10,
|
|
71
|
+
className: 'findMatch',
|
|
72
|
+
inlineClassName: 'findMatchInline',
|
|
73
|
+
showIfCollapsed: true,
|
|
74
|
+
overviewRuler: {
|
|
75
|
+
color: 'editorOverviewRuler.findMatchForeground',
|
|
76
|
+
position: OverviewRulerLane.Center
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
export class CellEditor extends React.Component<CellEditorProps, {}> {
|
|
81
|
+
|
|
82
|
+
protected editor?: SimpleMonacoEditor;
|
|
83
|
+
protected toDispose = new DisposableCollection();
|
|
84
|
+
protected container?: HTMLDivElement;
|
|
85
|
+
protected matches: NotebookCodeEditorFindMatch[] = [];
|
|
86
|
+
protected oldMatchDecorations: string[] = [];
|
|
87
|
+
|
|
88
|
+
override componentDidMount(): void {
|
|
89
|
+
this.disposeEditor();
|
|
90
|
+
this.toDispose.push(this.props.cell.onWillFocusCellEditor(focusRequest => {
|
|
91
|
+
this.editor?.getControl().focus();
|
|
92
|
+
const lineCount = this.editor?.getControl().getModel()?.getLineCount();
|
|
93
|
+
if (focusRequest && lineCount !== undefined) {
|
|
94
|
+
this.editor?.getControl().setPosition(focusRequest === 'lastLine' ?
|
|
95
|
+
{ lineNumber: lineCount, column: 1 } :
|
|
96
|
+
{ lineNumber: focusRequest, column: 1 },
|
|
97
|
+
'keyboard');
|
|
98
|
+
}
|
|
99
|
+
const currentLine = this.editor?.getControl().getPosition()?.lineNumber;
|
|
100
|
+
this.props.notebookContextManager.scopedStore.setContext(NOTEBOOK_CELL_CURSOR_FIRST_LINE, currentLine === 1);
|
|
101
|
+
this.props.notebookContextManager.scopedStore.setContext(NOTEBOOK_CELL_CURSOR_LAST_LINE, currentLine === lineCount);
|
|
102
|
+
}));
|
|
103
|
+
|
|
104
|
+
this.toDispose.push(this.props.cell.onWillBlurCellEditor(() => {
|
|
105
|
+
let parent = this.container?.parentElement;
|
|
106
|
+
while (parent && !parent.classList.contains('theia-notebook-cell')) {
|
|
107
|
+
parent = parent.parentElement;
|
|
108
|
+
}
|
|
109
|
+
if (parent) {
|
|
110
|
+
parent.focus();
|
|
111
|
+
}
|
|
112
|
+
}));
|
|
113
|
+
|
|
114
|
+
this.toDispose.push(this.props.cell.onDidChangeEditorOptions(options => {
|
|
115
|
+
this.editor?.getControl().updateOptions(options);
|
|
116
|
+
}));
|
|
117
|
+
|
|
118
|
+
this.toDispose.push(this.props.cell.onDidChangeLanguage(language => {
|
|
119
|
+
this.editor?.setLanguage(language);
|
|
120
|
+
}));
|
|
121
|
+
|
|
122
|
+
this.toDispose.push(this.props.cell.onDidFindMatches(matches => {
|
|
123
|
+
this.matches = matches;
|
|
124
|
+
animationFrame().then(() => this.setMatches());
|
|
125
|
+
}));
|
|
126
|
+
|
|
127
|
+
this.toDispose.push(this.props.cell.onDidSelectFindMatch(match => this.centerEditorInView()));
|
|
128
|
+
|
|
129
|
+
this.toDispose.push(this.props.notebookModel.onDidChangeSelectedCell(e => {
|
|
130
|
+
if (e.cell !== this.props.cell && this.editor?.getControl().hasTextFocus()) {
|
|
131
|
+
this.props.notebookContextManager.context?.focus();
|
|
132
|
+
}
|
|
133
|
+
}));
|
|
134
|
+
if (!this.props.notebookViewportService || (this.container && this.props.notebookViewportService.isElementInViewport(this.container))) {
|
|
135
|
+
this.initEditor();
|
|
136
|
+
} else {
|
|
137
|
+
const disposable = this.props.notebookViewportService?.onDidChangeViewport(() => {
|
|
138
|
+
if (!this.editor && this.container && this.props.notebookViewportService!.isElementInViewport(this.container)) {
|
|
139
|
+
this.initEditor();
|
|
140
|
+
disposable.dispose();
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
this.toDispose.push(disposable);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
this.toDispose.push(this.props.cell.onDidRequestCenterEditor(() => {
|
|
147
|
+
this.centerEditorInView();
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
override componentWillUnmount(): void {
|
|
152
|
+
this.disposeEditor();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
protected disposeEditor(): void {
|
|
156
|
+
this.toDispose.dispose();
|
|
157
|
+
this.toDispose = new DisposableCollection();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
protected centerEditorInView(): void {
|
|
161
|
+
const editorDomNode = this.editor?.getControl().getDomNode();
|
|
162
|
+
if (editorDomNode) {
|
|
163
|
+
editorDomNode.scrollIntoView({
|
|
164
|
+
behavior: 'instant',
|
|
165
|
+
block: 'center'
|
|
166
|
+
});
|
|
167
|
+
} else {
|
|
168
|
+
this.container?.scrollIntoView({
|
|
169
|
+
behavior: 'instant',
|
|
170
|
+
block: 'center'
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
protected async initEditor(): Promise<void> {
|
|
176
|
+
const { cell, notebookModel, monacoServices } = this.props;
|
|
177
|
+
if (this.container) {
|
|
178
|
+
const editorNode = this.container;
|
|
179
|
+
editorNode.style.height = '';
|
|
180
|
+
const editorModel = await cell.resolveTextModel();
|
|
181
|
+
const uri = cell.uri;
|
|
182
|
+
this.editor = new SimpleMonacoEditor(uri,
|
|
183
|
+
editorModel,
|
|
184
|
+
editorNode,
|
|
185
|
+
monacoServices,
|
|
186
|
+
{ ...DEFAULT_EDITOR_OPTIONS, ...cell.editorOptions },
|
|
187
|
+
[[IContextKeyService, this.props.notebookContextManager.scopedStore]],
|
|
188
|
+
{ contributions: EditorExtensionsRegistry.getEditorContributions().filter(c => c.id !== 'editor.contrib.findController') });
|
|
189
|
+
this.toDispose.push(this.editor);
|
|
190
|
+
this.editor.setLanguage(cell.language);
|
|
191
|
+
this.toDispose.push(this.editor.getControl().onDidContentSizeChange(() => {
|
|
192
|
+
editorNode.style.height = this.editor!.getControl().getContentHeight() + 7 + 'px';
|
|
193
|
+
this.editor!.setSize({ width: -1, height: this.editor!.getControl().getContentHeight() });
|
|
194
|
+
}));
|
|
195
|
+
this.toDispose.push(this.editor.onDocumentContentChanged(e => {
|
|
196
|
+
notebookModel.cellDirtyChanged(cell, true);
|
|
197
|
+
}));
|
|
198
|
+
this.toDispose.push(this.editor.getControl().onDidFocusEditorText(() => {
|
|
199
|
+
this.props.notebookModel.setSelectedCell(cell, false);
|
|
200
|
+
}));
|
|
201
|
+
this.toDispose.push(this.editor.getControl().onDidChangeCursorSelection(e => {
|
|
202
|
+
const selectedText = this.editor!.getControl().getModel()!.getValueInRange(e.selection);
|
|
203
|
+
this.props.notebookModel.selectedText = selectedText;
|
|
204
|
+
}));
|
|
205
|
+
this.toDispose.push(this.editor.getControl().onDidChangeCursorPosition(e => {
|
|
206
|
+
if (e.secondaryPositions.length === 0) {
|
|
207
|
+
this.props.notebookContextManager.scopedStore.setContext(NOTEBOOK_CELL_CURSOR_FIRST_LINE, e.position.lineNumber === 1);
|
|
208
|
+
this.props.notebookContextManager.scopedStore.setContext(NOTEBOOK_CELL_CURSOR_LAST_LINE,
|
|
209
|
+
e.position.lineNumber === this.editor!.getControl().getModel()!.getLineCount());
|
|
210
|
+
} else {
|
|
211
|
+
this.props.notebookContextManager.scopedStore.setContext(NOTEBOOK_CELL_CURSOR_FIRST_LINE, false);
|
|
212
|
+
this.props.notebookContextManager.scopedStore.setContext(NOTEBOOK_CELL_CURSOR_LAST_LINE, false);
|
|
213
|
+
}
|
|
214
|
+
}));
|
|
215
|
+
if (cell.editing && notebookModel.selectedCell === cell) {
|
|
216
|
+
this.editor.getControl().focus();
|
|
217
|
+
}
|
|
218
|
+
this.setMatches();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
protected setMatches(): void {
|
|
223
|
+
if (!this.editor) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const decorations: IModelDeltaDecoration[] = [];
|
|
227
|
+
for (const match of this.matches) {
|
|
228
|
+
const decoration = match.selected ? CURRENT_FIND_MATCH_DECORATION : FIND_MATCH_DECORATION;
|
|
229
|
+
decorations.push({
|
|
230
|
+
range: {
|
|
231
|
+
startLineNumber: match.range.start.line,
|
|
232
|
+
startColumn: match.range.start.character,
|
|
233
|
+
endLineNumber: match.range.end.line,
|
|
234
|
+
endColumn: match.range.end.character
|
|
235
|
+
},
|
|
236
|
+
options: decoration
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
this.oldMatchDecorations = this.editor.getControl()
|
|
241
|
+
.changeDecorations(accessor => accessor.deltaDecorations(this.oldMatchDecorations, decorations));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
protected setContainer(component: HTMLDivElement | null): void {
|
|
245
|
+
this.container = component ?? undefined;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
protected handleResize = () => {
|
|
249
|
+
this.editor?.refresh();
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
protected estimateHeight(): string {
|
|
253
|
+
const lineHeight = this.props.fontInfo?.lineHeight ?? 20;
|
|
254
|
+
return this.props.cell.text.split(OS.backend.EOL).length * lineHeight + 10 + 7 + 'px';
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
override render(): React.ReactNode {
|
|
258
|
+
return <div className='theia-notebook-cell-editor' onResize={this.handleResize} id={this.props.cell.uri.toString()}
|
|
259
|
+
ref={container => this.setContainer(container)} style={{ height: this.editor ? undefined : this.estimateHeight() }}>
|
|
260
|
+
</div >;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
}
|