5
5
6
6
import { KeyChord , KeyCode , KeyMod } from 'vs/base/common/keyCodes' ;
7
7
import { Mimes } from 'vs/base/common/mime' ;
8
+ import { IBulkEditService , ResourceTextEdit } from 'vs/editor/browser/services/bulkEditService' ;
8
9
import { localize } from 'vs/nls' ;
9
10
import { MenuId , registerAction2 } from 'vs/platform/actions/common/actions' ;
10
11
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey' ;
11
12
import { InputFocusedContext , InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys' ;
13
+ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
12
14
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry' ;
15
+ import { ResourceNotebookCellEdit } from 'vs/workbench/contrib/bulkEdit/browser/bulkCellEdits' ;
16
+ import { changeCellToKind , computeCellLinesContents , copyCellRange , joinCellsWithSurrounds , moveCellRange } from 'vs/workbench/contrib/notebook/browser/controller/cellOperations' ;
13
17
import { cellExecutionArgs , CellOverflowToolbarGroups , CellToolbarOrder , CELL_TITLE_CELL_GROUP_ID , INotebookCellActionContext , INotebookCellToolbarActionContext , INotebookCommandContext , NotebookCellAction , NotebookMultiCellAction , parseMultiCellExecutionArgs } from 'vs/workbench/contrib/notebook/browser/controller/coreActions' ;
14
- import { CellFocusMode , EXPAND_CELL_INPUT_COMMAND_ID , EXPAND_CELL_OUTPUT_COMMAND_ID , NOTEBOOK_CELL_EDITABLE , NOTEBOOK_CELL_HAS_OUTPUTS , NOTEBOOK_CELL_INPUT_COLLAPSED , NOTEBOOK_CELL_LIST_FOCUSED , NOTEBOOK_CELL_OUTPUT_COLLAPSED , NOTEBOOK_CELL_TYPE , NOTEBOOK_EDITOR_EDITABLE , NOTEBOOK_EDITOR_FOCUSED , NOTEBOOK_IS_ACTIVE_EDITOR } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
18
+ import { CellFocusMode , EXPAND_CELL_INPUT_COMMAND_ID , EXPAND_CELL_OUTPUT_COMMAND_ID , ICellViewModel , NOTEBOOK_CELL_EDITABLE , NOTEBOOK_CELL_HAS_OUTPUTS , NOTEBOOK_CELL_INPUT_COLLAPSED , NOTEBOOK_CELL_LIST_FOCUSED , NOTEBOOK_CELL_OUTPUT_COLLAPSED , NOTEBOOK_CELL_TYPE , NOTEBOOK_EDITOR_EDITABLE , NOTEBOOK_EDITOR_FOCUSED , NOTEBOOK_IS_ACTIVE_EDITOR } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
15
19
import * as icons from 'vs/workbench/contrib/notebook/browser/notebookIcons' ;
16
- import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
17
- import { CellEditType , CellKind , ICellEditOperation , NotebookCellMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
18
- import { IBulkEditService , ResourceTextEdit } from 'vs/editor/browser/services/bulkEditService' ;
19
- import { changeCellToKind , computeCellLinesContents , copyCellRange , joinCellsWithSurrounds , moveCellRange } from 'vs/workbench/contrib/notebook/browser/controller/cellOperations' ;
20
- import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel' ;
21
- import { ResourceNotebookCellEdit } from 'vs/workbench/contrib/bulkEdit/browser/bulkCellEdits' ;
20
+ import { CellEditType , CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
22
21
23
22
//#region Move/Copy cells
24
23
const MOVE_CELL_UP_COMMAND_ID = 'notebook.cell.moveUp' ;
@@ -322,30 +321,7 @@ const COLLAPSE_CELL_INPUT_COMMAND_ID = 'notebook.cell.collapseCellInput';
322
321
const COLLAPSE_CELL_OUTPUT_COMMAND_ID = 'notebook.cell.collapseCellOutput' ;
323
322
const TOGGLE_CELL_OUTPUTS_COMMAND_ID = 'notebook.cell.toggleOutputs' ;
324
323
325
- abstract class ChangeNotebookCellMetadataAction extends NotebookCellAction {
326
- async runWithContext ( accessor : ServicesAccessor , context : INotebookCellActionContext ) : Promise < void > {
327
- const textModel = context . notebookEditor . textModel ;
328
- if ( ! textModel ) {
329
- return ;
330
- }
331
-
332
- const metadataDelta = this . getMetadataDelta ( ) ;
333
- const edits : ICellEditOperation [ ] = [ ] ;
334
- const targetCells = ( context . cell ? [ context . cell ] : context . selectedCells ) ?? [ ] ;
335
- for ( const cell of targetCells ) {
336
- const index = textModel . cells . indexOf ( cell . model ) ;
337
- if ( index >= 0 ) {
338
- edits . push ( { editType : CellEditType . Metadata , index, metadata : { ...context . cell . metadata , ...metadataDelta } } ) ;
339
- }
340
- }
341
-
342
- textModel . applyEdits ( edits , true , undefined , ( ) => undefined , undefined ) ;
343
- }
344
-
345
- abstract getMetadataDelta ( ) : NotebookCellMetadata ;
346
- }
347
-
348
- registerAction2 ( class CollapseCellInputAction extends ChangeNotebookCellMetadataAction {
324
+ registerAction2 ( class CollapseCellInputAction extends NotebookMultiCellAction {
349
325
constructor ( ) {
350
326
super ( {
351
327
id : COLLAPSE_CELL_INPUT_COMMAND_ID ,
@@ -364,12 +340,16 @@ registerAction2(class CollapseCellInputAction extends ChangeNotebookCellMetadata
364
340
} ) ;
365
341
}
366
342
367
- getMetadataDelta ( ) : NotebookCellMetadata {
368
- return { inputCollapsed : true } ;
343
+ async runWithContext ( accessor : ServicesAccessor , context : INotebookCommandContext | INotebookCellToolbarActionContext ) : Promise < void > {
344
+ if ( context . ui ) {
345
+ context . cell . isInputCollapsed = true ;
346
+ } else {
347
+ context . selectedCells . forEach ( cell => cell . isInputCollapsed = true ) ;
348
+ }
369
349
}
370
350
} ) ;
371
351
372
- registerAction2 ( class ExpandCellInputAction extends ChangeNotebookCellMetadataAction {
352
+ registerAction2 ( class ExpandCellInputAction extends NotebookMultiCellAction {
373
353
constructor ( ) {
374
354
super ( {
375
355
id : EXPAND_CELL_INPUT_COMMAND_ID ,
@@ -388,12 +368,16 @@ registerAction2(class ExpandCellInputAction extends ChangeNotebookCellMetadataAc
388
368
} ) ;
389
369
}
390
370
391
- getMetadataDelta ( ) : NotebookCellMetadata {
392
- return { inputCollapsed : false } ;
371
+ async runWithContext ( accessor : ServicesAccessor , context : INotebookCommandContext | INotebookCellToolbarActionContext ) : Promise < void > {
372
+ if ( context . ui ) {
373
+ context . cell . isInputCollapsed = false ;
374
+ } else {
375
+ context . selectedCells . forEach ( cell => cell . isInputCollapsed = false ) ;
376
+ }
393
377
}
394
378
} ) ;
395
379
396
- registerAction2 ( class CollapseCellOutputAction extends ChangeNotebookCellMetadataAction {
380
+ registerAction2 ( class CollapseCellOutputAction extends NotebookMultiCellAction {
397
381
constructor ( ) {
398
382
super ( {
399
383
id : COLLAPSE_CELL_OUTPUT_COMMAND_ID ,
@@ -412,12 +396,16 @@ registerAction2(class CollapseCellOutputAction extends ChangeNotebookCellMetadat
412
396
} ) ;
413
397
}
414
398
415
- getMetadataDelta ( ) : NotebookCellMetadata {
416
- return { outputCollapsed : true } ;
399
+ async runWithContext ( accessor : ServicesAccessor , context : INotebookCommandContext | INotebookCellToolbarActionContext ) : Promise < void > {
400
+ if ( context . ui ) {
401
+ context . cell . isOutputCollapsed = true ;
402
+ } else {
403
+ context . selectedCells . forEach ( cell => cell . isOutputCollapsed = true ) ;
404
+ }
417
405
}
418
406
} ) ;
419
407
420
- registerAction2 ( class ExpandCellOuputAction extends ChangeNotebookCellMetadataAction {
408
+ registerAction2 ( class ExpandCellOuputAction extends NotebookMultiCellAction {
421
409
constructor ( ) {
422
410
super ( {
423
411
id : EXPAND_CELL_OUTPUT_COMMAND_ID ,
@@ -436,8 +424,12 @@ registerAction2(class ExpandCellOuputAction extends ChangeNotebookCellMetadataAc
436
424
} ) ;
437
425
}
438
426
439
- getMetadataDelta ( ) : NotebookCellMetadata {
440
- return { outputCollapsed : false } ;
427
+ async runWithContext ( accessor : ServicesAccessor , context : INotebookCommandContext | INotebookCellToolbarActionContext ) : Promise < void > {
428
+ if ( context . ui ) {
429
+ context . cell . isOutputCollapsed = false ;
430
+ } else {
431
+ context . selectedCells . forEach ( cell => cell . isOutputCollapsed = false ) ;
432
+ }
441
433
}
442
434
} ) ;
443
435
@@ -459,25 +451,16 @@ registerAction2(class extends NotebookMultiCellAction {
459
451
}
460
452
461
453
async runWithContext ( accessor : ServicesAccessor , context : INotebookCommandContext | INotebookCellToolbarActionContext ) : Promise < void > {
462
- const textModel = context . notebookEditor . textModel ;
463
- let cells : NotebookCellTextModel [ ] = [ ] ;
454
+ let cells : readonly ICellViewModel [ ] = [ ] ;
464
455
if ( context . ui ) {
465
- cells = [ context . cell . model ] ;
456
+ cells = [ context . cell ] ;
466
457
} else if ( context . selectedCells ) {
467
- cells = context . selectedCells . map ( cell => cell . model ) ;
468
- } else {
469
- cells = [ ...textModel . cells ] ;
458
+ cells = context . selectedCells ;
470
459
}
471
460
472
- const edits : ICellEditOperation [ ] = [ ] ;
473
- for ( const cell of cells ) {
474
- const index = textModel . cells . indexOf ( cell ) ;
475
- if ( index >= 0 ) {
476
- edits . push ( { editType : CellEditType . Metadata , index, metadata : { ...cell . metadata , outputCollapsed : ! cell . metadata . outputCollapsed } } ) ;
477
- }
461
+ for ( let cell of cells ) {
462
+ cell . isOutputCollapsed = ! cell . isOutputCollapsed ;
478
463
}
479
-
480
- textModel . applyEdits ( edits , true , undefined , ( ) => undefined , undefined ) ;
481
464
}
482
465
} ) ;
483
466
0 commit comments