@@ -35,15 +35,15 @@ import { IModeService } from 'vs/editor/common/services/modeService';
3535import { ContextAwareMenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem' ;
3636import { IMenu , MenuItemAction } from 'vs/platform/actions/common/actions' ;
3737import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
38- import { IContextKey , IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
38+ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
3939import { IContextMenuService } from 'vs/platform/contextview/browser/contextView' ;
4040import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
4141import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection' ;
4242import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
4343import { INotificationService } from 'vs/platform/notification/common/notification' ;
4444import { BOTTOM_CELL_TOOLBAR_HEIGHT , EDITOR_BOTTOM_PADDING , EDITOR_TOOLBAR_HEIGHT , EDITOR_TOP_MARGIN , EDITOR_TOP_PADDING } from 'vs/workbench/contrib/notebook/browser/constants' ;
4545import { CancelCellAction , ChangeCellLanguageAction , ExecuteCellAction , INotebookCellActionContext , InsertCodeCellAction , InsertMarkdownCellAction } from 'vs/workbench/contrib/notebook/browser/contrib/coreActions' ;
46- import { BaseCellRenderTemplate , CellEditState , CellRunState , CodeCellRenderTemplate , ICellViewModel , INotebookCellList , INotebookEditor , MarkdownCellRenderTemplate , NOTEBOOK_CELL_EDITABLE , NOTEBOOK_CELL_HAS_OUTPUTS , NOTEBOOK_CELL_MARKDOWN_EDIT_MODE , NOTEBOOK_CELL_RUNNABLE , NOTEBOOK_CELL_RUN_STATE , NOTEBOOK_CELL_TYPE , NOTEBOOK_VIEW_TYPE } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
46+ import { BaseCellRenderTemplate , CellEditState , CodeCellRenderTemplate , ICellViewModel , INotebookCellList , INotebookEditor , MarkdownCellRenderTemplate , NOTEBOOK_CELL_EDITABLE , NOTEBOOK_CELL_HAS_OUTPUTS , NOTEBOOK_CELL_MARKDOWN_EDIT_MODE , NOTEBOOK_CELL_RUNNABLE , NOTEBOOK_CELL_RUN_STATE , NOTEBOOK_CELL_TYPE , NOTEBOOK_VIEW_TYPE } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
4747import { CellMenus } from 'vs/workbench/contrib/notebook/browser/view/renderers/cellMenus' ;
4848import { CodeCell } from 'vs/workbench/contrib/notebook/browser/view/renderers/codeCell' ;
4949import { StatefullMarkdownCell } from 'vs/workbench/contrib/notebook/browser/view/renderers/markdownCell' ;
@@ -978,9 +978,14 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
978978 return templateData ;
979979 }
980980
981- private updateForRunState ( element : CodeCellViewModel , templateData : CodeCellRenderTemplate , runStateKey : IContextKey < string > ) : void {
982- runStateKey . set ( CellRunState [ element . runState ] ) ;
983- if ( element . runState === CellRunState . Running ) {
981+ private updateForRunState ( runState : NotebookCellRunState | undefined , templateData : CodeCellRenderTemplate ) : void {
982+ if ( typeof runState === 'undefined' ) {
983+ runState = NotebookCellRunState . Idle ;
984+ }
985+
986+ const runStateKey = NOTEBOOK_CELL_RUN_STATE . bindTo ( templateData . contextKeyService ) ;
987+ runStateKey . set ( NotebookCellRunState [ runState ] ) ;
988+ if ( runState === NotebookCellRunState . Running ) {
984989 templateData . progressBar . infinite ( ) . show ( 500 ) ;
985990
986991 templateData . runToolbar . setActions ( [
@@ -995,7 +1000,10 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
9951000 }
9961001 }
9971002
998- private updateForMetadata ( element : CodeCellViewModel , templateData : CodeCellRenderTemplate , cellEditableKey : IContextKey < boolean > , cellRunnableKey : IContextKey < boolean > ) : void {
1003+ private updateForMetadata ( element : CodeCellViewModel , templateData : CodeCellRenderTemplate ) : void {
1004+ const cellEditableKey = NOTEBOOK_CELL_EDITABLE . bindTo ( templateData . contextKeyService ) ;
1005+ const cellRunnableKey = NOTEBOOK_CELL_RUNNABLE . bindTo ( templateData . contextKeyService ) ;
1006+
9991007 const metadata = element . getEvaluatedMetadata ( this . notebookEditor . viewModel ! . notebookDocument . metadata ) ;
10001008 DOM . toggleClass ( templateData . cellContainer , 'runnable' , ! ! metadata . runnable ) ;
10011009 this . renderExecutionOrder ( element , templateData ) ;
@@ -1028,6 +1036,8 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
10281036 if ( typeof metadata . breakpointMargin === 'boolean' ) {
10291037 this . editorOptions . setGlyphMargin ( metadata . breakpointMargin ) ;
10301038 }
1039+
1040+ this . updateForRunState ( metadata . runState , templateData ) ;
10311041 }
10321042
10331043 private renderExecutionOrder ( element : CodeCellViewModel , templateData : CodeCellRenderTemplate ) : void {
@@ -1066,42 +1076,26 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
10661076 templateData . focusIndicator . style . height = `${ element . layoutInfo . indicatorHeight } px` ;
10671077 } ) ) ;
10681078
1069- const contextKeyService = this . contextKeyServiceProvider ( templateData . container ) ;
1070-
1071- const runStateKey = NOTEBOOK_CELL_RUN_STATE . bindTo ( contextKeyService ) ;
1072- runStateKey . set ( CellRunState [ element . runState ] ) ;
1073- this . updateForRunState ( element , templateData , runStateKey ) ;
1074- elementDisposables . add ( element . onDidChangeState ( ( e ) => {
1075- if ( e . runStateChanged ) {
1076- this . updateForRunState ( element , templateData , runStateKey ) ;
1077- }
1078- } ) ) ;
1079-
1080- const cellHasOutputsContext = NOTEBOOK_CELL_HAS_OUTPUTS . bindTo ( contextKeyService ) ;
1079+ const cellHasOutputsContext = NOTEBOOK_CELL_HAS_OUTPUTS . bindTo ( templateData . contextKeyService ) ;
10811080 cellHasOutputsContext . set ( element . outputs . length > 0 ) ;
10821081 elementDisposables . add ( element . onDidChangeOutputs ( ( ) => {
10831082 cellHasOutputsContext . set ( element . outputs . length > 0 ) ;
10841083 } ) ) ;
10851084
1086- NOTEBOOK_CELL_TYPE . bindTo ( contextKeyService ) . set ( 'code' ) ;
1087- NOTEBOOK_VIEW_TYPE . bindTo ( contextKeyService ) . set ( element . viewType ) ;
1088- const metadata = element . getEvaluatedMetadata ( this . notebookEditor . viewModel ! . notebookDocument . metadata ) ;
1089- const cellEditableKey = NOTEBOOK_CELL_EDITABLE . bindTo ( contextKeyService ) ;
1090- cellEditableKey . set ( ! ! metadata . editable ) ;
1091- const cellRunnableKey = NOTEBOOK_CELL_RUNNABLE . bindTo ( contextKeyService ) ;
1092- cellRunnableKey . set ( ! ! metadata . runnable ) ;
1093- this . updateForMetadata ( element , templateData , cellEditableKey , cellRunnableKey ) ;
1085+ NOTEBOOK_CELL_TYPE . bindTo ( templateData . contextKeyService ) . set ( 'code' ) ;
1086+ NOTEBOOK_VIEW_TYPE . bindTo ( templateData . contextKeyService ) . set ( element . viewType ) ;
1087+ this . updateForMetadata ( element , templateData ) ;
10941088 elementDisposables . add ( element . onDidChangeState ( ( e ) => {
10951089 if ( e . metadataChanged ) {
1096- this . updateForMetadata ( element , templateData , cellEditableKey , cellRunnableKey ) ;
1090+ this . updateForMetadata ( element , templateData ) ;
10971091 }
10981092
10991093 if ( e . outputIsHoveredChanged ) {
11001094 this . updateForHover ( element , templateData ) ;
11011095 }
11021096 } ) ) ;
11031097
1104- this . setupCellToolbarActions ( contextKeyService , templateData , elementDisposables ) ;
1098+ this . setupCellToolbarActions ( templateData . contextKeyService , templateData , elementDisposables ) ;
11051099
11061100 const toolbarContext = < INotebookCellActionContext > {
11071101 cell : element ,
0 commit comments