File tree Expand file tree Collapse file tree 8 files changed +24
-8
lines changed
history-react/redux/reducers
interactive-common/redux/reducers
native-editor/redux/reducers Expand file tree Collapse file tree 8 files changed +24
-8
lines changed Original file line number Diff line number Diff line change
1
+ Ensure user code in cell is preserved between cell execution and cell edits.
Original file line number Diff line number Diff line change @@ -669,7 +669,7 @@ export abstract class InteractiveBase extends WebViewHost<IInteractiveWindowMapp
669
669
670
670
case CellState . executing :
671
671
// Tell the react controls we have an update
672
- this . postMessage ( InteractiveWindowMessages . UpdateCell , cell ) . ignoreErrors ( ) ;
672
+ this . postMessage ( InteractiveWindowMessages . UpdateCellWithExecutionResults , cell ) . ignoreErrors ( ) ;
673
673
break ;
674
674
675
675
case CellState . error :
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ import { BaseReduxActionPayload } from './types';
30
30
export enum InteractiveWindowMessages {
31
31
StartCell = 'start_cell' ,
32
32
FinishCell = 'finish_cell' ,
33
- UpdateCell = 'update_cell ' ,
33
+ UpdateCellWithExecutionResults = 'UpdateCellWithExecutionResults ' ,
34
34
GotoCodeCell = 'gotocell_code' ,
35
35
CopyCodeCell = 'copycell_code' ,
36
36
NotebookExecutionActivated = 'notebook_execution_activated' ,
@@ -497,7 +497,7 @@ export class IInteractiveWindowMapping {
497
497
public [ IPyWidgetMessages . IPyWidgets_mirror_execute ] : { id : string ; msg : KernelMessage . IExecuteRequestMsg } ;
498
498
public [ InteractiveWindowMessages . StartCell ] : ICell ;
499
499
public [ InteractiveWindowMessages . FinishCell ] : ICell ;
500
- public [ InteractiveWindowMessages . UpdateCell ] : ICell ;
500
+ public [ InteractiveWindowMessages . UpdateCellWithExecutionResults ] : ICell ;
501
501
public [ InteractiveWindowMessages . GotoCodeCell ] : IGotoCode ;
502
502
public [ InteractiveWindowMessages . CopyCodeCell ] : ICopyCode ;
503
503
public [ InteractiveWindowMessages . NotebookExecutionActivated ] : string ;
Original file line number Diff line number Diff line change @@ -166,7 +166,8 @@ const messageWithMessageTypes: MessageMapping<IInteractiveWindowMapping> & Messa
166
166
[ InteractiveWindowMessages . Sync ] : MessageType . other ,
167
167
[ InteractiveWindowMessages . Undo ] : MessageType . other ,
168
168
[ InteractiveWindowMessages . UnfocusedCellEditor ] : MessageType . syncWithLiveShare ,
169
- [ InteractiveWindowMessages . UpdateCell ] : MessageType . syncAcrossSameNotebooks | MessageType . syncWithLiveShare ,
169
+ [ InteractiveWindowMessages . UpdateCellWithExecutionResults ] :
170
+ MessageType . syncAcrossSameNotebooks | MessageType . syncWithLiveShare ,
170
171
[ InteractiveWindowMessages . UpdateModel ] : MessageType . syncAcrossSameNotebooks | MessageType . syncWithLiveShare ,
171
172
[ InteractiveWindowMessages . UpdateKernel ] : MessageType . syncAcrossSameNotebooks | MessageType . syncWithLiveShare ,
172
173
[ InteractiveWindowMessages . UpdateDisplayData ] : MessageType . syncWithLiveShare ,
Original file line number Diff line number Diff line change @@ -449,6 +449,20 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
449
449
const modified = filtered . filter ( ( c ) => c . state === CellState . finished || c . state === CellState . error ) ;
450
450
const unmodified = this . model ?. cells . filter ( ( c ) => modified . find ( ( m ) => m . id === c . id ) ) ;
451
451
if ( modified . length > 0 && unmodified && this . model ) {
452
+ // As this point, we're updating the model because of changes to the cell as a result of execution.
453
+ // The output and execution count change, however we're just going to update everything.
454
+ // But, we should not update the `source`. The only time source can change is when a request comes from the UI.
455
+ // Perhaps we need a finer grained update (update only output and execution count along with `source=execution`).
456
+ // For now retain source from previous model.
457
+ // E.g. user executes a cell, in the mean time they update the text. Now model contains new value.
458
+ // However once execution has completed, this code will update the model with results from previous execution (prior to edit).
459
+ // We now need to give preference to the text in the model, over the old one that was executed.
460
+ modified . forEach ( ( modifiedCell ) => {
461
+ const originalCell = unmodified . find ( ( unmodifiedCell ) => unmodifiedCell . id === modifiedCell . id ) ;
462
+ if ( originalCell ) {
463
+ modifiedCell . data . source = originalCell . data . source ;
464
+ }
465
+ } ) ;
452
466
this . model . update ( {
453
467
source : 'user' ,
454
468
kind : 'modify' ,
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ export const reducerMap: Partial<IInteractiveActionMapping> = {
47
47
[ InteractiveWindowMessages . Redo ] : Execution . redo ,
48
48
[ InteractiveWindowMessages . StartCell ] : Creation . startCell ,
49
49
[ InteractiveWindowMessages . FinishCell ] : Creation . finishCell ,
50
- [ InteractiveWindowMessages . UpdateCell ] : Creation . updateCell ,
50
+ [ InteractiveWindowMessages . UpdateCellWithExecutionResults ] : Creation . updateCell ,
51
51
[ InteractiveWindowMessages . Activate ] : CommonEffects . activate ,
52
52
[ InteractiveWindowMessages . RestartKernel ] : Kernel . handleRestarted ,
53
53
[ CssMessages . GetCssResponse ] : CommonEffects . handleCss ,
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ export namespace Helpers {
83
83
84
84
// Prevent updates to the source, as its possible we have recieved a response for a cell execution
85
85
// and the user has updated the cell text since then.
86
- const newVM = {
86
+ const newVM : ICellViewModel = {
87
87
...newVMs [ index ] ,
88
88
hasBeenRun : true ,
89
89
cell : {
@@ -95,7 +95,7 @@ export namespace Helpers {
95
95
}
96
96
}
97
97
} ;
98
- newVMs [ index ] = asCellViewModel ( newVM ) ;
98
+ newVMs [ index ] = newVM ;
99
99
100
100
return {
101
101
...arg . prevState ,
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ export const reducerMap: Partial<INativeEditorActionMapping> = {
64
64
// Messages from the webview (some are ignored)
65
65
[ InteractiveWindowMessages . StartCell ] : Creation . startCell ,
66
66
[ InteractiveWindowMessages . FinishCell ] : Creation . finishCell ,
67
- [ InteractiveWindowMessages . UpdateCell ] : Creation . updateCell ,
67
+ [ InteractiveWindowMessages . UpdateCellWithExecutionResults ] : Creation . updateCell ,
68
68
[ InteractiveWindowMessages . NotebookDirty ] : CommonEffects . notebookDirty ,
69
69
[ InteractiveWindowMessages . NotebookClean ] : CommonEffects . notebookClean ,
70
70
[ InteractiveWindowMessages . LoadAllCells ] : Creation . loadAllCells ,
You can’t perform that action at this time.
0 commit comments