Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Composer/packages/client/src/ShellApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ export const ShellApi: React.FC = () => {
});
});
});
apiClient.registerApi('undo', actions.undo);
apiClient.registerApi('redo', actions.redo);

return () => {
apiClient.disconnect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ const shellApi = {
validateExpression: (expression: string) => {
return apiClient.apiCall('isExpression', { expression });
},

undo: () => {
return apiClient.apiCall('undo');
},

redo: () => {
return apiClient.apiCall('redo');
},
};

function ExtensionContainer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export const KeyboardCommandTypes = {
Cut: 'cut',
Paste: 'paste',
},
Operation: {
Redo: 'redo',
Undo: 'undo',
},
};

const findCommandAreaByValue = (() => {
Expand All @@ -40,6 +44,7 @@ const findCommandAreaByValue = (() => {
export const KeyboardPrimaryTypes = {
Cursor: 'Cursor',
Node: 'Node',
Operation: 'Operation',
};

const BasicShortcuts = {
Expand Down Expand Up @@ -88,13 +93,26 @@ const KeyboardNodeEditingShortcuts = {
'Mac.Meta.x': KeyboardCommandTypes.Node.Cut,
};

const { arrowNavigation, tabNavigation, keyboardNodeEditing } = EditorConfig.features;
const KeyboardOperationEditingShortcuts = {
'Windows.Control.Z': KeyboardCommandTypes.Operation.Undo,
'Windows.Control.z': KeyboardCommandTypes.Operation.Undo,
'Windows.Control.Shift.Z': KeyboardCommandTypes.Operation.Redo,
'Windows.Control.Shift.z': KeyboardCommandTypes.Operation.Redo,

'Mac.Meta.Z': KeyboardCommandTypes.Operation.Undo,
'Mac.Meta.z': KeyboardCommandTypes.Operation.Undo,
'Mac.Meta.Shift.Z': KeyboardCommandTypes.Operation.Redo,
'Mac.Meta.Shift.z': KeyboardCommandTypes.Operation.Redo,
};

const { arrowNavigation, tabNavigation, keyboardNodeEditing, keyboardOperationEditing } = EditorConfig.features;

const SupportedShortcuts = {
...BasicShortcuts,
...(arrowNavigation ? ArrowMoveShortcuts : null),
...(tabNavigation ? TabNavShortcuts : null),
...(keyboardNodeEditing ? KeyboardNodeEditingShortcuts : null),
...(keyboardOperationEditing ? KeyboardOperationEditingShortcuts : null),
};

export function mapShortcutToKeyboardCommand(keyCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ export enum NodeEventTypes {
DeleteSelection = 'event.data.delete-selection',
AppendSelection = 'event.data.paste-selection--keyboard',
InsertSelection = 'event.data.paste-selection--menu',
Undo = 'event.operation.undo',
Redo = 'event.operation.redo',
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const ObiEditor: FC<ObiEditorProps> = ({
onOpen,
onChange,
onSelect,
undo,
redo,
}): JSX.Element | null => {
let divRef;

Expand Down Expand Up @@ -125,6 +127,12 @@ export const ObiEditor: FC<ObiEditorProps> = ({
onChange(dialog);
};
break;
case NodeEventTypes.Undo:
handler = undo;
break;
case NodeEventTypes.Redo:
handler = redo;
break;
default:
handler = onFocusSteps;
break;
Expand Down Expand Up @@ -251,6 +259,17 @@ export const ObiEditor: FC<ObiEditorProps> = ({
focused && onFocusSteps([focused]);
break;
}
case KeyboardPrimaryTypes.Operation: {
switch (command) {
case KeyboardCommandTypes.Operation.Undo:
dispatchEvent(NodeEventTypes.Undo, {});
break;
case KeyboardCommandTypes.Operation.Redo:
dispatchEvent(NodeEventTypes.Redo, {});
break;
}
break;
}
default:
break;
}
Expand Down Expand Up @@ -310,6 +329,8 @@ ObiEditor.defaultProps = {
onOpen: () => {},
onChange: () => {},
onSelect: () => {},
undo: () => {},
redo: () => {},
};

interface ObiEditorProps {
Expand All @@ -323,4 +344,6 @@ interface ObiEditorProps {
onOpen: (calleeDialog: string, callerId: string) => any;
onChange: (newDialog: any) => any;
onSelect: (selection: any) => any;
undo?: () => any;
redo?: () => any;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const EditorConfig = {
arrowNavigation: true,
tabNavigation: true,
keyboardNodeEditing: false,
keyboardOperationEditing: true,
},
};
14 changes: 13 additions & 1 deletion Composer/packages/extensions/visual-designer/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ const VisualDesigner: React.FC<VisualDesignerProps> = ({
}

const data = dataCache.current;
const { navTo, onFocusEvent, onFocusSteps, onSelect, saveData, getLgTemplates, removeLgTemplate } = shellApi;
const {
navTo,
onFocusEvent,
onFocusSteps,
onSelect,
saveData,
getLgTemplates,
removeLgTemplate,
undo,
redo,
} = shellApi;

const focusedId = Array.isArray(focusedSteps) && focusedSteps[0] ? focusedSteps[0] : '';

Expand Down Expand Up @@ -64,6 +74,8 @@ const VisualDesigner: React.FC<VisualDesignerProps> = ({
onOpen={(x, rest) => navTo(x, rest)}
onChange={x => saveData(x)}
onSelect={onSelect}
undo={undo}
redo={redo}
/>
</div>
</NodeRendererContext.Provider>
Expand Down