@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.
Files changed (88) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/contributions/notebook-actions-contribution.d.ts +1 -0
  3. package/lib/browser/contributions/notebook-actions-contribution.d.ts.map +1 -1
  4. package/lib/browser/contributions/notebook-actions-contribution.js +31 -5
  5. package/lib/browser/contributions/notebook-actions-contribution.js.map +1 -1
  6. package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts +2 -0
  7. package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts.map +1 -1
  8. package/lib/browser/contributions/notebook-cell-actions-contribution.js +41 -7
  9. package/lib/browser/contributions/notebook-cell-actions-contribution.js.map +1 -1
  10. package/lib/browser/contributions/notebook-status-bar-contribution.d.ts +14 -0
  11. package/lib/browser/contributions/notebook-status-bar-contribution.d.ts.map +1 -0
  12. package/lib/browser/contributions/notebook-status-bar-contribution.js +75 -0
  13. package/lib/browser/contributions/notebook-status-bar-contribution.js.map +1 -0
  14. package/lib/browser/notebook-editor-widget.d.ts.map +1 -1
  15. package/lib/browser/notebook-editor-widget.js +3 -5
  16. package/lib/browser/notebook-editor-widget.js.map +1 -1
  17. package/lib/browser/notebook-frontend-module.d.ts.map +1 -1
  18. package/lib/browser/notebook-frontend-module.js +3 -0
  19. package/lib/browser/notebook-frontend-module.js.map +1 -1
  20. package/lib/browser/notebook-open-handler.d.ts +3 -2
  21. package/lib/browser/notebook-open-handler.d.ts.map +1 -1
  22. package/lib/browser/notebook-open-handler.js +12 -5
  23. package/lib/browser/notebook-open-handler.js.map +1 -1
  24. package/lib/browser/view/notebook-cell-editor.d.ts +1 -0
  25. package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -1
  26. package/lib/browser/view/notebook-cell-editor.js +30 -16
  27. package/lib/browser/view/notebook-cell-editor.js.map +1 -1
  28. package/lib/browser/view/notebook-cell-list-view.d.ts +6 -4
  29. package/lib/browser/view/notebook-cell-list-view.d.ts.map +1 -1
  30. package/lib/browser/view/notebook-cell-list-view.js +20 -13
  31. package/lib/browser/view/notebook-cell-list-view.js.map +1 -1
  32. package/lib/browser/view-model/notebook-cell-model.d.ts +3 -0
  33. package/lib/browser/view-model/notebook-cell-model.d.ts.map +1 -1
  34. package/lib/browser/view-model/notebook-cell-model.js +5 -0
  35. package/lib/browser/view-model/notebook-cell-model.js.map +1 -1
  36. package/package.json +8 -8
  37. package/src/browser/contributions/cell-operations.ts +44 -44
  38. package/src/browser/contributions/notebook-actions-contribution.ts +379 -350
  39. package/src/browser/contributions/notebook-cell-actions-contribution.ts +525 -487
  40. package/src/browser/contributions/notebook-color-contribution.ts +268 -268
  41. package/src/browser/contributions/notebook-context-keys.ts +113 -113
  42. package/src/browser/contributions/notebook-label-provider-contribution.ts +85 -85
  43. package/src/browser/contributions/notebook-outline-contribution.ts +114 -114
  44. package/src/browser/contributions/notebook-output-action-contribution.ts +82 -82
  45. package/src/browser/contributions/notebook-preferences.ts +92 -92
  46. package/src/browser/contributions/notebook-status-bar-contribution.ts +77 -0
  47. package/src/browser/contributions/notebook-undo-redo-handler.ts +41 -41
  48. package/src/browser/index.ts +27 -27
  49. package/src/browser/notebook-cell-resource-resolver.ts +130 -130
  50. package/src/browser/notebook-editor-widget-factory.ts +82 -82
  51. package/src/browser/notebook-editor-widget.tsx +330 -331
  52. package/src/browser/notebook-frontend-module.ts +119 -115
  53. package/src/browser/notebook-open-handler.ts +120 -114
  54. package/src/browser/notebook-output-utils.ts +119 -119
  55. package/src/browser/notebook-renderer-registry.ts +85 -85
  56. package/src/browser/notebook-type-registry.ts +54 -54
  57. package/src/browser/notebook-types.ts +186 -186
  58. package/src/browser/renderers/cell-output-webview.ts +33 -33
  59. package/src/browser/service/notebook-clipboard-service.ts +43 -43
  60. package/src/browser/service/notebook-context-manager.ts +162 -162
  61. package/src/browser/service/notebook-editor-widget-service.ts +101 -101
  62. package/src/browser/service/notebook-execution-service.ts +139 -139
  63. package/src/browser/service/notebook-execution-state-service.ts +311 -311
  64. package/src/browser/service/notebook-kernel-history-service.ts +124 -124
  65. package/src/browser/service/notebook-kernel-quick-pick-service.ts +479 -479
  66. package/src/browser/service/notebook-kernel-service.ts +357 -357
  67. package/src/browser/service/notebook-model-resolver-service.ts +160 -160
  68. package/src/browser/service/notebook-monaco-text-model-service.ts +48 -48
  69. package/src/browser/service/notebook-options.ts +155 -155
  70. package/src/browser/service/notebook-renderer-messaging-service.ts +121 -121
  71. package/src/browser/service/notebook-service.ts +215 -215
  72. package/src/browser/style/index.css +483 -471
  73. package/src/browser/view/notebook-cell-editor.tsx +263 -247
  74. package/src/browser/view/notebook-cell-list-view.tsx +279 -262
  75. package/src/browser/view/notebook-cell-toolbar-factory.tsx +102 -102
  76. package/src/browser/view/notebook-cell-toolbar.tsx +74 -74
  77. package/src/browser/view/notebook-code-cell-view.tsx +350 -350
  78. package/src/browser/view/notebook-find-widget.tsx +335 -335
  79. package/src/browser/view/notebook-main-toolbar.tsx +235 -235
  80. package/src/browser/view/notebook-markdown-cell-view.tsx +208 -208
  81. package/src/browser/view/notebook-viewport-service.ts +61 -61
  82. package/src/browser/view-model/notebook-cell-model.ts +473 -466
  83. package/src/browser/view-model/notebook-cell-output-model.ts +100 -100
  84. package/src/browser/view-model/notebook-model.ts +550 -550
  85. package/src/common/index.ts +18 -18
  86. package/src/common/notebook-common.ts +337 -337
  87. package/src/common/notebook-protocol.ts +35 -35
  88. 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.onDidChangeEditorOptions(options => {
105
- this.editor?.getControl().updateOptions(options);
106
- }));
107
-
108
- this.toDispose.push(this.props.cell.onDidChangeLanguage(language => {
109
- this.editor?.setLanguage(language);
110
- }));
111
-
112
- this.toDispose.push(this.props.cell.onDidFindMatches(matches => {
113
- this.matches = matches;
114
- animationFrame().then(() => this.setMatches());
115
- }));
116
-
117
- this.toDispose.push(this.props.cell.onDidSelectFindMatch(match => {
118
- const editorDomNode = this.editor?.getControl().getDomNode();
119
- if (editorDomNode) {
120
- editorDomNode.scrollIntoView({
121
- behavior: 'instant',
122
- block: 'center'
123
- });
124
- } else {
125
- this.container?.scrollIntoView({
126
- behavior: 'instant',
127
- block: 'center'
128
- });
129
- }
130
- }));
131
-
132
- this.toDispose.push(this.props.notebookModel.onDidChangeSelectedCell(e => {
133
- if (e.cell !== this.props.cell && this.editor?.getControl().hasTextFocus()) {
134
- this.props.notebookContextManager.context?.focus();
135
- }
136
- }));
137
- if (!this.props.notebookViewportService || (this.container && this.props.notebookViewportService.isElementInViewport(this.container))) {
138
- this.initEditor();
139
- } else {
140
- const disposable = this.props.notebookViewportService?.onDidChangeViewport(() => {
141
- if (!this.editor && this.container && this.props.notebookViewportService!.isElementInViewport(this.container)) {
142
- this.initEditor();
143
- disposable.dispose();
144
- }
145
- });
146
- this.toDispose.push(disposable);
147
- }
148
- }
149
-
150
- override componentWillUnmount(): void {
151
- this.disposeEditor();
152
- }
153
-
154
- protected disposeEditor(): void {
155
- this.toDispose.dispose();
156
- this.toDispose = new DisposableCollection();
157
- }
158
-
159
- protected async initEditor(): Promise<void> {
160
- const { cell, notebookModel, monacoServices } = this.props;
161
- if (this.container) {
162
- const editorNode = this.container;
163
- editorNode.style.height = '';
164
- const editorModel = await cell.resolveTextModel();
165
- const uri = cell.uri;
166
- this.editor = new SimpleMonacoEditor(uri,
167
- editorModel,
168
- editorNode,
169
- monacoServices,
170
- { ...DEFAULT_EDITOR_OPTIONS, ...cell.editorOptions },
171
- [[IContextKeyService, this.props.notebookContextManager.scopedStore]],
172
- { contributions: EditorExtensionsRegistry.getEditorContributions().filter(c => c.id !== 'editor.contrib.findController') });
173
- this.toDispose.push(this.editor);
174
- this.editor.setLanguage(cell.language);
175
- this.toDispose.push(this.editor.getControl().onDidContentSizeChange(() => {
176
- editorNode.style.height = this.editor!.getControl().getContentHeight() + 7 + 'px';
177
- this.editor!.setSize({ width: -1, height: this.editor!.getControl().getContentHeight() });
178
- }));
179
- this.toDispose.push(this.editor.onDocumentContentChanged(e => {
180
- notebookModel.cellDirtyChanged(cell, true);
181
- }));
182
- this.toDispose.push(this.editor.getControl().onDidFocusEditorText(() => {
183
- this.props.notebookModel.setSelectedCell(cell, false);
184
- }));
185
- this.toDispose.push(this.editor.getControl().onDidChangeCursorSelection(e => {
186
- const selectedText = this.editor!.getControl().getModel()!.getValueInRange(e.selection);
187
- this.props.notebookModel.selectedText = selectedText;
188
- }));
189
- this.toDispose.push(this.editor.getControl().onDidChangeCursorPosition(e => {
190
- if (e.secondaryPositions.length === 0) {
191
- this.props.notebookContextManager.scopedStore.setContext(NOTEBOOK_CELL_CURSOR_FIRST_LINE, e.position.lineNumber === 1);
192
- this.props.notebookContextManager.scopedStore.setContext(NOTEBOOK_CELL_CURSOR_LAST_LINE,
193
- e.position.lineNumber === this.editor!.getControl().getModel()!.getLineCount());
194
- } else {
195
- this.props.notebookContextManager.scopedStore.setContext(NOTEBOOK_CELL_CURSOR_FIRST_LINE, false);
196
- this.props.notebookContextManager.scopedStore.setContext(NOTEBOOK_CELL_CURSOR_LAST_LINE, false);
197
- }
198
- }));
199
- if (cell.editing && notebookModel.selectedCell === cell) {
200
- this.editor.getControl().focus();
201
- }
202
- this.setMatches();
203
- }
204
- }
205
-
206
- protected setMatches(): void {
207
- if (!this.editor) {
208
- return;
209
- }
210
- const decorations: IModelDeltaDecoration[] = [];
211
- for (const match of this.matches) {
212
- const decoration = match.selected ? CURRENT_FIND_MATCH_DECORATION : FIND_MATCH_DECORATION;
213
- decorations.push({
214
- range: {
215
- startLineNumber: match.range.start.line,
216
- startColumn: match.range.start.character,
217
- endLineNumber: match.range.end.line,
218
- endColumn: match.range.end.character
219
- },
220
- options: decoration
221
- });
222
- }
223
-
224
- this.oldMatchDecorations = this.editor.getControl()
225
- .changeDecorations(accessor => accessor.deltaDecorations(this.oldMatchDecorations, decorations));
226
- }
227
-
228
- protected setContainer(component: HTMLDivElement | null): void {
229
- this.container = component ?? undefined;
230
- };
231
-
232
- protected handleResize = () => {
233
- this.editor?.refresh();
234
- };
235
-
236
- protected estimateHeight(): string {
237
- const lineHeight = this.props.fontInfo?.lineHeight ?? 20;
238
- return this.props.cell.text.split(OS.backend.EOL).length * lineHeight + 10 + 7 + 'px';
239
- }
240
-
241
- override render(): React.ReactNode {
242
- return <div className='theia-notebook-cell-editor' onResize={this.handleResize} id={this.props.cell.uri.toString()}
243
- ref={container => this.setContainer(container)} style={{ height: this.editor ? undefined : this.estimateHeight() }}>
244
- </div >;
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
+ }