Skip to content

Commit

Permalink
Review feedback and fix undo/redo for interactive command
Browse files Browse the repository at this point in the history
  • Loading branch information
rchiodo committed Jan 5, 2021
1 parent abc4978 commit 2be16d1
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/client/datascience/interactive-common/interactiveBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,12 @@ export abstract class InteractiveBase extends WebviewPanelHost<IInteractiveWindo

@captureTelemetry(Telemetry.Undo)
public undoCells() {
this.postMessage(InteractiveWindowMessages.Undo).ignoreErrors();
this.postMessage(InteractiveWindowMessages.UndoCommand).ignoreErrors();
}

@captureTelemetry(Telemetry.Redo)
public redoCells() {
this.postMessage(InteractiveWindowMessages.Redo).ignoreErrors();
this.postMessage(InteractiveWindowMessages.RedoCommand).ignoreErrors();
}

@captureTelemetry(Telemetry.DeleteAllCells)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export enum InteractiveWindowMessages {
DeleteAllCells = 'delete_all_cells',
Undo = 'undo',
Redo = 'redo',
UndoCommand = 'undo.command', // Only used by the interactive window
RedoCommand = 'redo.command',
ExpandAll = 'expand_all',
CollapseAll = 'collapse_all',
StartProgress = 'start_progress',
Expand Down Expand Up @@ -611,6 +613,8 @@ export class IInteractiveWindowMapping {
public [InteractiveWindowMessages.DeleteAllCells]: IAddCellAction;
public [InteractiveWindowMessages.Undo]: ICell[];
public [InteractiveWindowMessages.Redo]: ICell[];
public [InteractiveWindowMessages.UndoCommand]: never | undefined;
public [InteractiveWindowMessages.RedoCommand]: never | undefined;
public [InteractiveWindowMessages.ExpandAll]: never | undefined;
public [InteractiveWindowMessages.CollapseAll]: never | undefined;
public [InteractiveWindowMessages.StartProgress]: never | undefined;
Expand Down
2 changes: 2 additions & 0 deletions src/client/datascience/interactive-common/synchronization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ const messageWithMessageTypes: MessageMapping<IInteractiveWindowMapping> & Messa
[InteractiveWindowMessages.SubmitNewCell]: MessageType.other,
[InteractiveWindowMessages.Sync]: MessageType.other,
[InteractiveWindowMessages.Undo]: MessageType.other,
[InteractiveWindowMessages.UndoCommand]: MessageType.other,
[InteractiveWindowMessages.RedoCommand]: MessageType.other,
[InteractiveWindowMessages.UnfocusedCellEditor]: MessageType.syncWithLiveShare,
[InteractiveWindowMessages.UpdateCellWithExecutionResults]:
MessageType.syncAcrossSameNotebooks | MessageType.syncWithLiveShare,
Expand Down
4 changes: 3 additions & 1 deletion src/datascience-ui/history-react/redux/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,7 @@ export const reducerMap: Partial<IInteractiveActionMapping> = {
[InteractiveWindowMessages.UpdateDisplayData]: CommonEffects.handleUpdateDisplayData,
[InteractiveWindowMessages.HasCell]: Transfer.hasCell,
[InteractiveWindowMessages.UpdateExternalCellButtons]: CommonEffects.handleWebviewButtons,
[InteractiveWindowMessages.ExecuteExternalCommand]: Transfer.executeExternalCommand
[InteractiveWindowMessages.ExecuteExternalCommand]: Transfer.executeExternalCommand,
[InteractiveWindowMessages.UndoCommand]: Execution.undo,
[InteractiveWindowMessages.RedoCommand]: Execution.redo
};
52 changes: 38 additions & 14 deletions src/datascience-ui/native-editor/redux/reducers/creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ export namespace Creation {
if (position >= 0) {
newList.splice(position, 0, newVM);
} else {
newList.splice(newList.length, 0, newVM);
position = newList.length;
newList.splice(0, 0, newVM);
position = 0;
}

const result = {
Expand Down Expand Up @@ -145,7 +145,19 @@ export namespace Creation {
}

export function insertBelow(arg: NativeEditorReducerArg<ICellAction & IAddCellAction>): IMainState {
const newVM = prepareCellVM(createEmptyCell(arg.payload.data.newCellId, null), false, arg.prevState.settings);
return insertExistingBelow({
...arg,
payload: {
...arg.payload,
data: { ...arg.payload.data, cell: createEmptyCell(arg.payload.data.newCellId, null) }
}
});
}

export function insertExistingBelow(
arg: NativeEditorReducerArg<ICellAction & IAddCellAction & { cell: ICell }>
): IMainState {
const newVM = prepareCellVM(arg.payload.data.cell, false, arg.prevState.settings);
const newList = [...arg.prevState.cellVMs];

// Find the position where we want to insert
Expand Down Expand Up @@ -370,17 +382,29 @@ export namespace Creation {
payload: { ...arg.payload, data: { cellId: arg.payload.data.cell.id } }
});
case 'remove':
const cellBelow =
arg.prevState.cellVMs.length > arg.payload.data.index
? arg.prevState.cellVMs[arg.payload.data.index].cell
: undefined;
return insertExistingAbove({
...disabledQueueArg,
payload: {
...arg.payload,
data: { cell: arg.payload.data.cell, cellId: cellBelow ? cellBelow.id : undefined }
}
});
if (arg.prevState.cellVMs.length > arg.payload.data.index) {
const cellBelow = arg.prevState.cellVMs[arg.payload.data.index].cell;
return insertExistingAbove({
...disabledQueueArg,
payload: {
...arg.payload,
data: { cell: arg.payload.data.cell, cellId: cellBelow ? cellBelow.id : undefined }
}
});
} else {
// Delete is outside current range. Insert at the bottom
return insertExistingBelow({
...disabledQueueArg,
payload: {
...arg.payload,
data: {
cell: arg.payload.data.cell,
cellId: undefined,
newCellId: arg.payload.data.cell.id
}
}
});
}
case 'remove_all':
return loadAllCells({
...disabledQueueArg,
Expand Down

0 comments on commit 2be16d1

Please sign in to comment.