@@ -40,6 +40,8 @@ import { registerNotebookContribution } from 'vs/workbench/contrib/notebook/brow
40
40
import { CellEditorOptions } from 'vs/workbench/contrib/notebook/browser/view/cellParts/cellEditorOptions' ;
41
41
import { NOTEBOOK_CELL_EDITOR_FOCUSED , NOTEBOOK_IS_ACTIVE_EDITOR } from 'vs/workbench/contrib/notebook/common/notebookContextKeys' ;
42
42
import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
43
+ import { RedoCommand , UndoCommand } from 'vs/editor/browser/editorExtensions' ;
44
+ import { registerWorkbenchContribution2 , WorkbenchPhase } from 'vs/workbench/common/contributions' ;
43
45
44
46
const NOTEBOOK_ADD_FIND_MATCH_TO_SELECTION_ID = 'notebook.addFindMatchToSelection' ;
45
47
@@ -475,6 +477,30 @@ export class NotebookMultiCursorController extends Disposable implements INotebo
475
477
} ) ;
476
478
}
477
479
480
+ async undo ( ) {
481
+ const models : ITextModel [ ] = [ ] ;
482
+ for ( const match of this . trackedMatches ) {
483
+ const model = await match . cellViewModel . resolveTextModel ( ) ;
484
+ if ( model ) {
485
+ models . push ( model ) ;
486
+ }
487
+ }
488
+
489
+ await Promise . all ( models . map ( model => model . undo ( ) ) ) ;
490
+ }
491
+
492
+ async redo ( ) {
493
+ const models : ITextModel [ ] = [ ] ;
494
+ for ( const match of this . trackedMatches ) {
495
+ const model = await match . cellViewModel . resolveTextModel ( ) ;
496
+ if ( model ) {
497
+ models . push ( model ) ;
498
+ }
499
+ }
500
+
501
+ await Promise . all ( models . map ( model => model . redo ( ) ) ) ;
502
+ }
503
+
478
504
private constructCellEditorOptions ( cell : ICellViewModel ) : EditorConfiguration {
479
505
const cellEditorOptions = new CellEditorOptions ( this . notebookEditor . getBaseCellEditorOptions ( cell . language ) , this . notebookEditor . notebookOptions , this . configurationService ) ;
480
506
const options = cellEditorOptions . getUpdatedValue ( cell . internalMetadata , cell . uri ) ;
@@ -670,7 +696,59 @@ class NotebookDeleteLeftMultiSelectionAction extends NotebookAction {
670
696
}
671
697
}
672
698
699
+ class NotebookMultiCursorUndoRedoContribution extends Disposable {
700
+
701
+ static readonly ID = 'workbench.contrib.notebook.multiCursorUndoRedo' ;
702
+
703
+ constructor ( @IEditorService private readonly _editorService : IEditorService , @IConfigurationService private readonly configurationService : IConfigurationService ) {
704
+ super ( ) ;
705
+
706
+ if ( ! this . configurationService . getValue < boolean > ( 'notebook.multiSelect.enabled' ) ) {
707
+ return ;
708
+ }
709
+
710
+ const PRIORITY = 10005 ;
711
+ this . _register ( UndoCommand . addImplementation ( PRIORITY , 'notebook-multicursor-undo-redo' , ( ) => {
712
+ const editor = getNotebookEditorFromEditorPane ( this . _editorService . activeEditorPane ) ;
713
+ if ( ! editor ) {
714
+ return false ;
715
+ }
716
+
717
+ if ( ! editor . hasModel ( ) ) {
718
+ return false ;
719
+ }
720
+
721
+ const controller = editor . getContribution < NotebookMultiCursorController > ( NotebookMultiCursorController . id ) ;
722
+
723
+ return controller . undo ( ) ;
724
+ } , ContextKeyExpr . and (
725
+ ContextKeyExpr . equals ( 'config.notebook.multiSelect.enabled' , true ) ,
726
+ NOTEBOOK_IS_ACTIVE_EDITOR ,
727
+ NOTEBOOK_MULTI_SELECTION_CONTEXT . IsNotebookMultiSelect ,
728
+ ) ) ) ;
729
+
730
+ this . _register ( RedoCommand . addImplementation ( PRIORITY , 'notebook-multicursor-undo-redo' , ( ) => {
731
+ const editor = getNotebookEditorFromEditorPane ( this . _editorService . activeEditorPane ) ;
732
+ if ( ! editor ) {
733
+ return false ;
734
+ }
735
+
736
+ if ( ! editor . hasModel ( ) ) {
737
+ return false ;
738
+ }
739
+
740
+ const controller = editor . getContribution < NotebookMultiCursorController > ( NotebookMultiCursorController . id ) ;
741
+ return controller . redo ( ) ;
742
+ } , ContextKeyExpr . and (
743
+ ContextKeyExpr . equals ( 'config.notebook.multiSelect.enabled' , true ) ,
744
+ NOTEBOOK_IS_ACTIVE_EDITOR ,
745
+ NOTEBOOK_MULTI_SELECTION_CONTEXT . IsNotebookMultiSelect ,
746
+ ) ) ) ;
747
+ }
748
+ }
749
+
673
750
registerNotebookContribution ( NotebookMultiCursorController . id , NotebookMultiCursorController ) ;
674
751
registerAction2 ( NotebookAddMatchToMultiSelectionAction ) ;
675
752
registerAction2 ( NotebookExitMultiSelectionAction ) ;
676
753
registerAction2 ( NotebookDeleteLeftMultiSelectionAction ) ;
754
+ registerWorkbenchContribution2 ( NotebookMultiCursorUndoRedoContribution . ID , NotebookMultiCursorUndoRedoContribution , WorkbenchPhase . BlockRestore ) ;
0 commit comments