@@ -9,6 +9,8 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
9
9
import { localize , localize2 } from 'vs/nls' ;
10
10
import { CONTEXT_ACCESSIBILITY_MODE_ENABLED } from 'vs/platform/accessibility/common/accessibility' ;
11
11
import { MenuId , MenuRegistry , registerAction2 } from 'vs/platform/actions/common/actions' ;
12
+ import { ICommandService } from 'vs/platform/commands/common/commands' ;
13
+ import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
12
14
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey' ;
13
15
import { InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys' ;
14
16
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
@@ -17,6 +19,7 @@ import { CTX_INLINE_CHAT_FOCUSED, CTX_INLINE_CHAT_HAS_PROVIDER, CTX_INLINE_CHAT_
17
19
import { CTX_NOTEBOOK_CELL_CHAT_FOCUSED , CTX_NOTEBOOK_CHAT_HAS_ACTIVE_REQUEST , CTX_NOTEBOOK_CHAT_OUTER_FOCUS_POSITION , CTX_NOTEBOOK_CHAT_USER_DID_EDIT , MENU_CELL_CHAT_INPUT , MENU_CELL_CHAT_WIDGET , MENU_CELL_CHAT_WIDGET_FEEDBACK , MENU_CELL_CHAT_WIDGET_STATUS } from 'vs/workbench/contrib/notebook/browser/controller/chat/notebookChatContext' ;
18
20
import { NotebookChatController } from 'vs/workbench/contrib/notebook/browser/controller/chat/notebookChatController' ;
19
21
import { CELL_TITLE_CELL_GROUP_ID , INotebookActionContext , INotebookCellActionContext , NotebookAction , NotebookCellAction , getEditorFromArgsOrActivePane } from 'vs/workbench/contrib/notebook/browser/controller/coreActions' ;
22
+ import { insertNewCell } from 'vs/workbench/contrib/notebook/browser/controller/insertCellActions' ;
20
23
import { CellEditState } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
21
24
import { CellKind , NOTEBOOK_EDITOR_CURSOR_BOUNDARY , NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
22
25
import { NOTEBOOK_CELL_EDITOR_FOCUSED , NOTEBOOK_CELL_GENERATED_BY_CHAT , NOTEBOOK_EDITOR_EDITABLE , NOTEBOOK_EDITOR_FOCUSED } from 'vs/workbench/contrib/notebook/common/notebookContextKeys' ;
@@ -364,6 +367,26 @@ interface IInsertCellWithChatArgs extends INotebookActionContext {
364
367
autoSend ?: boolean ;
365
368
}
366
369
370
+ async function startChat ( accessor : ServicesAccessor , context : INotebookActionContext , index : number , input ?: string , autoSend ?: boolean ) {
371
+ const configurationService = accessor . get ( IConfigurationService ) ;
372
+ const commandService = accessor . get ( ICommandService ) ;
373
+
374
+ if ( configurationService . getValue < boolean > ( NotebookSetting . cellChat ) ) {
375
+ context . notebookEditor . focusContainer ( ) ;
376
+ NotebookChatController . get ( context . notebookEditor ) ?. run ( index , input , autoSend ) ;
377
+ } else {
378
+ const newCell = await insertNewCell ( accessor , context , CellKind . Code , 'below' , true ) ;
379
+ if ( newCell ) {
380
+ await context . notebookEditor . revealFirstLineIfOutsideViewport ( newCell ) ;
381
+ const codeEditor = context . notebookEditor . codeEditors . find ( ce => ce [ 0 ] === newCell ) ?. [ 1 ] ;
382
+ if ( codeEditor ) {
383
+ codeEditor . focus ( ) ;
384
+ commandService . executeCommand ( 'inlineChat.start' ) ;
385
+ }
386
+ }
387
+ }
388
+ }
389
+
367
390
registerAction2 ( class extends NotebookAction {
368
391
constructor ( ) {
369
392
super (
@@ -404,7 +427,6 @@ registerAction2(class extends NotebookAction {
404
427
NOTEBOOK_EDITOR_EDITABLE . isEqualTo ( true ) ,
405
428
ContextKeyExpr . not ( InputFocusedContextKey ) ,
406
429
CTX_INLINE_CHAT_HAS_PROVIDER ,
407
- ContextKeyExpr . equals ( `config.${ NotebookSetting . cellChat } ` , true )
408
430
) ,
409
431
weight : KeybindingWeight . WorkbenchContrib ,
410
432
primary : KeyMod . CtrlCmd | KeyCode . KeyI ,
@@ -418,7 +440,6 @@ registerAction2(class extends NotebookAction {
418
440
when : ContextKeyExpr . and (
419
441
NOTEBOOK_EDITOR_EDITABLE . isEqualTo ( true ) ,
420
442
CTX_INLINE_CHAT_HAS_PROVIDER ,
421
- ContextKeyExpr . equals ( `config.${ NotebookSetting . cellChat } ` , true )
422
443
)
423
444
}
424
445
]
@@ -467,8 +488,7 @@ registerAction2(class extends NotebookAction {
467
488
468
489
async runWithContext ( accessor : ServicesAccessor , context : IInsertCellWithChatArgs ) {
469
490
const index = Math . max ( 0 , context . cell ? context . notebookEditor . getCellIndex ( context . cell ) + 1 : 0 ) ;
470
- context . notebookEditor . focusContainer ( ) ;
471
- NotebookChatController . get ( context . notebookEditor ) ?. run ( index , context . input , context . autoSend ) ;
491
+ await startChat ( accessor , context , index , context . input , context . autoSend ) ;
472
492
}
473
493
} ) ;
474
494
@@ -490,17 +510,15 @@ registerAction2(class extends NotebookAction {
490
510
order : - 1 ,
491
511
when : ContextKeyExpr . and (
492
512
NOTEBOOK_EDITOR_EDITABLE . isEqualTo ( true ) ,
493
- CTX_INLINE_CHAT_HAS_PROVIDER ,
494
- ContextKeyExpr . equals ( `config.${ NotebookSetting . cellChat } ` , true )
513
+ CTX_INLINE_CHAT_HAS_PROVIDER
495
514
)
496
515
} ,
497
516
]
498
517
} ) ;
499
518
}
500
519
501
520
async runWithContext ( accessor : ServicesAccessor , context : INotebookActionContext ) {
502
- context . notebookEditor . focusContainer ( ) ;
503
- NotebookChatController . get ( context . notebookEditor ) ?. run ( 0 , '' , false ) ;
521
+ await startChat ( accessor , context , 0 , '' , false ) ;
504
522
}
505
523
} ) ;
506
524
@@ -518,7 +536,6 @@ MenuRegistry.appendMenuItem(MenuId.NotebookToolbar, {
518
536
ContextKeyExpr . notEquals ( 'config.notebook.insertToolbarLocation' , 'betweenCells' ) ,
519
537
ContextKeyExpr . notEquals ( 'config.notebook.insertToolbarLocation' , 'hidden' ) ,
520
538
CTX_INLINE_CHAT_HAS_PROVIDER ,
521
- ContextKeyExpr . equals ( `config.${ NotebookSetting . cellChat } ` , true )
522
539
)
523
540
} ) ;
524
541
0 commit comments