|
@@ -15,8 +15,8 @@ export default class HotkeysDetector extends React.Component {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
check(event) {
|
|
check(event) {
|
|
|
-
|
|
|
|
|
const target = event.target;
|
|
const target = event.target;
|
|
|
|
|
+ let eventKey = event.key;
|
|
|
// ignore when target dom is input
|
|
// ignore when target dom is input
|
|
|
const inputPattern = /^input|textinput|textarea$/i;
|
|
const inputPattern = /^input|textinput|textarea$/i;
|
|
|
if (inputPattern.test(target.tagName) || target.isContentEditable) {
|
|
if (inputPattern.test(target.tagName) || target.isContentEditable) {
|
|
@@ -25,44 +25,28 @@ export default class HotkeysDetector extends React.Component {
|
|
|
this.processingCommands = this.hotkeyList;
|
|
this.processingCommands = this.hotkeyList;
|
|
|
|
|
|
|
|
if (event.ctrlKey) {
|
|
if (event.ctrlKey) {
|
|
|
- this.processingCommands = this.processingCommands.filter((value) => {
|
|
|
|
|
- return value.ctrlKey;
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- else if (event.metaKey) {
|
|
|
|
|
- this.processingCommands = this.processingCommands.filter((value) => {
|
|
|
|
|
- return value.metaKey;
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ eventKey += '+ctrl';
|
|
|
}
|
|
}
|
|
|
- else if (event.altKey) {
|
|
|
|
|
- this.processingCommands = this.processingCommands.filter((value) => {
|
|
|
|
|
- return value.altKey;
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (event.metaKey) {
|
|
|
|
|
+ eventKey += '+meta';
|
|
|
}
|
|
}
|
|
|
- else if (event.shiftKey) {
|
|
|
|
|
- this.processingCommands = this.processingCommands.filter((value) => {
|
|
|
|
|
- return value.shiftKey;
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (event.altKey) {
|
|
|
|
|
+ eventKey += '+alt';
|
|
|
}
|
|
}
|
|
|
- else {
|
|
|
|
|
- this.processingCommands = this.processingCommands.filter((value) => {
|
|
|
|
|
- return ((!value.ctrlKey) && (!value.metaKey) && (!value.altKey) && (!value.shiftKey));
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (event.shiftKey) {
|
|
|
|
|
+ eventKey += '+shift';
|
|
|
}
|
|
}
|
|
|
this.setState({
|
|
this.setState({
|
|
|
- userCommand: this.state.userCommand.concat(event.key),
|
|
|
|
|
|
|
+ userCommand: this.state.userCommand.concat(eventKey),
|
|
|
});
|
|
});
|
|
|
// filters the corresponding hotkeys(keys) that the user has pressed so far
|
|
// filters the corresponding hotkeys(keys) that the user has pressed so far
|
|
|
const tempUserCommand = this.state.userCommand;
|
|
const tempUserCommand = this.state.userCommand;
|
|
|
this.processingCommands = this.processingCommands.filter((value) => {
|
|
this.processingCommands = this.processingCommands.filter((value) => {
|
|
|
- return value.stroke.slice(0, tempUserCommand.length).toString() === tempUserCommand.toString();
|
|
|
|
|
- });
|
|
|
|
|
- this.processingCommands = this.processingCommands.map((value) => {
|
|
|
|
|
- return value.stroke;
|
|
|
|
|
|
|
+ return value.slice(0, tempUserCommand.length).toString() === tempUserCommand.toString();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// executes if there were keymap that matches what the user pressed fully.
|
|
// executes if there were keymap that matches what the user pressed fully.
|
|
|
- if ((this.processingCommands.length === 1) && (this.hotkeyList.find(obj => obj.stroke.toString() === this.state.userCommand.toString()))) {
|
|
|
|
|
|
|
+ if ((this.processingCommands.length === 1) && (this.hotkeyList.find(ary => ary.toString() === this.state.userCommand.toString()))) {
|
|
|
this.props.onDetected(this.processingCommands[0]);
|
|
this.props.onDetected(this.processingCommands[0]);
|
|
|
this.setState({
|
|
this.setState({
|
|
|
userCommand: [],
|
|
userCommand: [],
|