Skip to content

Commit f3c42d8

Browse files
committed
do not copy execution related metadata
1 parent ea02bca commit f3c42d8

File tree

3 files changed

+81
-80
lines changed

3 files changed

+81
-80
lines changed

src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -962,22 +962,24 @@ registerAction2(class extends NotebookAction {
962962

963963
let topPastedCell: CellViewModel | undefined = undefined;
964964
pasteCells.items.reverse().map(cell => {
965-
const data = CellUri.parse(cell.uri);
966-
967-
if (pasteCells.isCopy || data?.notebook.toString() !== viewModel.uri.toString()) {
968-
return viewModel.notebookDocument.createCellTextModel(
969-
cell.getValue(),
970-
cell.language,
971-
cell.cellKind,
972-
[],
973-
cell.metadata
974-
);
975-
} else {
976-
return cell;
977-
}
965+
return {
966+
source: cell.getValue(),
967+
language: cell.language,
968+
cellKind: cell.cellKind,
969+
outputs: cell.outputs,
970+
metadata: {
971+
editable: cell.metadata?.editable,
972+
runnable: cell.metadata?.runnable,
973+
breakpointMargin: cell.metadata?.breakpointMargin,
974+
hasExecutionOrder: cell.metadata?.hasExecutionOrder,
975+
inputCollapsed: cell.metadata?.inputCollapsed,
976+
outputCollapsed: cell.metadata?.outputCollapsed,
977+
custom: cell.metadata?.custom
978+
}
979+
};
978980
}).forEach(pasteCell => {
979981
const newIdx = typeof currCellIndex === 'number' ? currCellIndex + 1 : 0;
980-
topPastedCell = viewModel.createCell(newIdx, pasteCell.getValue(), pasteCell.language, pasteCell.cellKind, pasteCell.metadata, pasteCell.outputs, true);
982+
topPastedCell = viewModel.createCell(newIdx, pasteCell.source, pasteCell.language, pasteCell.cellKind, pasteCell.metadata, pasteCell.outputs, true);
981983
});
982984

983985
if (topPastedCell) {
@@ -1018,21 +1020,23 @@ registerAction2(class extends NotebookCellAction {
10181020

10191021
let topPastedCell: CellViewModel | undefined = undefined;
10201022
pasteCells.items.reverse().map(cell => {
1021-
const data = CellUri.parse(cell.uri);
1022-
1023-
if (pasteCells.isCopy || data?.notebook.toString() !== viewModel.uri.toString()) {
1024-
return viewModel.notebookDocument.createCellTextModel(
1025-
cell.getValue(),
1026-
cell.language,
1027-
cell.cellKind,
1028-
[],
1029-
cell.metadata
1030-
);
1031-
} else {
1032-
return cell;
1033-
}
1023+
return {
1024+
source: cell.getValue(),
1025+
language: cell.language,
1026+
cellKind: cell.cellKind,
1027+
outputs: cell.outputs,
1028+
metadata: {
1029+
editable: cell.metadata?.editable,
1030+
runnable: cell.metadata?.runnable,
1031+
breakpointMargin: cell.metadata?.breakpointMargin,
1032+
hasExecutionOrder: cell.metadata?.hasExecutionOrder,
1033+
inputCollapsed: cell.metadata?.inputCollapsed,
1034+
outputCollapsed: cell.metadata?.outputCollapsed,
1035+
custom: cell.metadata?.custom
1036+
}
1037+
};
10341038
}).forEach(pasteCell => {
1035-
topPastedCell = viewModel.createCell(currCellIndex, pasteCell.getValue(), pasteCell.language, pasteCell.cellKind, pasteCell.metadata, pasteCell.outputs, true);
1039+
topPastedCell = viewModel.createCell(currCellIndex, pasteCell.source, pasteCell.language, pasteCell.cellKind, pasteCell.metadata, pasteCell.outputs, true);
10361040
return;
10371041
});
10381042

src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -426,30 +426,24 @@ export class NotebookService extends Disposable implements INotebookService, ICu
426426

427427
let topPastedCell: CellViewModel | undefined = undefined;
428428
pasteCells.items.reverse().map(cell => {
429-
const data = CellUri.parse(cell.uri);
430-
431-
if (pasteCells.isCopy || data?.notebook.toString() !== viewModel.uri.toString()) {
432-
return viewModel.notebookDocument.createCellTextModel(
433-
cell.getValue(),
434-
cell.language,
435-
cell.cellKind,
436-
[],
437-
{
438-
editable: cell.metadata?.editable,
439-
runnable: cell.metadata?.runnable,
440-
breakpointMargin: cell.metadata?.breakpointMargin,
441-
hasExecutionOrder: cell.metadata?.hasExecutionOrder,
442-
inputCollapsed: cell.metadata?.inputCollapsed,
443-
outputCollapsed: cell.metadata?.outputCollapsed,
444-
custom: cell.metadata?.custom
445-
}
446-
);
447-
} else {
448-
return cell;
449-
}
429+
return {
430+
source: cell.getValue(),
431+
language: cell.language,
432+
cellKind: cell.cellKind,
433+
outputs: cell.outputs,
434+
metadata: {
435+
editable: cell.metadata?.editable,
436+
runnable: cell.metadata?.runnable,
437+
breakpointMargin: cell.metadata?.breakpointMargin,
438+
hasExecutionOrder: cell.metadata?.hasExecutionOrder,
439+
inputCollapsed: cell.metadata?.inputCollapsed,
440+
outputCollapsed: cell.metadata?.outputCollapsed,
441+
custom: cell.metadata?.custom
442+
}
443+
};
450444
}).forEach(pasteCell => {
451445
const newIdx = typeof currCellIndex === 'number' ? currCellIndex + 1 : 0;
452-
topPastedCell = viewModel.createCell(newIdx, pasteCell.getValue(), pasteCell.language, pasteCell.cellKind, pasteCell.metadata, pasteCell.outputs, true);
446+
topPastedCell = viewModel.createCell(newIdx, pasteCell.source, pasteCell.language, pasteCell.cellKind, pasteCell.metadata, pasteCell.outputs, true);
453447
});
454448

455449
if (topPastedCell) {
@@ -462,21 +456,23 @@ export class NotebookService extends Disposable implements INotebookService, ICu
462456

463457
let topPastedCell: CellViewModel | undefined = undefined;
464458
pasteCells.items.reverse().map(cell => {
465-
const data = CellUri.parse(cell.uri);
466-
467-
if (pasteCells.isCopy || data?.notebook.toString() !== viewModel.uri.toString()) {
468-
return viewModel.notebookDocument.createCellTextModel(
469-
cell.getValue(),
470-
cell.language,
471-
cell.cellKind,
472-
[],
473-
cell.metadata
474-
);
475-
} else {
476-
return cell;
477-
}
459+
return {
460+
source: cell.getValue(),
461+
language: cell.language,
462+
cellKind: cell.cellKind,
463+
outputs: cell.outputs,
464+
metadata: {
465+
editable: cell.metadata?.editable,
466+
runnable: cell.metadata?.runnable,
467+
breakpointMargin: cell.metadata?.breakpointMargin,
468+
hasExecutionOrder: cell.metadata?.hasExecutionOrder,
469+
inputCollapsed: cell.metadata?.inputCollapsed,
470+
outputCollapsed: cell.metadata?.outputCollapsed,
471+
custom: cell.metadata?.custom
472+
}
473+
};
478474
}).forEach(pasteCell => {
479-
topPastedCell = viewModel.createCell(0, pasteCell.getValue(), pasteCell.language, pasteCell.cellKind, pasteCell.metadata, pasteCell.outputs, true);
475+
topPastedCell = viewModel.createCell(0, pasteCell.source, pasteCell.language, pasteCell.cellKind, pasteCell.metadata, pasteCell.outputs, true);
480476
});
481477

482478
if (topPastedCell) {

src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -286,18 +286,6 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
286286
super.dispose();
287287
}
288288

289-
createCellTextModel(
290-
source: string,
291-
language: string,
292-
cellKind: CellKind,
293-
outputs: IProcessedOutput[],
294-
metadata: NotebookCellMetadata | undefined
295-
) {
296-
const cellHandle = this._cellhandlePool++;
297-
const cellUri = CellUri.generate(this.uri, cellHandle);
298-
return new NotebookCellTextModel(cellUri, cellHandle, source, language, cellKind, outputs || [], metadata || {}, this.transientOptions, this._modelService);
299-
}
300-
301289
pushStackElement(label: string, selectionState: number[] | undefined) {
302290
this._operationManager.pushStackElement(label, selectionState);
303291
}
@@ -618,9 +606,9 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
618606
}
619607
}
620608

621-
//#region Notebook Text Model Edit API
609+
//#region Split Cell API, should be replaced with applyEdit later on.
622610

623-
insertCell(index: number, cell: NotebookCellTextModel, synchronous: boolean, pushUndoStop: boolean, beforeSelections: number[] | undefined, endSelections: number[] | undefined): void {
611+
private _insertCell(index: number, cell: NotebookCellTextModel, synchronous: boolean, pushUndoStop: boolean, beforeSelections: number[] | undefined, endSelections: number[] | undefined): void {
624612
if (pushUndoStop) {
625613
this._operationManager.pushEditOperation(new InsertCellEdit(this.uri, index, cell, {
626614
insertCell: (index, cell, endSelections) => { this._insertNewCell(index, [cell], true, endSelections); },
@@ -631,6 +619,19 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
631619
this._insertNewCell(index, [cell], synchronous, endSelections);
632620
}
633621

622+
private _createCellTextModel(
623+
source: string,
624+
language: string,
625+
cellKind: CellKind,
626+
outputs: IProcessedOutput[],
627+
metadata: NotebookCellMetadata | undefined
628+
) {
629+
const cellHandle = this._cellhandlePool++;
630+
const cellUri = CellUri.generate(this.uri, cellHandle);
631+
return new NotebookCellTextModel(cellUri, cellHandle, source, language, cellKind, outputs || [], metadata || {}, this.transientOptions, this._modelService);
632+
}
633+
634+
634635
async splitNotebookCell(index: number, newLinesContents: string[], endSelections: number[]) {
635636
const cell = this._cells[index];
636637

@@ -649,8 +650,8 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
649650
let insertIndex = index + 1;
650651
const newCells = [];
651652
for (let j = 1; j < newLinesContents.length; j++, insertIndex++) {
652-
const cell = this.createCellTextModel(newLinesContents[j], language, kind, [], undefined);
653-
this.insertCell(insertIndex, cell, true, false, undefined, j === newLinesContents.length - 1 ? endSelections : undefined);
653+
const cell = this._createCellTextModel(newLinesContents[j], language, kind, [], undefined);
654+
this._insertCell(insertIndex, cell, true, false, undefined, j === newLinesContents.length - 1 ? endSelections : undefined);
654655
newCells.push(cell);
655656
}
656657
}

0 commit comments

Comments
 (0)