Skip to content

Commit

Permalink
Add "Go to running cell" button
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Dec 30, 2021
1 parent c12b2dc commit 1716994
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import { localize } from 'vs/nls';
import { MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
import { EditorsOrder } from 'vs/workbench/common/editor';
import { insertCell } from 'vs/workbench/contrib/notebook/browser/controller/cellOperations';
import { cellExecutionArgs, CellToolbarOrder, CELL_TITLE_CELL_GROUP_ID, executeNotebookCondition, getContextFromActiveEditor, getContextFromUri, INotebookActionContext, INotebookCellActionContext, INotebookCellToolbarActionContext, INotebookCommandContext, NotebookAction, NotebookCellAction, NotebookMultiCellAction, NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT, parseMultiCellExecutionArgs } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';
import { CellEditState, CellFocusMode, EXECUTE_CELL_COMMAND_ID, NOTEBOOK_CELL_EXECUTING, NOTEBOOK_CELL_EXECUTION_STATE, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_TYPE, NOTEBOOK_HAS_RUNNING_CELL, NOTEBOOK_INTERRUPTIBLE_KERNEL, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_KERNEL_COUNT, NOTEBOOK_MISSING_KERNEL_EXTENSION } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import * as icons from 'vs/workbench/contrib/notebook/browser/notebookIcons';
import { CellKind, NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput';
import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';

Expand All @@ -30,6 +32,7 @@ const EXECUTE_CELL_INSERT_BELOW = 'notebook.cell.executeAndInsertBelow';
const EXECUTE_CELL_AND_BELOW = 'notebook.cell.executeCellAndBelow';
const EXECUTE_CELLS_ABOVE = 'notebook.cell.executeCellsAbove';
const RENDER_ALL_MARKDOWN_CELLS = 'notebook.renderAllMarkdownCells';
const REVEAL_RUNNING_CELL = 'notebook.revealRunningCell';

// If this changes, update getCodeCellExecutionContextKeyService to match
export const executeCondition = ContextKeyExpr.and(
Expand Down Expand Up @@ -520,3 +523,49 @@ registerAction2(class CancelNotebook extends NotebookAction {
return context.notebookEditor.cancelNotebookCells();
}
});


registerAction2(class RevealRunningCellAction extends NotebookAction {
constructor() {
super({
id: REVEAL_RUNNING_CELL,
title: localize('revealRunningCell', "Go To Running Cell"),
precondition: NOTEBOOK_HAS_RUNNING_CELL,
menu: [
{
id: MenuId.EditorTitle,
when: ContextKeyExpr.and(
NOTEBOOK_IS_ACTIVE_EDITOR,
NOTEBOOK_HAS_RUNNING_CELL,
ContextKeyExpr.notEquals('config.notebook.globalToolbar', true)
),
group: 'navigation',
order: 0
},
{
id: MenuId.NotebookToolbar,
when: ContextKeyExpr.and(
NOTEBOOK_IS_ACTIVE_EDITOR,
NOTEBOOK_HAS_RUNNING_CELL,
ContextKeyExpr.equals('config.notebook.globalToolbar', true)
),
group: 'navigation/execute',
order: 0
}
],
icon: ThemeIcon.modify(icons.executingStateIcon, 'spin')
});
}

async runWithContext(accessor: ServicesAccessor, context: INotebookActionContext): Promise<void> {
const notebookExecutionStateService = accessor.get(INotebookExecutionStateService);
const notebook = context.notebookEditor.textModel.uri;
const executingCells = notebookExecutionStateService.getCellExecutionStatesForNotebook(notebook);
if (executingCells[0]) {
const cell = context.notebookEditor.getCellByHandle(executingCells[0].cellHandle);
if (cell) {
context.notebookEditor.revealInCenter(cell);
}
}
}
});

0 comments on commit 1716994

Please sign in to comment.