@@ -11,10 +11,9 @@ import { clamp } from 'vs/base/common/numbers';
11
11
import * as strings from 'vs/base/common/strings' ;
12
12
import { URI } from 'vs/base/common/uri' ;
13
13
import { IBulkEditService , ResourceEdit , ResourceTextEdit } from 'vs/editor/browser/services/bulkEditService' ;
14
- import { IPosition , Position } from 'vs/editor/common/core/position' ;
15
14
import { Range } from 'vs/editor/common/core/range' ;
16
15
import * as editorCommon from 'vs/editor/common/editorCommon' ;
17
- import { EndOfLinePreference , IModelDecorationOptions , IModelDeltaDecoration , IReadonlyTextBuffer , TrackedRangeStickiness } from 'vs/editor/common/model' ;
16
+ import { IModelDecorationOptions , IModelDeltaDecoration , TrackedRangeStickiness } from 'vs/editor/common/model' ;
18
17
import { MultiModelEditStackElement , SingleModelEditStackElement } from 'vs/editor/common/model/editStack' ;
19
18
import { IntervalNode , IntervalTree } from 'vs/editor/common/model/intervalTree' ;
20
19
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel' ;
@@ -31,7 +30,7 @@ import { MarkupCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewM
31
30
import { ViewContext } from 'vs/workbench/contrib/notebook/browser/viewModel/viewContext' ;
32
31
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel' ;
33
32
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel' ;
34
- import { CellEditType , CellKind , ICell , INotebookSearchOptions , IOutputDto , ISelectionState , NotebookCellMetadata , NotebookCellsChangeType , NotebookCellTextModelSplice , SelectionStateType } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
33
+ import { CellEditType , CellKind , ICell , INotebookSearchOptions , ISelectionState , NotebookCellsChangeType , NotebookCellTextModelSplice , SelectionStateType } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
35
34
import { cellIndexesToRanges , cellRangesToIndexes , ICellRange , reduceRanges } from 'vs/workbench/contrib/notebook/common/notebookRange' ;
36
35
37
36
export interface INotebookEditorViewState {
@@ -589,8 +588,8 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
589
588
return index + 1 ;
590
589
}
591
590
592
- hasCell ( handle : number ) {
593
- return this . _handleToViewCellMapping . has ( handle ) ;
591
+ hasCell ( cell : ICellViewModel ) {
592
+ return this . _handleToViewCellMapping . has ( cell . handle ) ;
594
593
}
595
594
596
595
getVersionId ( ) {
@@ -774,58 +773,6 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
774
773
}
775
774
}
776
775
777
- createCell ( index : number , source : string , language : string , type : CellKind , metadata : NotebookCellMetadata | undefined , outputs : IOutputDto [ ] , synchronous : boolean , pushUndoStop : boolean = true , previouslyPrimary : number | null = null , previouslyFocused : ICellViewModel [ ] = [ ] ) : CellViewModel {
778
- const beforeSelections = previouslyFocused . map ( e => e . handle ) ;
779
- const endSelections : ISelectionState = { kind : SelectionStateType . Index , focus : { start : index , end : index + 1 } , selections : [ { start : index , end : index + 1 } ] } ;
780
- this . _notebook . applyEdits ( [
781
- {
782
- editType : CellEditType . Replace ,
783
- index,
784
- count : 0 ,
785
- cells : [
786
- {
787
- cellKind : type ,
788
- language : language ,
789
- mime : undefined ,
790
- outputs : outputs ,
791
- metadata : metadata ,
792
- source : source
793
- }
794
- ]
795
- }
796
- ] , synchronous , { kind : SelectionStateType . Handle , primary : previouslyPrimary , selections : beforeSelections } , ( ) => endSelections , undefined ) ;
797
- return this . _viewCells [ index ] ;
798
- }
799
-
800
- deleteCell ( index : number , synchronous : boolean , pushUndoStop : boolean = true ) {
801
- const focusSelectionIndex = this . getFocus ( ) ?. start ?? null ;
802
- let endPrimarySelection : number | null = null ;
803
-
804
- if ( index === focusSelectionIndex ) {
805
- if ( focusSelectionIndex < this . length - 1 ) {
806
- endPrimarySelection = this . _viewCells [ focusSelectionIndex + 1 ] . handle ;
807
- } else if ( focusSelectionIndex === this . length - 1 && this . length > 1 ) {
808
- endPrimarySelection = this . _viewCells [ focusSelectionIndex - 1 ] . handle ;
809
- }
810
- }
811
-
812
- let endSelections : number [ ] = this . selectionHandles . filter ( handle => handle !== endPrimarySelection && handle !== this . _viewCells [ index ] ?. handle ) ;
813
-
814
- this . _notebook . applyEdits ( [
815
- {
816
- editType : CellEditType . Replace ,
817
- index : index ,
818
- count : 1 ,
819
- cells : [ ]
820
- } ] ,
821
- synchronous ,
822
- { kind : SelectionStateType . Index , focus : this . getFocus ( ) , selections : this . getSelections ( ) } ,
823
- ( ) => ( { kind : SelectionStateType . Handle , primary : endPrimarySelection , selections : endSelections } ) ,
824
- undefined ,
825
- pushUndoStop
826
- ) ;
827
- }
828
-
829
776
/**
830
777
*
831
778
* @param index
@@ -851,65 +798,6 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
851
798
return true ;
852
799
}
853
800
854
- private _pushIfAbsent ( positions : IPosition [ ] , p : IPosition ) {
855
- const last = positions . length > 0 ? positions [ positions . length - 1 ] : undefined ;
856
- if ( ! last || last . lineNumber !== p . lineNumber || last . column !== p . column ) {
857
- positions . push ( p ) ;
858
- }
859
- }
860
-
861
- /**
862
- * Add split point at the beginning and the end;
863
- * Move end of line split points to the beginning of the next line;
864
- * Avoid duplicate split points
865
- */
866
- private _splitPointsToBoundaries ( splitPoints : IPosition [ ] , textBuffer : IReadonlyTextBuffer ) : IPosition [ ] | null {
867
- const boundaries : IPosition [ ] = [ ] ;
868
- const lineCnt = textBuffer . getLineCount ( ) ;
869
- const getLineLen = ( lineNumber : number ) => {
870
- return textBuffer . getLineLength ( lineNumber ) ;
871
- } ;
872
-
873
- // split points need to be sorted
874
- splitPoints = splitPoints . sort ( ( l , r ) => {
875
- const lineDiff = l . lineNumber - r . lineNumber ;
876
- const columnDiff = l . column - r . column ;
877
- return lineDiff !== 0 ? lineDiff : columnDiff ;
878
- } ) ;
879
-
880
- for ( let sp of splitPoints ) {
881
- if ( getLineLen ( sp . lineNumber ) + 1 === sp . column && sp . column !== 1 /** empty line */ && sp . lineNumber < lineCnt ) {
882
- sp = new Position ( sp . lineNumber + 1 , 1 ) ;
883
- }
884
- this . _pushIfAbsent ( boundaries , sp ) ;
885
- }
886
-
887
- if ( boundaries . length === 0 ) {
888
- return null ;
889
- }
890
-
891
- // boundaries already sorted and not empty
892
- const modelStart = new Position ( 1 , 1 ) ;
893
- const modelEnd = new Position ( lineCnt , getLineLen ( lineCnt ) + 1 ) ;
894
- return [ modelStart , ...boundaries , modelEnd ] ;
895
- }
896
-
897
- computeCellLinesContents ( cell : ICellViewModel , splitPoints : IPosition [ ] ) : string [ ] | null {
898
- const rangeBoundaries = this . _splitPointsToBoundaries ( splitPoints , cell . textBuffer ) ;
899
- if ( ! rangeBoundaries ) {
900
- return null ;
901
- }
902
- const newLineModels : string [ ] = [ ] ;
903
- for ( let i = 1 ; i < rangeBoundaries . length ; i ++ ) {
904
- const start = rangeBoundaries [ i - 1 ] ;
905
- const end = rangeBoundaries [ i ] ;
906
-
907
- newLineModels . push ( cell . textBuffer . getValueInRange ( new Range ( start . lineNumber , start . column , end . lineNumber , end . column ) , EndOfLinePreference . TextDefined ) ) ;
908
- }
909
-
910
- return newLineModels ;
911
- }
912
-
913
801
getEditorViewState ( ) : INotebookEditorViewState {
914
802
const editingCells : { [ key : number ] : boolean ; } = { } ;
915
803
this . _viewCells . forEach ( ( cell , i ) => {
0 commit comments