Skip to content

Commit

Permalink
a11y: add keyboard shortcut for copy, cut, paste (microsoft#2694)
Browse files Browse the repository at this point in the history
* open node shortcut for visual editor

* refactor

* move focus to nexe node

* delete useless code

* fix some bug
  • Loading branch information
alanlong9278 authored Apr 28, 2020
1 parent 6589428 commit 24bebc2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,15 @@ const KeyboardNodeEditingShortcuts = {
'Windows.Control.c': KeyboardCommandTypes.Node.Copy,
'Windows.Control.X': KeyboardCommandTypes.Node.Cut,
'Windows.Control.x': KeyboardCommandTypes.Node.Cut,
'Windows.Control.V': KeyboardCommandTypes.Node.Paste,
'Windows.Control.v': KeyboardCommandTypes.Node.Paste,

'Mac.Meta.C': KeyboardCommandTypes.Node.Copy,
'Mac.Meta.c': KeyboardCommandTypes.Node.Copy,
'Mac.Meta.X': KeyboardCommandTypes.Node.Cut,
'Mac.Meta.x': KeyboardCommandTypes.Node.Cut,
'Mac.Meta.V': KeyboardCommandTypes.Node.Paste,
'Mac.Meta.v': KeyboardCommandTypes.Node.Paste,
};

const KeyboardOperationEditingShortcuts = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,18 @@ export const ObiEditor: FC<ObiEditorProps> = ({
case KeyboardCommandTypes.Node.Cut:
dispatchEvent(NodeEventTypes.CutSelection, { actionIds: getClipboardTargetsFromContext() });
break;
case KeyboardCommandTypes.Node.Paste:
dispatchEvent(NodeEventTypes.AppendSelection, {
target: focusedId,
actions: clipboardActions,
});
case KeyboardCommandTypes.Node.Paste: {
const currentSelectedId = selectionContext.selectedIds[0];
if (currentSelectedId.endsWith('+')) {
const { arrayPath, arrayIndex } = DialogUtils.parseNodePath(currentSelectedId.slice(0, -1)) || {};
dispatchEvent(NodeEventTypes.Insert, {
id: arrayPath,
position: arrayIndex,
$kind: 'PASTE',
});
}
break;
}
}
break;
case KeyboardPrimaryTypes.Cursor: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const EditorConfig = {
showEvents: false,
arrowNavigation: true,
tabNavigation: true,
keyboardNodeEditing: false,
keyboardNodeEditing: true,
keyboardOperationEditing: true,
},
};

0 comments on commit 24bebc2

Please sign in to comment.