From 6363323e89a6b6f8fe817de9fabb77a4c5803b22 Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Wed, 13 Nov 2019 16:17:03 -0800 Subject: [PATCH] Fix for 7999 - CTRL+Z should not undo at the top level --- news/2 Fixes/7999.md | 1 + .../interactiveWindowTypes.ts | 1 + .../interactive-common/mainStateController.ts | 48 ++++++++++--------- .../native-editor/nativeCell.tsx | 15 ++++-- .../native-editor/nativeEditor.tsx | 12 +++++ .../nativeEditor.functional.test.tsx | 42 +++++++++++++++- 6 files changed, 91 insertions(+), 28 deletions(-) create mode 100644 news/2 Fixes/7999.md diff --git a/news/2 Fixes/7999.md b/news/2 Fixes/7999.md new file mode 100644 index 000000000000..216f1c461491 --- /dev/null +++ b/news/2 Fixes/7999.md @@ -0,0 +1 @@ +CTRL+Z is deleting cells. It should only undo changes inside of the code for a cell. 'Z' and 'SHIFT+Z' are for undoing/redoing cell adds/moves. diff --git a/src/client/datascience/interactive-common/interactiveWindowTypes.ts b/src/client/datascience/interactive-common/interactiveWindowTypes.ts index 5b04aa885d4d..e1489b3b71ed 100644 --- a/src/client/datascience/interactive-common/interactiveWindowTypes.ts +++ b/src/client/datascience/interactive-common/interactiveWindowTypes.ts @@ -97,6 +97,7 @@ export enum NativeCommandType { InsertBelow, MoveCellDown, MoveCellUp, + Redo, Run, RunAbove, RunAll, diff --git a/src/datascience-ui/interactive-common/mainStateController.ts b/src/datascience-ui/interactive-common/mainStateController.ts index f59699093fb8..c95d56d38121 100644 --- a/src/datascience-ui/interactive-common/mainStateController.ts +++ b/src/datascience-ui/interactive-common/mainStateController.ts @@ -267,31 +267,35 @@ export class MainStateController implements IMessageHandler { } public redo = () => { - // Pop one off of our redo stack and update our undo - const cells = this.pendingState.redoStack[this.pendingState.redoStack.length - 1]; - const redoStack = this.pendingState.redoStack.slice(0, this.pendingState.redoStack.length - 1); - const undoStack = this.pushStack(this.pendingState.undoStack, this.pendingState.cellVMs); - this.sendMessage(InteractiveWindowMessages.Redo); - this.setState({ - cellVMs: cells, - undoStack: undoStack, - redoStack: redoStack, - skipNextScroll: true - }); + if (this.pendingState.redoStack.length > 0) { + // Pop one off of our redo stack and update our undo + const cells = this.pendingState.redoStack[this.pendingState.redoStack.length - 1]; + const redoStack = this.pendingState.redoStack.slice(0, this.pendingState.redoStack.length - 1); + const undoStack = this.pushStack(this.pendingState.undoStack, this.pendingState.cellVMs); + this.sendMessage(InteractiveWindowMessages.Redo); + this.setState({ + cellVMs: cells, + undoStack: undoStack, + redoStack: redoStack, + skipNextScroll: true + }); + } } public undo = () => { - // Pop one off of our undo stack and update our redo - const cells = this.pendingState.undoStack[this.pendingState.undoStack.length - 1]; - const undoStack = this.pendingState.undoStack.slice(0, this.pendingState.undoStack.length - 1); - const redoStack = this.pushStack(this.pendingState.redoStack, this.pendingState.cellVMs); - this.sendMessage(InteractiveWindowMessages.Undo); - this.setState({ - cellVMs: cells, - undoStack: undoStack, - redoStack: redoStack, - skipNextScroll: true - }); + if (this.pendingState.undoStack.length > 0) { + // Pop one off of our undo stack and update our redo + const cells = this.pendingState.undoStack[this.pendingState.undoStack.length - 1]; + const undoStack = this.pendingState.undoStack.slice(0, this.pendingState.undoStack.length - 1); + const redoStack = this.pushStack(this.pendingState.redoStack, this.pendingState.cellVMs); + this.sendMessage(InteractiveWindowMessages.Undo); + this.setState({ + cellVMs: cells, + undoStack: undoStack, + redoStack: redoStack, + skipNextScroll: true + }); + } } public deleteCell = (cellId: string) => { diff --git a/src/datascience-ui/native-editor/nativeCell.tsx b/src/datascience-ui/native-editor/nativeCell.tsx index 08500ae84dd0..567216abeb58 100644 --- a/src/datascience-ui/native-editor/nativeCell.tsx +++ b/src/datascience-ui/native-editor/nativeCell.tsx @@ -325,10 +325,17 @@ export class NativeCell extends React.Component { } break; case 'z': - if (!this.isFocused() && this.props.stateController.canUndo()) { - e.stopPropagation(); - this.props.stateController.undo(); - this.props.stateController.sendCommand(NativeCommandType.Undo, 'keyboard'); + case 'Z': + if (!this.isFocused()) { + if (e.shiftKey && !e.ctrlKey && !e.altKey && this.props.stateController.canRedo()) { + e.stopPropagation(); + this.props.stateController.redo(); + this.props.stateController.sendCommand(NativeCommandType.Redo, 'keyboard'); + } else if (!e.shiftKey && !e.altKey && !e.ctrlKey && this.props.stateController.canUndo()) { + e.stopPropagation(); + this.props.stateController.undo(); + this.props.stateController.sendCommand(NativeCommandType.Undo, 'keyboard'); + } } break; diff --git a/src/datascience-ui/native-editor/nativeEditor.tsx b/src/datascience-ui/native-editor/nativeEditor.tsx index 804382da9c1d..666e53377ac8 100644 --- a/src/datascience-ui/native-editor/nativeEditor.tsx +++ b/src/datascience-ui/native-editor/nativeEditor.tsx @@ -365,6 +365,18 @@ export class NativeEditor extends React.Component