Support reverting Jupyter execution count via nb diff editor (#227157)

Co-authored-by: Benjamin Pasero <benjamin.pasero@microsoft.com>
This commit is contained in:
Don Jayamanne
2024-09-02 14:23:17 +10:00
committed by GitHub
parent 6d0f24883e
commit 2503ccd9d0

View File

@@ -123,10 +123,13 @@ function createCodeCellFromNotebookCell(cell: NotebookCellData, preferredLanguag
const codeCell: any = {
cell_type: 'code',
// Possible the metadata was edited as part of diff view
// In diff view we display execution_count as part of metadata, hence when execution count changes in metadata,
// We need to change that here as well, i.e. give preference to any execution_count value in metadata.
execution_count: cellMetadata.execution_count ?? cell.executionSummary?.executionOrder ?? null,
// Metadata should always contain the execution_count.
// When ever execution summary data changes we will update the metadata to contain the execution count.
// Failing to do so means we have a problem.
// Also do not read the value of executionSummary here, as its possible user reverted changes to metadata
// & in that case execution summary could contain the data, but metadata will not.
// In such cases we do not want to re-set the metadata with the value from execution summary (remember, user reverted that).
execution_count: cellMetadata.execution_count ?? null,
source: splitMultilineString(cell.value.replace(/\r\n/g, '\n')),
outputs: (cell.outputs || []).map(translateCellDisplayOutput),
metadata: cellMetadata.metadata