@@ -23,6 +23,7 @@ import { CellKind, NOTEBOOK_EDITOR_CURSOR_BOUNDARY, NotebookCellRunState } from
2323import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService' ;
2424import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
2525import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService' ;
26+ import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel' ;
2627
2728// Notebook Commands
2829const EXECUTE_NOTEBOOK_COMMAND_ID = 'notebook.execute' ;
@@ -745,7 +746,7 @@ registerAction2(class extends NotebookAction {
745746 const clipboardService = accessor . get < IClipboardService > ( IClipboardService ) ;
746747 const notebookService = accessor . get < INotebookService > ( INotebookService ) ;
747748 clipboardService . writeText ( context . cell . getText ( ) ) ;
748- notebookService . setToCopy ( [ context . cell . model ] ) ;
749+ notebookService . setToCopy ( [ context . cell . model ] , true ) ;
749750 }
750751} ) ;
751752
@@ -774,7 +775,7 @@ registerAction2(class extends NotebookAction {
774775 }
775776
776777 viewModel . deleteCell ( viewModel . getCellIndex ( context . cell ) , true ) ;
777- notebookService . setToCopy ( [ context . cell . model ] ) ;
778+ notebookService . setToCopy ( [ context . cell . model ] , false ) ;
778779 }
779780} ) ;
780781
@@ -794,17 +795,33 @@ registerAction2(class extends NotebookAction {
794795
795796 async runWithContext ( accessor : ServicesAccessor , context : INotebookCellActionContext ) {
796797 const notebookService = accessor . get < INotebookService > ( INotebookService ) ;
797- const pasteCells = notebookService . getToCopy ( ) || [ ] ;
798+ const pasteCells = notebookService . getToCopy ( ) ;
798799
799800 const viewModel = context . notebookEditor . viewModel ;
800801
801802 if ( ! viewModel ) {
802803 return ;
803804 }
804805
806+ if ( ! pasteCells ) {
807+ return ;
808+ }
809+
805810 const currCellIndex = viewModel . getCellIndex ( context ! . cell ) ;
806811
807- pasteCells . reverse ( ) . forEach ( pasteCell => {
812+ pasteCells . items . reverse ( ) . map ( cell => {
813+ if ( pasteCells . isCopy ) {
814+ return viewModel . notebookDocument . createCellTextModel (
815+ cell . getValue ( ) ,
816+ cell . language ,
817+ cell . cellKind ,
818+ [ ] ,
819+ cell . metadata
820+ ) ;
821+ } else {
822+ return cell ;
823+ }
824+ } ) . forEach ( pasteCell => {
808825 viewModel . insertCell ( currCellIndex , pasteCell , true ) ;
809826 return ;
810827 } ) ;
@@ -826,17 +843,33 @@ registerAction2(class extends NotebookAction {
826843
827844 async runWithContext ( accessor : ServicesAccessor , context : INotebookCellActionContext ) {
828845 const notebookService = accessor . get < INotebookService > ( INotebookService ) ;
829- const pasteCells = notebookService . getToCopy ( ) || [ ] ;
846+ const pasteCells = notebookService . getToCopy ( ) ;
830847
831848 const viewModel = context . notebookEditor . viewModel ;
832849
833850 if ( ! viewModel ) {
834851 return ;
835852 }
836853
854+ if ( ! pasteCells ) {
855+ return ;
856+ }
857+
837858 const currCellIndex = viewModel . getCellIndex ( context ! . cell ) ;
838859
839- pasteCells . reverse ( ) . forEach ( pasteCell => {
860+ pasteCells . items . reverse ( ) . map ( cell => {
861+ if ( pasteCells . isCopy ) {
862+ return viewModel . notebookDocument . createCellTextModel (
863+ cell . getValue ( ) ,
864+ cell . language ,
865+ cell . cellKind ,
866+ [ ] ,
867+ cell . metadata
868+ ) ;
869+ } else {
870+ return cell ;
871+ }
872+ } ) . forEach ( pasteCell => {
840873 viewModel . insertCell ( currCellIndex + 1 , pasteCell , true ) ;
841874 return ;
842875 } ) ;
0 commit comments