Skip to content

Commit

Permalink
always show the toolabr when the document is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Aug 13, 2020
1 parent 000dad4 commit 4a0543f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ registerAction2(class extends InsertCellCommand {
}
});

registerAction2(class extends NotebookCellAction {
registerAction2(class extends NotebookAction {
constructor() {
super(
{
Expand All @@ -589,15 +589,22 @@ registerAction2(class extends NotebookCellAction {
});
}

async runWithContext(accessor: ServicesAccessor, context: INotebookCellActionContext): Promise<void> {
async run(accessor: ServicesAccessor): Promise<void> {
const context = this.getActiveEditorContext(accessor);
if (context) {
this.runWithContext(accessor, context);
}
}

async runWithContext(accessor: ServicesAccessor, context: INotebookActionContext): Promise<void> {
const newCell = context.notebookEditor.insertNotebookCell(undefined, CellKind.Code, 'above', undefined, true);
if (newCell) {
context.notebookEditor.focusNotebookCell(newCell, 'editor');
}
}
});

registerAction2(class extends NotebookCellAction {
registerAction2(class extends NotebookAction {
constructor() {
super(
{
Expand All @@ -607,7 +614,14 @@ registerAction2(class extends NotebookCellAction {
});
}

async runWithContext(accessor: ServicesAccessor, context: INotebookCellActionContext): Promise<void> {
async run(accessor: ServicesAccessor): Promise<void> {
const context = this.getActiveEditorContext(accessor);
if (context) {
this.runWithContext(accessor, context);
}
}

async runWithContext(accessor: ServicesAccessor, context: INotebookActionContext): Promise<void> {
const newCell = context.notebookEditor.insertNotebookCell(undefined, CellKind.Markdown, 'above', undefined, true);
if (newCell) {
context.notebookEditor.focusNotebookCell(newCell, 'editor');
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/contrib/notebook/browser/media/notebook.css
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@
opacity: 0.5 !important;
}


.monaco-workbench .notebookOverlay .cell-list-top-cell-toolbar-container.emptyNotebook {
opacity: 1 !important;
}

.monaco-workbench .notebookOverlay .cell-list-top-cell-toolbar-container,
.monaco-workbench .notebookOverlay > .cell-list-container > .monaco-list > .monaco-scrollable-element > .monaco-list-rows > .monaco-list-row .cell-bottom-toolbar-container {
position: absolute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,7 @@ export class RunStateRenderer {

export class ListTopCellToolbar extends Disposable {
private topCellToolbar: HTMLElement;
private _modelDisposables = new DisposableStore();
constructor(
protected readonly notebookEditor: INotebookEditor,

Expand Down Expand Up @@ -1330,6 +1331,26 @@ export class ListTopCellToolbar extends Disposable {
this._register(this.notebookEditor.onDidScroll((e) => {
this.topCellToolbar.style.top = `-${e.scrollTop}px`;
}));

this._register(this.notebookEditor.onDidChangeModel(() => {
this._modelDisposables.clear();

if (this.notebookEditor.viewModel) {
this._modelDisposables.add(this.notebookEditor.viewModel.onDidChangeViewCells(() => {
this.updateClass();
}));
}
}));

this.updateClass();
}

private updateClass() {
if (this.notebookEditor.viewModel?.length === 0) {
DOM.addClass(this.topCellToolbar, 'emptyNotebook');
} else {
DOM.removeClass(this.topCellToolbar, 'emptyNotebook');
}
}

private getCellToolbarActions(menu: IMenu, alwaysFillSecondaryActions: boolean): { primary: IAction[], secondary: IAction[] } {
Expand Down

0 comments on commit 4a0543f

Please sign in to comment.