Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Focus on label editor in Inspector when double-clicking terminal or bus nodes #2063

Merged
merged 2 commits into from
Nov 3, 2020
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
17 changes: 10 additions & 7 deletions packages/xod-client/src/core/domSideeffectsMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import waitForElement from 'wait-for-element';
import { FOCUS_BOUND_VALUE } from '../editor/actionTypes';
import { FOCUS_BOUND_VALUE, FOCUS_LABEL } from '../editor/actionTypes';

const CONTROL_SELECTORS = {
// Select widget control with a tricky selector instead of ID, because
// some constant nodes has a generated id of the terminal Node
[FOCUS_BOUND_VALUE]: '.PinWidget input, .PinWidget select',
[FOCUS_LABEL]: '#widget_label',
};

export default _ => next => action => {
if (action.type === FOCUS_BOUND_VALUE) {
if (Object.prototype.hasOwnProperty.call(CONTROL_SELECTORS, action.type)) {
// First of all, do the stuff in reducers to show inspector pane.
const n = next(action);
// Wait for updated Inspector, because it could appeared
// or it changed entirely on new selection
waitForElement('.Inspector-container')
.then(__ => {
// Select widget control with a tricky selector instead of ID, because
// some constant nodes has a generated id of the terminal Node
const ctrl = document.querySelector(
'.PinWidget input, .PinWidget select'
);
const ctrl = document.querySelector(CONTROL_SELECTORS[action.type]);
if (!ctrl) return;
if (ctrl.setSelectionRange)
ctrl.setSelectionRange(0, ctrl.value.length);
Expand Down
1 change: 1 addition & 0 deletions packages/xod-client/src/editor/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const MOVE_PANEL = 'MOVE_PANEL';
export const TOGGLE_PANEL_AUTOHIDE = 'TOGGLE_PANEL_AUTOHIDE';

export const FOCUS_BOUND_VALUE = 'FOCUS_BOUND_VALUE';
export const FOCUS_LABEL = 'FOCUS_LABEL';

export const TABTEST_RUN_REQUESTED = 'TABTEST_RUN_REQUESTED';
export const TABTEST_GENERATED_CPP = 'TABTEST_GENERATED_CPP';
Expand Down
8 changes: 8 additions & 0 deletions packages/xod-client/src/editor/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,14 @@ export const focusBoundValue = (nodeId, patchPath) => ({
},
});

export const focusLabel = (nodeId, patchPath) => ({
type: ActionType.FOCUS_LABEL,
payload: {
nodeId,
patchPath,
},
});

export const abortTabtest = () => (dispatch, getState) => {
const worker = Selectors.tabtestWorker(getState());
if (worker) worker.terminate();
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 @@ -378,6 +378,7 @@ const mapDispatchToProps = dispatch => ({
splitLinksToBuses: EditorActions.splitLinksToBuses,
addBusNode: ProjectActions.addBusNode,
focusBoundValue: EditorActions.focusBoundValue,
focusLabel: EditorActions.focusLabel,
},
dispatch
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ import { bindApi, getOffsetMatrix } from '../modeUtils';

const debuggingMode = R.merge(selectingMode, {
onNodeDoubleClick(api, nodeId, patchPath) {
if (patchPath === XP.NOT_IMPLEMENTED_IN_XOD_PATH) {
api.props.actions.openImplementationEditor();
} else if (XP.isConstantNodeType(patchPath) || XP.isTweakPath(patchPath)) {
if (R.contains(patchPath, R.keys(XP.MANAGED_ATTACHMENT_FILENAMES))) {
api.props.actions.openAttachmentEditor(patchPath);
} else if (
XP.isConstantNodeType(patchPath) ||
XP.isTweakPath(patchPath) ||
XP.isBindableCustomType(patchPath)
) {
api.props.actions.focusBoundValue(nodeId, api.props.patchPath);
} else if (
XP.isBusPatchPath(patchPath) ||
XP.isTerminalPatchPath(patchPath)
) {
api.props.actions.focusLabel(nodeId, api.props.patchPath);
} else {
api.props.actions.drillDown(patchPath, nodeId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ const selectingMode = {
XP.isBindableCustomType(patchPath)
) {
api.props.actions.focusBoundValue(nodeId, api.props.patchPath);
} else if (
XP.isBusPatchPath(patchPath) ||
XP.isTerminalPatchPath(patchPath)
) {
api.props.actions.focusLabel(nodeId, api.props.patchPath);
} else {
api.props.actions.switchPatch(patchPath);
}
Expand Down
1 change: 1 addition & 0 deletions packages/xod-client/src/editor/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ const editorReducer = (state = initialState, action) => {
);

case EAT.FOCUS_BOUND_VALUE:
case EAT.FOCUS_LABEL:
// maximize Inspector panel to focus & select widget's input
return R.assocPath(
['panels', PANEL_IDS.INSPECTOR, 'maximized'],
Expand Down