@theia/notebook 1.46.1 → 1.47.0
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/lib/browser/contributions/notebook-actions-contribution.d.ts +3 -1
- package/lib/browser/contributions/notebook-actions-contribution.d.ts.map +1 -1
- package/lib/browser/contributions/notebook-actions-contribution.js +38 -37
- package/lib/browser/contributions/notebook-actions-contribution.js.map +1 -1
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts +5 -1
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts.map +1 -1
- package/lib/browser/contributions/notebook-cell-actions-contribution.js +29 -36
- package/lib/browser/contributions/notebook-cell-actions-contribution.js.map +1 -1
- package/lib/browser/contributions/notebook-color-contribution.js +2 -7
- package/lib/browser/contributions/notebook-color-contribution.js.map +1 -1
- package/lib/browser/index.js +12 -21
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/notebook-cell-resource-resolver.d.ts +10 -5
- package/lib/browser/notebook-cell-resource-resolver.d.ts.map +1 -1
- package/lib/browser/notebook-cell-resource-resolver.js +18 -17
- package/lib/browser/notebook-cell-resource-resolver.js.map +1 -1
- package/lib/browser/notebook-editor-widget-factory.js +10 -18
- package/lib/browser/notebook-editor-widget-factory.js.map +1 -1
- package/lib/browser/notebook-editor-widget.d.ts +20 -0
- package/lib/browser/notebook-editor-widget.d.ts.map +1 -1
- package/lib/browser/notebook-editor-widget.js +69 -32
- package/lib/browser/notebook-editor-widget.js.map +1 -1
- package/lib/browser/notebook-open-handler.js +4 -12
- package/lib/browser/notebook-open-handler.js.map +1 -1
- package/lib/browser/notebook-renderer-registry.d.ts +7 -0
- package/lib/browser/notebook-renderer-registry.d.ts.map +1 -1
- package/lib/browser/notebook-renderer-registry.js +13 -7
- package/lib/browser/notebook-renderer-registry.js.map +1 -1
- package/lib/browser/notebook-type-registry.js +2 -7
- package/lib/browser/notebook-type-registry.js.map +1 -1
- package/lib/browser/renderers/cell-output-webview.d.ts +2 -1
- package/lib/browser/renderers/cell-output-webview.d.ts.map +1 -1
- package/lib/browser/renderers/cell-output-webview.js.map +1 -1
- package/lib/browser/service/notebook-cell-context-manager.d.ts.map +1 -1
- package/lib/browser/service/notebook-cell-context-manager.js +6 -16
- package/lib/browser/service/notebook-cell-context-manager.js.map +1 -1
- package/lib/browser/service/notebook-editor-widget-service.js +8 -16
- package/lib/browser/service/notebook-editor-widget-service.js.map +1 -1
- package/lib/browser/service/notebook-execution-service.js +12 -20
- package/lib/browser/service/notebook-execution-service.js.map +1 -1
- package/lib/browser/service/notebook-execution-state-service.d.ts.map +1 -1
- package/lib/browser/service/notebook-execution-state-service.js +5 -14
- package/lib/browser/service/notebook-execution-state-service.js.map +1 -1
- package/lib/browser/service/notebook-kernel-history-service.js +12 -20
- package/lib/browser/service/notebook-kernel-history-service.js.map +1 -1
- package/lib/browser/service/notebook-kernel-quick-pick-service.js +12 -20
- package/lib/browser/service/notebook-kernel-quick-pick-service.js.map +1 -1
- package/lib/browser/service/notebook-kernel-service.d.ts +23 -12
- package/lib/browser/service/notebook-kernel-service.d.ts.map +1 -1
- package/lib/browser/service/notebook-kernel-service.js +11 -26
- package/lib/browser/service/notebook-kernel-service.js.map +1 -1
- package/lib/browser/service/notebook-model-resolver-service.d.ts +3 -2
- package/lib/browser/service/notebook-model-resolver-service.d.ts.map +1 -1
- package/lib/browser/service/notebook-model-resolver-service.js +21 -22
- package/lib/browser/service/notebook-model-resolver-service.js.map +1 -1
- package/lib/browser/service/notebook-renderer-messaging-service.d.ts +1 -0
- package/lib/browser/service/notebook-renderer-messaging-service.d.ts.map +1 -1
- package/lib/browser/service/notebook-renderer-messaging-service.js +12 -7
- package/lib/browser/service/notebook-renderer-messaging-service.js.map +1 -1
- package/lib/browser/service/notebook-service.d.ts +2 -2
- package/lib/browser/service/notebook-service.d.ts.map +1 -1
- package/lib/browser/service/notebook-service.js +13 -21
- package/lib/browser/service/notebook-service.js.map +1 -1
- package/lib/browser/view/notebook-cell-list-view.d.ts +3 -1
- package/lib/browser/view/notebook-cell-list-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-list-view.js +24 -7
- package/lib/browser/view/notebook-cell-list-view.js.map +1 -1
- package/lib/browser/view/notebook-cell-toolbar-factory.d.ts +1 -0
- package/lib/browser/view/notebook-cell-toolbar-factory.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-toolbar-factory.js +11 -18
- package/lib/browser/view/notebook-cell-toolbar-factory.js.map +1 -1
- package/lib/browser/view/notebook-cell-toolbar.js +2 -2
- package/lib/browser/view/notebook-cell-toolbar.js.map +1 -1
- package/lib/browser/view/notebook-code-cell-view.d.ts +6 -2
- package/lib/browser/view/notebook-code-cell-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-code-cell-view.js +41 -30
- package/lib/browser/view/notebook-code-cell-view.js.map +1 -1
- package/lib/browser/view/notebook-main-toolbar.d.ts.map +1 -1
- package/lib/browser/view/notebook-main-toolbar.js +19 -22
- package/lib/browser/view/notebook-main-toolbar.js.map +1 -1
- package/lib/browser/view/notebook-markdown-cell-view.js +6 -14
- package/lib/browser/view/notebook-markdown-cell-view.js.map +1 -1
- package/lib/browser/view-model/notebook-cell-model.d.ts +1 -1
- package/lib/browser/view-model/notebook-cell-model.d.ts.map +1 -1
- package/lib/browser/view-model/notebook-cell-model.js +17 -22
- package/lib/browser/view-model/notebook-cell-model.js.map +1 -1
- package/lib/browser/view-model/notebook-model.d.ts +17 -14
- package/lib/browser/view-model/notebook-model.d.ts.map +1 -1
- package/lib/browser/view-model/notebook-model.js +30 -27
- package/lib/browser/view-model/notebook-model.js.map +1 -1
- package/lib/common/index.js +3 -12
- package/lib/common/index.js.map +1 -1
- package/lib/common/notebook-common.d.ts +1 -2
- package/lib/common/notebook-common.d.ts.map +1 -1
- package/lib/common/notebook-common.js.map +1 -1
- package/package.json +9 -8
- package/src/browser/contributions/notebook-actions-contribution.ts +41 -24
- package/src/browser/contributions/notebook-cell-actions-contribution.ts +24 -15
- package/src/browser/notebook-cell-resource-resolver.ts +24 -7
- package/src/browser/notebook-editor-widget.tsx +68 -6
- package/src/browser/notebook-renderer-registry.ts +19 -0
- package/src/browser/renderers/cell-output-webview.ts +2 -1
- package/src/browser/service/notebook-cell-context-manager.ts +0 -1
- package/src/browser/service/notebook-execution-state-service.ts +2 -3
- package/src/browser/service/notebook-kernel-service.ts +18 -21
- package/src/browser/service/notebook-model-resolver-service.ts +14 -10
- package/src/browser/service/notebook-renderer-messaging-service.ts +9 -1
- package/src/browser/service/notebook-service.ts +4 -4
- package/src/browser/style/index.css +17 -3
- package/src/browser/view/notebook-cell-list-view.tsx +34 -11
- package/src/browser/view/notebook-cell-toolbar-factory.tsx +2 -0
- package/src/browser/view/notebook-cell-toolbar.tsx +2 -2
- package/src/browser/view/notebook-code-cell-view.tsx +39 -14
- package/src/browser/view/notebook-main-toolbar.tsx +10 -4
- package/src/browser/view-model/notebook-cell-model.ts +5 -3
- package/src/browser/view-model/notebook-model.ts +27 -14
- package/src/common/notebook-common.ts +1 -2
|
@@ -61,7 +61,7 @@ export class NotebookCodeCellRenderer implements CellRenderer {
|
|
|
61
61
|
</div>
|
|
62
62
|
</div>
|
|
63
63
|
<div className='theia-notebook-cell-with-sidebar'>
|
|
64
|
-
<NotebookCodeCellOutputs cell={cell} outputWebviewFactory={this.cellOutputWebviewFactory}
|
|
64
|
+
<NotebookCodeCellOutputs cell={cell} notebook={notebookModel} outputWebviewFactory={this.cellOutputWebviewFactory}
|
|
65
65
|
renderSidebar={() =>
|
|
66
66
|
this.notebookCellToolbarFactory.renderSidebar(NotebookCellActionContribution.OUTPUT_SIDEBAR_MENU, notebookModel, cell, cell.outputs[0])} />
|
|
67
67
|
</div>
|
|
@@ -71,21 +71,40 @@ export class NotebookCodeCellRenderer implements CellRenderer {
|
|
|
71
71
|
|
|
72
72
|
export interface NotebookCodeCellStatusProps {
|
|
73
73
|
cell: NotebookCellModel;
|
|
74
|
-
executionStateService: NotebookExecutionStateService
|
|
74
|
+
executionStateService: NotebookExecutionStateService;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
export
|
|
77
|
+
export interface NotebookCodeCellStatusState {
|
|
78
|
+
currentExecution?: CellExecution;
|
|
79
|
+
executionTime: number;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export class NotebookCodeCellStatus extends React.Component<NotebookCodeCellStatusProps, NotebookCodeCellStatusState> {
|
|
78
83
|
|
|
79
84
|
protected toDispose = new DisposableCollection();
|
|
80
85
|
|
|
81
86
|
constructor(props: NotebookCodeCellStatusProps) {
|
|
82
87
|
super(props);
|
|
83
88
|
|
|
84
|
-
this.state = {
|
|
89
|
+
this.state = {
|
|
90
|
+
executionTime: 0
|
|
91
|
+
};
|
|
85
92
|
|
|
93
|
+
let currentInterval: NodeJS.Timeout | undefined;
|
|
86
94
|
this.toDispose.push(props.executionStateService.onDidChangeExecution(event => {
|
|
87
95
|
if (event.affectsCell(this.props.cell.uri)) {
|
|
88
|
-
this.setState({ currentExecution: event.changed });
|
|
96
|
+
this.setState({ currentExecution: event.changed, executionTime: 0 });
|
|
97
|
+
clearInterval(currentInterval);
|
|
98
|
+
if (event.changed?.state === NotebookCellExecutionState.Executing) {
|
|
99
|
+
const startTime = Date.now();
|
|
100
|
+
// The resolution of the time display is only a single digit after the decimal point.
|
|
101
|
+
// Therefore, we only need to update the display every 100ms.
|
|
102
|
+
currentInterval = setInterval(() => {
|
|
103
|
+
this.setState({
|
|
104
|
+
executionTime: Date.now() - startTime
|
|
105
|
+
});
|
|
106
|
+
}, 100);
|
|
107
|
+
}
|
|
89
108
|
}
|
|
90
109
|
}));
|
|
91
110
|
}
|
|
@@ -126,22 +145,28 @@ export class NotebookCodeCellStatus extends React.Component<NotebookCodeCellStat
|
|
|
126
145
|
{iconClasses &&
|
|
127
146
|
<>
|
|
128
147
|
<span className={`${iconClasses} notebook-cell-status-item`} style={{ color }}></span>
|
|
129
|
-
<div className='notebook-cell-status-item'>{this.getExecutionTime()}</div>
|
|
148
|
+
<div className='notebook-cell-status-item'>{this.renderTime(this.getExecutionTime())}</div>
|
|
130
149
|
</>}
|
|
131
150
|
</>;
|
|
132
151
|
}
|
|
133
152
|
|
|
134
|
-
private getExecutionTime():
|
|
153
|
+
private getExecutionTime(): number {
|
|
135
154
|
const { runStartTime, runEndTime } = this.props.cell.internalMetadata;
|
|
136
|
-
|
|
137
|
-
|
|
155
|
+
const { executionTime } = this.state;
|
|
156
|
+
if (runStartTime !== undefined && runEndTime !== undefined) {
|
|
157
|
+
return runEndTime - runStartTime;
|
|
138
158
|
}
|
|
139
|
-
return
|
|
159
|
+
return executionTime;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private renderTime(ms: number): string {
|
|
163
|
+
return `${(ms / 1000).toLocaleString(undefined, { maximumFractionDigits: 1, minimumFractionDigits: 1 })}s`;
|
|
140
164
|
}
|
|
141
165
|
}
|
|
142
166
|
|
|
143
167
|
interface NotebookCellOutputProps {
|
|
144
168
|
cell: NotebookCellModel;
|
|
169
|
+
notebook: NotebookModel;
|
|
145
170
|
outputWebviewFactory: CellOutputWebviewFactory;
|
|
146
171
|
renderSidebar: () => React.ReactNode;
|
|
147
172
|
}
|
|
@@ -158,14 +183,14 @@ export class NotebookCodeCellOutputs extends React.Component<NotebookCellOutputP
|
|
|
158
183
|
}
|
|
159
184
|
|
|
160
185
|
override async componentDidMount(): Promise<void> {
|
|
161
|
-
const { cell, outputWebviewFactory } = this.props;
|
|
186
|
+
const { cell, notebook, outputWebviewFactory } = this.props;
|
|
162
187
|
this.toDispose.push(cell.onDidChangeOutputs(async () => {
|
|
163
188
|
if (!this.outputsWebviewPromise && cell.outputs.length > 0) {
|
|
164
|
-
this.outputsWebviewPromise = outputWebviewFactory(cell).then(webview => {
|
|
189
|
+
this.outputsWebviewPromise = outputWebviewFactory(cell, notebook).then(webview => {
|
|
165
190
|
this.outputsWebview = webview;
|
|
166
191
|
this.forceUpdate();
|
|
167
192
|
return webview;
|
|
168
|
-
|
|
193
|
+
});
|
|
169
194
|
this.forceUpdate();
|
|
170
195
|
} else if (this.outputsWebviewPromise && cell.outputs.length === 0 && cell.internalMetadata.runEndTime) {
|
|
171
196
|
(await this.outputsWebviewPromise).dispose();
|
|
@@ -175,7 +200,7 @@ export class NotebookCodeCellOutputs extends React.Component<NotebookCellOutputP
|
|
|
175
200
|
}
|
|
176
201
|
}));
|
|
177
202
|
if (cell.outputs.length > 0) {
|
|
178
|
-
this.outputsWebviewPromise = outputWebviewFactory(cell).then(webview => {
|
|
203
|
+
this.outputsWebviewPromise = outputWebviewFactory(cell, notebook).then(webview => {
|
|
179
204
|
this.outputsWebview = webview;
|
|
180
205
|
this.forceUpdate();
|
|
181
206
|
return webview;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
//
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
|
-
import { CommandRegistry, CompoundMenuNodeRole, DisposableCollection, MenuModelRegistry, MenuNode, nls } from '@theia/core';
|
|
16
|
+
import { ArrayUtils, CommandRegistry, CompoundMenuNodeRole, DisposableCollection, MenuModelRegistry, MenuNode, nls } from '@theia/core';
|
|
17
17
|
import * as React from '@theia/core/shared/react';
|
|
18
18
|
import { codicon } from '@theia/core/lib/browser';
|
|
19
19
|
import { NotebookCommands, NotebookMenus } from '../contributions/notebook-actions-contribution';
|
|
@@ -21,6 +21,7 @@ import { NotebookModel } from '../view-model/notebook-model';
|
|
|
21
21
|
import { NotebookKernelService } from '../service/notebook-kernel-service';
|
|
22
22
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
23
23
|
import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
|
|
24
|
+
import { NotebookCommand } from '../../common';
|
|
24
25
|
|
|
25
26
|
export interface NotebookMainToolbarProps {
|
|
26
27
|
notebookModel: NotebookModel
|
|
@@ -85,7 +86,7 @@ export class NotebookMainToolbar extends React.Component<NotebookMainToolbarProp
|
|
|
85
86
|
return <div className='theia-notebook-main-toolbar'>
|
|
86
87
|
{this.getMenuItems().map(item => this.renderMenuItem(item))}
|
|
87
88
|
<div style={{ flexGrow: 1 }}></div>
|
|
88
|
-
<div className='theia-notebook-main-toolbar-item'
|
|
89
|
+
<div className='theia-notebook-main-toolbar-item action-label'
|
|
89
90
|
onClick={() => this.props.commandRegistry.executeCommand(NotebookCommands.SELECT_KERNEL_COMMAND.id, this.props.notebookModel)}>
|
|
90
91
|
<span className={codicon('server-environment')} />
|
|
91
92
|
<span className=' theia-notebook-main-toolbar-item-text'>
|
|
@@ -97,13 +98,18 @@ export class NotebookMainToolbar extends React.Component<NotebookMainToolbarProp
|
|
|
97
98
|
|
|
98
99
|
protected renderMenuItem(item: MenuNode): React.ReactNode {
|
|
99
100
|
if (item.role === CompoundMenuNodeRole.Group) {
|
|
100
|
-
const itemNodes = item.children?.map(child => this.renderMenuItem(child))
|
|
101
|
+
const itemNodes = ArrayUtils.coalesce(item.children?.map(child => this.renderMenuItem(child)) ?? []);
|
|
101
102
|
return <React.Fragment key={item.id}>
|
|
102
103
|
{itemNodes}
|
|
103
104
|
{itemNodes && itemNodes.length > 0 && <span key={`${item.id}-separator`} className='theia-notebook-toolbar-separator'></span>}
|
|
104
105
|
</React.Fragment>;
|
|
105
106
|
} else if (!item.when || this.props.contextKeyService.match(item.when)) {
|
|
106
|
-
|
|
107
|
+
const visibleCommand = Boolean(this.props.commandRegistry.getVisibleHandler(item.command ?? '', this.props.notebookModel));
|
|
108
|
+
if (!visibleCommand) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
const title = (this.props.commandRegistry.getCommand(item.command ?? '') as NotebookCommand)?.tooltip ?? item.label;
|
|
112
|
+
return <div key={item.id} title={title} className='theia-notebook-main-toolbar-item action-label'
|
|
107
113
|
onClick={() => {
|
|
108
114
|
if (item.command) {
|
|
109
115
|
this.props.commandRegistry.executeCommand(item.command, this.props.notebookModel);
|
|
@@ -150,7 +150,7 @@ export class NotebookCellModel implements NotebookCell, Disposable {
|
|
|
150
150
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
textModel
|
|
153
|
+
protected textModel?: MonacoEditorModel;
|
|
154
154
|
|
|
155
155
|
protected htmlContext: HTMLLIElement;
|
|
156
156
|
|
|
@@ -220,12 +220,14 @@ export class NotebookCellModel implements NotebookCell, Disposable {
|
|
|
220
220
|
this.onDidChangeInternalMetadataEmitter.dispose();
|
|
221
221
|
this.onDidChangeLanguageEmitter.dispose();
|
|
222
222
|
this.notebookCellContextManager.dispose();
|
|
223
|
-
this.textModel
|
|
223
|
+
this.textModel?.dispose();
|
|
224
224
|
this.toDispose.dispose();
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
requestEdit(): void {
|
|
228
|
-
this.
|
|
228
|
+
if (!this.textModel || !this.textModel.readOnly) {
|
|
229
|
+
this.onDidRequestCellEditChangeEmitter.fire(true);
|
|
230
|
+
}
|
|
229
231
|
}
|
|
230
232
|
|
|
231
233
|
requestStopEdit(): void {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
|
-
import { Disposable, Emitter, URI } from '@theia/core';
|
|
17
|
+
import { Disposable, Emitter, Event, Resource, URI } from '@theia/core';
|
|
18
18
|
import { Saveable, SaveOptions } from '@theia/core/lib/browser';
|
|
19
19
|
import {
|
|
20
20
|
CellData, CellEditType, CellUri, NotebookCellInternalMetadata,
|
|
@@ -28,6 +28,7 @@ import { NotebookCellModel, NotebookCellModelFactory } from './notebook-cell-mod
|
|
|
28
28
|
import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service';
|
|
29
29
|
import { inject, injectable, interfaces, postConstruct } from '@theia/core/shared/inversify';
|
|
30
30
|
import { UndoRedoService } from '@theia/editor/lib/browser/undo-redo-service';
|
|
31
|
+
import { MarkdownString } from '@theia/core/lib/common/markdown-rendering';
|
|
31
32
|
|
|
32
33
|
export const NotebookModelFactory = Symbol('NotebookModelFactory');
|
|
33
34
|
|
|
@@ -42,10 +43,10 @@ export function createNotebookModelContainer(parent: interfaces.Container, props
|
|
|
42
43
|
|
|
43
44
|
const NotebookModelProps = Symbol('NotebookModelProps');
|
|
44
45
|
export interface NotebookModelProps {
|
|
45
|
-
data: NotebookData
|
|
46
|
-
|
|
47
|
-
viewType: string
|
|
48
|
-
serializer: NotebookSerializer
|
|
46
|
+
data: NotebookData;
|
|
47
|
+
resource: Resource;
|
|
48
|
+
viewType: string;
|
|
49
|
+
serializer: NotebookSerializer;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
@injectable()
|
|
@@ -63,6 +64,10 @@ export class NotebookModel implements Saveable, Disposable {
|
|
|
63
64
|
protected readonly onDidChangeContentEmitter = new Emitter<NotebookContentChangedEvent[]>();
|
|
64
65
|
readonly onDidChangeContent = this.onDidChangeContentEmitter.event;
|
|
65
66
|
|
|
67
|
+
get onDidChangeReadOnly(): Event<boolean | MarkdownString> {
|
|
68
|
+
return this.props.resource.onDidChangeReadOnly ?? Event.None;
|
|
69
|
+
}
|
|
70
|
+
|
|
66
71
|
@inject(FileService)
|
|
67
72
|
protected readonly fileService: FileService;
|
|
68
73
|
|
|
@@ -81,7 +86,7 @@ export class NotebookModel implements Saveable, Disposable {
|
|
|
81
86
|
|
|
82
87
|
protected nextHandle: number = 0;
|
|
83
88
|
|
|
84
|
-
protected _dirty
|
|
89
|
+
protected _dirty = false;
|
|
85
90
|
|
|
86
91
|
set dirty(dirty: boolean) {
|
|
87
92
|
this._dirty = dirty;
|
|
@@ -92,13 +97,17 @@ export class NotebookModel implements Saveable, Disposable {
|
|
|
92
97
|
return this._dirty;
|
|
93
98
|
}
|
|
94
99
|
|
|
100
|
+
get readOnly(): boolean | MarkdownString {
|
|
101
|
+
return this.props.resource.readOnly ?? false;
|
|
102
|
+
}
|
|
103
|
+
|
|
95
104
|
selectedCell?: NotebookCellModel;
|
|
96
105
|
protected dirtyCells: NotebookCellModel[] = [];
|
|
97
106
|
|
|
98
107
|
cells: NotebookCellModel[];
|
|
99
108
|
|
|
100
109
|
get uri(): URI {
|
|
101
|
-
return this.props.uri;
|
|
110
|
+
return this.props.resource.uri;
|
|
102
111
|
}
|
|
103
112
|
|
|
104
113
|
get viewType(): string {
|
|
@@ -112,7 +121,7 @@ export class NotebookModel implements Saveable, Disposable {
|
|
|
112
121
|
this.dirty = false;
|
|
113
122
|
|
|
114
123
|
this.cells = this.props.data.cells.map((cell, index) => this.cellModelFactory({
|
|
115
|
-
uri: CellUri.generate(this.props.uri, index),
|
|
124
|
+
uri: CellUri.generate(this.props.resource.uri, index),
|
|
116
125
|
handle: index,
|
|
117
126
|
source: cell.source,
|
|
118
127
|
language: cell.language,
|
|
@@ -294,7 +303,7 @@ export class NotebookModel implements Saveable, Disposable {
|
|
|
294
303
|
}
|
|
295
304
|
}
|
|
296
305
|
|
|
297
|
-
|
|
306
|
+
protected async replaceCells(start: number, deleteCount: number, newCells: CellData[], computeUndoRedo: boolean): Promise<void> {
|
|
298
307
|
const cells = newCells.map(cell => {
|
|
299
308
|
const handle = this.nextHandle++;
|
|
300
309
|
return this.cellModelFactory({
|
|
@@ -325,11 +334,15 @@ export class NotebookModel implements Saveable, Disposable {
|
|
|
325
334
|
async () => this.replaceCells(start, deleteCount, newCells, false));
|
|
326
335
|
}
|
|
327
336
|
|
|
337
|
+
// Ensure that all text model have been created
|
|
338
|
+
// Otherwise we run into a race condition once we fire `onDidChangeContent`
|
|
339
|
+
await Promise.all(cells.map(cell => cell.resolveTextModel()));
|
|
340
|
+
|
|
328
341
|
this.onDidAddOrRemoveCellEmitter.fire({ rawEvent: { kind: NotebookCellsChangeType.ModelChange, changes }, newCellIds: cells.map(cell => cell.handle) });
|
|
329
342
|
this.onDidChangeContentEmitter.fire([{ kind: NotebookCellsChangeType.ModelChange, changes }]);
|
|
330
343
|
}
|
|
331
344
|
|
|
332
|
-
|
|
345
|
+
protected changeCellInternalMetadataPartial(cell: NotebookCellModel, internalMetadata: NullablePartialNotebookCellInternalMetadata): void {
|
|
333
346
|
const newInternalMetadata: NotebookCellInternalMetadata = {
|
|
334
347
|
...cell.internalMetadata
|
|
335
348
|
};
|
|
@@ -345,7 +358,7 @@ export class NotebookModel implements Saveable, Disposable {
|
|
|
345
358
|
]);
|
|
346
359
|
}
|
|
347
360
|
|
|
348
|
-
|
|
361
|
+
protected updateNotebookMetadata(metadata: NotebookDocumentMetadata, computeUndoRedo: boolean): void {
|
|
349
362
|
const oldMetadata = this.metadata;
|
|
350
363
|
if (computeUndoRedo) {
|
|
351
364
|
this.undoRedoService.pushElement(this.uri,
|
|
@@ -358,7 +371,7 @@ export class NotebookModel implements Saveable, Disposable {
|
|
|
358
371
|
this.onDidChangeContentEmitter.fire([{ kind: NotebookCellsChangeType.ChangeDocumentMetadata, metadata: this.metadata }]);
|
|
359
372
|
}
|
|
360
373
|
|
|
361
|
-
|
|
374
|
+
protected changeCellLanguage(cell: NotebookCellModel, languageId: string, computeUndoRedo: boolean): void {
|
|
362
375
|
if (cell.language === languageId) {
|
|
363
376
|
return;
|
|
364
377
|
}
|
|
@@ -368,7 +381,7 @@ export class NotebookModel implements Saveable, Disposable {
|
|
|
368
381
|
this.onDidChangeContentEmitter.fire([{ kind: NotebookCellsChangeType.ChangeCellLanguage, index: this.cells.indexOf(cell), language: languageId }]);
|
|
369
382
|
}
|
|
370
383
|
|
|
371
|
-
|
|
384
|
+
protected moveCellToIndex(fromIndex: number, length: number, toIndex: number, computeUndoRedo: boolean): boolean {
|
|
372
385
|
if (computeUndoRedo) {
|
|
373
386
|
this.undoRedoService.pushElement(this.uri,
|
|
374
387
|
async () => { this.moveCellToIndex(toIndex, length, fromIndex, false); },
|
|
@@ -383,7 +396,7 @@ export class NotebookModel implements Saveable, Disposable {
|
|
|
383
396
|
return true;
|
|
384
397
|
}
|
|
385
398
|
|
|
386
|
-
|
|
399
|
+
protected getCellIndexByHandle(handle: number): number {
|
|
387
400
|
return this.cells.findIndex(c => c.handle === handle);
|
|
388
401
|
}
|
|
389
402
|
}
|
|
@@ -19,8 +19,7 @@ import { MarkdownString } from '@theia/core/lib/common/markdown-rendering/markdo
|
|
|
19
19
|
import { BinaryBuffer } from '@theia/core/lib/common/buffer';
|
|
20
20
|
import { UriComponents } from '@theia/core/lib/common/uri';
|
|
21
21
|
|
|
22
|
-
export interface NotebookCommand {
|
|
23
|
-
id: string;
|
|
22
|
+
export interface NotebookCommand extends Command {
|
|
24
23
|
title?: string;
|
|
25
24
|
tooltip?: string;
|
|
26
25
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|