@@ -8,9 +8,9 @@ import { Emitter, Event } from 'vs/base/common/event';
8
8
import { KeyCode , KeyMod } from 'vs/base/common/keyCodes' ;
9
9
import { Disposable , DisposableStore } from 'vs/base/common/lifecycle' ;
10
10
import { ResourceMap } from 'vs/base/common/map' ;
11
+ import { URI } from 'vs/base/common/uri' ;
11
12
import { EditorConfiguration } from 'vs/editor/browser/config/editorConfiguration' ;
12
13
import { ICodeEditor } from 'vs/editor/browser/editorBrowser' ;
13
- import { RedoCommand , UndoCommand } from 'vs/editor/browser/editorExtensions' ;
14
14
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditor/codeEditorWidget' ;
15
15
import { IEditorConfiguration } from 'vs/editor/common/config/editorConfiguration' ;
16
16
import { Position } from 'vs/editor/common/core/position' ;
@@ -34,7 +34,6 @@ import { ContextKeyExpr, IContextKeyService, RawContextKey } from 'vs/platform/c
34
34
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
35
35
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry' ;
36
36
import { IPastFutureElements , IUndoRedoElement , IUndoRedoService , UndoRedoElementType } from 'vs/platform/undoRedo/common/undoRedo' ;
37
- import { registerWorkbenchContribution2 , WorkbenchPhase } from 'vs/workbench/common/contributions' ;
38
37
import { INotebookActionContext , NotebookAction } from 'vs/workbench/contrib/notebook/browser/controller/coreActions' ;
39
38
import { getNotebookEditorFromEditorPane , ICellViewModel , INotebookEditor , INotebookEditorContribution } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
40
39
import { registerNotebookContribution } from 'vs/workbench/contrib/notebook/browser/notebookEditorExtensions' ;
@@ -79,7 +78,7 @@ export class NotebookMultiCursorController extends Disposable implements INotebo
79
78
80
79
private readonly anchorDisposables = this . _register ( new DisposableStore ( ) ) ;
81
80
private readonly cursorsDisposables = this . _register ( new DisposableStore ( ) ) ;
82
- private cursorsControllers : ResourceMap < [ ITextModel , CursorsController ] > = new ResourceMap < [ ITextModel , CursorsController ] > ( ) ;
81
+ private cursorsControllers : ResourceMap < CursorsController > = new ResourceMap < CursorsController > ( ) ;
83
82
84
83
private _nbIsMultiSelectSession = NOTEBOOK_MULTI_SELECTION_CONTEXT . IsNotebookMultiSelect . bindTo ( this . contextKeyService ) ;
85
84
private _nbMultiSelectState = NOTEBOOK_MULTI_SELECTION_CONTEXT . NotebookMultiSelectState . bindTo ( this . contextKeyService ) ;
@@ -131,7 +130,7 @@ export class NotebookMultiCursorController extends Disposable implements INotebo
131
130
new CursorConfiguration ( textModel . getLanguageId ( ) , textModel . getOptions ( ) , editorConfig , this . languageConfigurationService )
132
131
) ) ;
133
132
controller . setSelections ( new ViewModelEventsCollector ( ) , undefined , match . wordSelections , CursorChangeReason . Explicit ) ;
134
- this . cursorsControllers . set ( match . cellViewModel . uri , [ textModel , controller ] ) ;
133
+ this . cursorsControllers . set ( match . cellViewModel . uri , controller ) ;
135
134
} ) ;
136
135
}
137
136
@@ -270,42 +269,35 @@ export class NotebookMultiCursorController extends Disposable implements INotebo
270
269
return ;
271
270
}
272
271
273
- const textModels = [ anchorCellModel ] ;
274
- this . cursorsControllers . forEach ( controller => {
275
- const model = controller [ 0 ] ;
276
- textModels . push ( model ) ;
277
- } ) ;
278
-
279
272
const newElementsMap : ResourceMap < IUndoRedoElement [ ] > = new ResourceMap < IUndoRedoElement [ ] > ( ) ;
273
+ const resources : URI [ ] = [ ] ;
280
274
281
- textModels . forEach ( model => {
282
- const trackedMatch = this . trackedMatches . find ( match => match . cellViewModel . uri . toString ( ) === model . uri . toString ( ) ) ;
283
- if ( ! trackedMatch ) {
284
- return ;
285
- }
275
+ this . trackedMatches . forEach ( trackedMatch => {
286
276
const undoRedoState = trackedMatch . undoRedoHistory ;
287
277
if ( ! undoRedoState ) {
288
278
return ;
289
279
}
290
280
291
- const currentPastElements = this . undoRedoService . getElements ( model . uri ) . past . slice ( ) ;
281
+ resources . push ( trackedMatch . cellViewModel . uri ) ;
282
+
283
+ const currentPastElements = this . undoRedoService . getElements ( trackedMatch . cellViewModel . uri ) . past . slice ( ) ;
292
284
const oldPastElements = trackedMatch . undoRedoHistory . past . slice ( ) ;
293
285
const newElements = currentPastElements . slice ( oldPastElements . length ) ;
294
286
if ( newElements . length === 0 ) {
295
287
return ;
296
288
}
297
289
298
- newElementsMap . set ( model . uri , newElements ) ;
290
+ newElementsMap . set ( trackedMatch . cellViewModel . uri , newElements ) ;
299
291
300
- this . undoRedoService . removeElements ( model . uri ) ;
292
+ this . undoRedoService . removeElements ( trackedMatch . cellViewModel . uri ) ;
301
293
oldPastElements . forEach ( element => {
302
294
this . undoRedoService . pushElement ( element ) ;
303
295
} ) ;
304
296
} ) ;
305
297
306
298
this . undoRedoService . pushElement ( {
307
299
type : UndoRedoElementType . Workspace ,
308
- resources : textModels . map ( model => model . uri ) ,
300
+ resources : resources ,
309
301
label : 'Multi Cursor Edit' ,
310
302
code : 'multiCursorEdit' ,
311
303
confirmBeforeUndo : false ,
@@ -553,38 +545,6 @@ export class NotebookMultiCursorController extends Disposable implements INotebo
553
545
) ;
554
546
}
555
547
556
- async undo ( ) {
557
- const anchorCellModel = this . anchorCell ?. [ 1 ] . getModel ( ) ;
558
- if ( ! anchorCellModel ) {
559
- // should not happen
560
- return ;
561
- }
562
-
563
- const models = [ anchorCellModel ] ;
564
- this . cursorsControllers . forEach ( controller => {
565
- const model = controller [ 0 ] ;
566
- models . push ( model ) ;
567
- } ) ;
568
-
569
- await Promise . all ( models . map ( model => model . undo ( ) ) ) ;
570
- }
571
-
572
- async redo ( ) {
573
- const anchorCellModel = this . anchorCell ?. [ 1 ] . getModel ( ) ;
574
- if ( ! anchorCellModel ) {
575
- // should not happen
576
- return ;
577
- }
578
-
579
- const models = [ anchorCellModel ] ;
580
- this . cursorsControllers . forEach ( controller => {
581
- const model = controller [ 0 ] ;
582
- models . push ( model ) ;
583
- } ) ;
584
-
585
- await Promise . all ( models . map ( model => model . redo ( ) ) ) ;
586
- }
587
-
588
548
private getWord ( selection : Selection , model : ITextModel ) : IWordAtPosition | null {
589
549
const lineNumber = selection . startLineNumber ;
590
550
const startColumn = selection . startColumn ;
@@ -676,53 +636,6 @@ class NotebookExitMultiSelectionAction extends NotebookAction {
676
636
}
677
637
}
678
638
679
- class NotebookMultiCursorUndoRedoContribution extends Disposable {
680
-
681
- static readonly ID = 'workbench.contrib.notebook.multiCursorUndoRedo' ;
682
-
683
- constructor ( @IEditorService private readonly _editorService : IEditorService ) {
684
- super ( ) ;
685
-
686
- const PRIORITY = 10005 ;
687
- this . _register ( UndoCommand . addImplementation ( PRIORITY , 'notebook-multicursor-undo-redo' , ( ) => {
688
- const editor = getNotebookEditorFromEditorPane ( this . _editorService . activeEditorPane ) ;
689
- if ( ! editor ) {
690
- return false ;
691
- }
692
-
693
- if ( ! editor . hasModel ( ) ) {
694
- return false ;
695
- }
696
-
697
- const controller = editor . getContribution < NotebookMultiCursorController > ( NotebookMultiCursorController . id ) ;
698
-
699
- return controller . undo ( ) ;
700
- } , ContextKeyExpr . and (
701
- ContextKeyExpr . equals ( 'config.notebook.multiSelect.enabled' , true ) ,
702
- NOTEBOOK_IS_ACTIVE_EDITOR ,
703
- NOTEBOOK_MULTI_SELECTION_CONTEXT . IsNotebookMultiSelect ,
704
- ) ) ) ;
705
-
706
- this . _register ( RedoCommand . addImplementation ( PRIORITY , 'notebook-multicursor-undo-redo' , ( ) => {
707
- const editor = getNotebookEditorFromEditorPane ( this . _editorService . activeEditorPane ) ;
708
- if ( ! editor ) {
709
- return false ;
710
- }
711
-
712
- if ( ! editor . hasModel ( ) ) {
713
- return false ;
714
- }
715
-
716
- const controller = editor . getContribution < NotebookMultiCursorController > ( NotebookMultiCursorController . id ) ;
717
- return controller . redo ( ) ;
718
- } , ContextKeyExpr . and (
719
- ContextKeyExpr . equals ( 'config.notebook.multiSelect.enabled' , true ) ,
720
- NOTEBOOK_IS_ACTIVE_EDITOR ,
721
- NOTEBOOK_MULTI_SELECTION_CONTEXT . IsNotebookMultiSelect ,
722
- ) ) ) ;
723
- }
724
- }
725
-
726
639
class NotebookDeleteLeftMultiSelectionAction extends NotebookAction {
727
640
constructor ( ) {
728
641
super ( {
@@ -760,5 +673,4 @@ class NotebookDeleteLeftMultiSelectionAction extends NotebookAction {
760
673
registerNotebookContribution ( NotebookMultiCursorController . id , NotebookMultiCursorController ) ;
761
674
registerAction2 ( NotebookAddMatchToMultiSelectionAction ) ;
762
675
registerAction2 ( NotebookExitMultiSelectionAction ) ;
763
- registerWorkbenchContribution2 ( NotebookMultiCursorUndoRedoContribution . ID , NotebookMultiCursorUndoRedoContribution , WorkbenchPhase . BlockRestore ) ;
764
676
registerAction2 ( NotebookDeleteLeftMultiSelectionAction ) ;
0 commit comments