Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
Add an onCmdCtrlKey prop to the ObjectInspector.
Browse files Browse the repository at this point in the history
This will be called with the item an data about it when
the user Ctrl + Click (Cmd on OSX) on a node.
This will be useful in the console in order to have a shortcut
to put objects in the sidebar.
  • Loading branch information
nchevobbe committed Apr 19, 2018
1 parent 7fadbbd commit bc9bd6f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/devtools-reps/src/launchpad/components/Result.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ class Result extends Component {
createLongStringClient,
releaseActor,
mode: MODE[modeKey],
onInspectIconClick: nodeFront => console.log("inspectIcon click", nodeFront),
disableFocus: false,
// The following properties are optional function props called by the
// objectInspector on some occasions. Here we pass dull functions that only
// logs the parameters with which the callback was called.
onCmdCtrlClick: (node, { depth, event, focused, expanded }) =>
console.log("CmdCtrlClick", {node, depth, event, focused, expanded}),
onInspectIconClick: nodeFront => console.log("inspectIcon click", {nodeFront}),
onViewSourceInDebugger: location =>
console.log("onViewSourceInDebugger", {location}),
disableFocus: false,
})
);
}
Expand Down
12 changes: 12 additions & 0 deletions packages/devtools-reps/src/object-inspector/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ class ObjectInspector extends Component {
expanded: boolean
) : Object {
const {
onCmdCtrlClick,
onDoubleClick,
dimTopLevelWindow,
} = this.props;
Expand All @@ -409,6 +410,17 @@ class ObjectInspector extends Component {
block: nodeIsBlock(item)
}),
onClick: e => {
if (e.metaKey && onCmdCtrlClick) {
onCmdCtrlClick(item, {
depth,
event: e,
focused,
expanded,
});
e.stopPropagation();
return;
}

// If this click happened because the user selected some text, bail out.
// Note that if the user selected some text before and then clicks here,
// the previously selected text will be first unselected, unless the user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ describe("ObjectInspector - properties", () => {
expect(onDoubleClick.mock.calls.length).toBe(1);
});

it("calls the onCmdCtrlClick prop function when provided and cmd/ctrl-clicked", () => {
const stub = gripRepStubs.get("testMaxProps");
const onCmdCtrlClick = jest.fn();

const oi = mount(ObjectInspector(generateDefaults({
roots: [{
path: "root",
contents: {
value: stub
}
}],
onCmdCtrlClick,
})));

const node = oi.find(".node").first();
node.simulate("click", { metaKey: true });

expect(onCmdCtrlClick.mock.calls.length).toBe(1);
});

it("calls the onLabel prop function when provided one and label clicked", () => {
const stub = gripRepStubs.get("testMaxProps");
const onLabelClick = jest.fn();
Expand Down
9 changes: 9 additions & 0 deletions packages/devtools-reps/src/object-inspector/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ export type Props = {
expanded: boolean
}
) => any,
onCmdCtrlClick: ?(
item: Node,
options: {
depth: number,
event: SyntheticEvent,
focused: boolean,
expanded: boolean
}
) => any,
onLabelClick: ?(
item: Node,
options: {
Expand Down

0 comments on commit bc9bd6f

Please sign in to comment.