Skip to content

Commit

Permalink
fix(xod-client, xod-client-electron): make "Select all" menu item sel…
Browse files Browse the repository at this point in the history
…ects all entities on the Patch or all in the input if it focused
  • Loading branch information
brusherru committed Oct 29, 2018
1 parent 360c4ba commit b4bbb91
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
14 changes: 13 additions & 1 deletion packages/xod-client-electron/src/view/containers/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,19 @@ class App extends client.App {
items.cut,
items.copy,
items.paste,
items.selectall,
onClick(items.selectall, () => {
// We can't use `role: 'selectall'` here, cause it ignores `onClick`.
// So we have to handle all cases manually:

// - select all in inputs
if (client.isInput(document.activeElement)) {
document.activeElement.select();
return;
}

// - select entities on Patch
this.props.actions.selectAll();
}),
items.separator,
onClick(items.insertNode, () => this.props.actions.showSuggester(null)),
onClick(items.insertComment, this.props.actions.addComment),
Expand Down
2 changes: 2 additions & 0 deletions packages/xod-client/src/core/containers/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import PopupProjectPreferences from '../../project/components/PopupProjectPrefer
import PopupPublishProject from '../../project/components/PopupPublishProject';

import * as actions from '../actions';
import { selectAll } from '../../editor/actions';
import { NO_PATCH_TO_TRANSPILE } from '../../editor/messages';

import formatErrorMessage from '../formatErrorMessage';
Expand Down Expand Up @@ -177,6 +178,7 @@ App.propTypes = {
};

App.actions = {
selectAll,
updateCompileLimit: actions.updateCompileLimit,
createProject: actions.createProject,
requestPublishProject: actions.requestPublishProject,
Expand Down
10 changes: 10 additions & 0 deletions packages/xod-client/src/editor/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ export const setEditorSelection = entities => ({
payload: { entities },
});

export const selectAll = () => (dispatch, getState) => {
const state = getState();
const selection = {
nodes: R.values(ProjectSelectors.getCurrentPatchNodes(state)),
links: R.values(ProjectSelectors.getCurrentPatchLinks(state)),
comments: R.values(ProjectSelectors.getCurrentPatchComments(state)),
};
return dispatch(setEditorSelection(selection));
};

export const addAndSelectNode = (
typeId,
position,
Expand Down
1 change: 1 addition & 0 deletions packages/xod-client/src/editor/containers/Patch/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ const mapDispatchToProps = dispatch => ({
resizeNode: ProjectActions.resizeNode,
deselectAll: EditorActions.deselectAll,
deleteSelection: EditorActions.deleteSelection,
selectAll: EditorActions.selectAll,
selectLink: EditorActions.selectLink,
selectNode: EditorActions.selectNode,
selectComment: EditorActions.selectComment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,8 @@ const selectingMode = {
},
onSelectAll({ props }, event) {
if (isInputTarget(event)) return;

event.preventDefault();

props.actions.setSelection(
R.compose(R.map(R.values), R.pick(['nodes', 'links', 'comments']))(props)
);
props.actions.selectAll();
},
onBackgroundClick(api, event) {
// to prevent misclicks when selecting multiple entities
Expand Down
1 change: 0 additions & 1 deletion packages/xod-client/src/utils/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ const rawItems = {
selectall: {
label: 'Select All',
command: COMMAND.SELECT_ALL,
role: 'selectall',
},
projectPreferences: {
label: 'Project Preferences',
Expand Down

0 comments on commit b4bbb91

Please sign in to comment.