Skip to content

Commit

Permalink
fix(xod-client): handle CmdOrCtrl+A on all platforms and OS correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
brusherru committed Oct 29, 2018
1 parent 41ddd3c commit e4f7076
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
11 changes: 0 additions & 11 deletions packages/xod-client-browser/src/containers/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,6 @@ class App extends client.App {

props.actions.openProject(props.tutorialProject);
props.actions.fetchGrant();

document.addEventListener('keydown', event => {
// Prevent selecting all contents with "Ctrl+a" or "Command+a"
// Ctrl+a or Command+a
const key = event.keyCode || event.which;
const mod = event.metaKey || event.ctrlKey;
if (mod && key === 65 && !client.isInputTarget(event)) {
event.preventDefault();
this.props.actions.selectAll();
}
});
}

onDocumentClick(e) {
Expand Down
13 changes: 13 additions & 0 deletions packages/xod-client/src/core/containers/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
transpile,
} from 'xod-arduino';

import { isInputTarget } from '../../utils/browser';
import { lowercaseKebabMask } from '../../utils/inputFormatting';
import sanctuaryPropType from '../../utils/sanctuaryPropType';

Expand All @@ -32,6 +33,17 @@ export default class App extends React.Component {
this.transformProjectForTranspiler = this.transformProjectForTranspiler.bind(
this
);

document.addEventListener('keydown', event => {
// Prevent selecting all contents with "Ctrl+a" or "Command+a"
// Ctrl+a or Command+a
const key = event.keyCode || event.which;
const mod = event.metaKey || event.ctrlKey;
if (mod && key === 65 && !isInputTarget(event)) {
event.preventDefault();
this.props.actions.selectAll();
}
});
}
componentDidMount() {
document.addEventListener('cut', this.props.actions.cutEntities);
Expand Down Expand Up @@ -138,6 +150,7 @@ App.propTypes = {
popups: PropTypes.objectOf(PropTypes.bool),
popupsData: PropTypes.objectOf(PropTypes.object),
actions: PropTypes.shape({
selectAll: PropTypes.func.isRequired,
updateCompileLimit: PropTypes.func.isRequired,
createProject: PropTypes.func.isRequired,
updateProjectMeta: PropTypes.func.isRequired,
Expand Down

0 comments on commit e4f7076

Please sign in to comment.