Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/notebook/src/browser/notebook-editor-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { Deferred } from '@theia/core/lib/common/promise-util';
import { MarkdownString } from '@theia/core/lib/common/markdown-rendering';
import { NotebookContextManager } from './service/notebook-context-manager';
import { NotebookViewportService } from './view/notebook-viewport-service';
import { NotebookCellCommands } from './contributions/notebook-cell-actions-contribution';
const PerfectScrollbar = require('react-perfect-scrollbar');

export const NotebookEditorWidgetContainerFactory = Symbol('NotebookEditorWidgetContainerFactory');
Expand All @@ -43,6 +44,7 @@ export function createNotebookEditorWidgetContainer(parent: interfaces.Container

child.bind(NotebookContextManager).toSelf().inSingletonScope();
child.bind(NotebookMainToolbarRenderer).toSelf().inSingletonScope();
child.bind(NotebookCellToolbarFactory).toSelf().inSingletonScope();
child.bind(NotebookCodeCellRenderer).toSelf().inSingletonScope();
child.bind(NotebookMarkdownCellRenderer).toSelf().inSingletonScope();
child.bind(NotebookViewportService).toSelf().inSingletonScope();
Expand Down Expand Up @@ -152,6 +154,12 @@ export class NotebookEditorWidget extends ReactWidget implements Navigatable, Sa
this.renderers.set(CellKind.Markup, this.markdownCellRenderer);
this.renderers.set(CellKind.Code, this.codeCellRenderer);
this._ready.resolve(this.waitForData());
this.ready.then(model => {
if (model.cells.length === 1 && model.cells[0].source === '') {
this.commandRegistry.executeCommand(NotebookCellCommands.EDIT_COMMAND.id, model, model.cells[0]);
model.setSelectedCell(model.cells[0]);
}
});
}

protected async waitForData(): Promise<NotebookModel> {
Expand Down
2 changes: 0 additions & 2 deletions packages/notebook/src/browser/notebook-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { NotebookEditorWidgetFactory } from './notebook-editor-widget-factory';
import { NotebookCellResourceResolver } from './notebook-cell-resource-resolver';
import { NotebookModelResolverService } from './service/notebook-model-resolver-service';
import { NotebookCellActionContribution } from './contributions/notebook-cell-actions-contribution';
import { NotebookCellToolbarFactory } from './view/notebook-cell-toolbar-factory';
import { createNotebookModelContainer, NotebookModel, NotebookModelFactory, NotebookModelProps } from './view-model/notebook-model';
import { createNotebookCellModelContainer, NotebookCellModel, NotebookCellModelFactory, NotebookCellModelProps } from './view-model/notebook-cell-model';
import { createNotebookEditorWidgetContainer, NotebookEditorWidgetContainerFactory, NotebookEditorProps, NotebookEditorWidget } from './notebook-editor-widget';
Expand All @@ -53,7 +52,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(NotebookRendererRegistry).toSelf().inSingletonScope();

bind(WidgetFactory).to(NotebookEditorWidgetFactory).inSingletonScope();
bind(NotebookCellToolbarFactory).toSelf().inSingletonScope();

bind(NotebookService).toSelf().inSingletonScope();
bind(NotebookEditorWidgetService).toSelf().inSingletonScope();
Expand Down
6 changes: 4 additions & 2 deletions packages/notebook/src/browser/view-model/notebook-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,10 @@ export class NotebookModel implements Saveable, Disposable {
}

setSelectedCell(cell: NotebookCellModel): void {
this.selectedCell = cell;
this.onDidChangeSelectedCellEmitter.fire(cell);
if (this.selectedCell !== cell) {
this.selectedCell = cell;
this.onDidChangeSelectedCellEmitter.fire(cell);
}
}

private addCellOutputListeners(cells: NotebookCellModel[]): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class NotebookCellListView extends React.Component<CellListProps, Noteboo

constructor(props: CellListProps) {
super(props);
this.state = { selectedCell: undefined, dragOverIndicator: undefined };
this.state = { selectedCell: props.notebookModel.selectedCell, dragOverIndicator: undefined };
this.toDispose.push(props.notebookModel.onDidAddOrRemoveCell(e => {
if (e.newCellIds && e.newCellIds.length > 0) {
this.setState({ ...this.state, selectedCell: this.props.notebookModel.cells.find(model => model.handle === e.newCellIds![e.newCellIds!.length - 1]) });
Expand Down
5 changes: 3 additions & 2 deletions packages/notebook/src/browser/view/notebook-cell-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ abstract class NotebookCellActionBar extends React.Component<NotebookCellToolbar
constructor(props: NotebookCellToolbarProps) {
super(props);
this.toDispose.push(props.onContextKeysChanged(e => {
if (this.props.getMenuItems().some(item => item.contextKeys ? e.affects(item.contextKeys) : false)) {
this.setState({ inlineItems: this.props.getMenuItems() });
const menuItems = this.props.getMenuItems();
if (menuItems.some(item => item.contextKeys ? e.affects(item.contextKeys) : false)) {
this.setState({ inlineItems: menuItems });
}
}));
this.state = { inlineItems: this.props.getMenuItems() };
Expand Down