Skip to content

Commit

Permalink
added delete + backspace to remove selection hotkey list and prevent …
Browse files Browse the repository at this point in the history
…default so browser doesn't navigate back
  • Loading branch information
jessp committed May 12, 2016
1 parent 0775d58 commit 73f3806
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ export function deleteCaption(captionId) {
return { type: DELETE_CAPTION, captionId };
}

export function deleteSelection(selection) {
export function deleteSelection(event, selection) {
event.preventDefault();
return { type: DELETE_SELECTION, selection };
}

Expand Down
4 changes: 2 additions & 2 deletions app/components/Root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Root extends Component {
'resetZoom': 'ctrl+0',
'shiftDown': { sequence: 'shift', action: 'keydown' },
'shiftUp': { sequence: 'shift', action: 'keyup' },
'delete': ['alt+d', 'ctrl+d', 'command+d']
'delete': ['alt+d', 'ctrl+d', 'command+d', 'del', 'backspace']
};

const keyHandlers = {
Expand All @@ -73,7 +73,7 @@ class Root extends Component {
'resetZoom': () => dispatch(resetZoom()),
'shiftDown': () => this.setState({ shiftKey: true }),
'shiftUp': () => this.setState({ shiftKey: false }),
'delete': () => dispatch(deleteSelection(selection))
'delete': (event) => dispatch(deleteSelection(event, selection))
};

let graphApi = {
Expand Down
10 changes: 10 additions & 0 deletions app/components/__tests__/Edge-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,14 @@ describe("Edge Component", () => {
TestUtils.Simulate.click(select);
expect(clickEdge.mock.calls[0][0]).toBe(data.id);
});

it("should be removed when delete hotkey is pressed", () => {
let deleteEdge = jest.genMockFunction();
let edge = TestUtils.renderIntoDocument(
<Edge edge={data} graphId="someid" clickEdge={deleteEdge} />
);
let element = ReactDOM.findDOMNode(edge);
TestUtils.Simulate.keyDown(element, {key: "Delete", keyCode: 46, which: 46});
expect(deleteEdge.mock.calls[0]).toBeUndefined();
});
});
12 changes: 12 additions & 0 deletions app/components/__tests__/Node-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { shallow } from "enzyme";
import Node from '../Node';
import NodeCircle from "../NodeCircle";
import NodeLabel from "../NodeLabel";
import TestUtils from 'react-addons-test-utils';


describe("Node Component", () => {

Expand Down Expand Up @@ -79,4 +81,14 @@ describe("Node Component", () => {

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

it("should be removed when delete hotkey is pressed", () => {
let deleteNode = jest.genMockFunction();
let wrapper = shallow(
<Node node={data} graph={{id: "someid"}} clickNode={deleteNode} />
);
let element = wrapper.find("g.node");
TestUtils.Simulate.keyDown(element, {key: "Delete", keyCode: 46, which: 46});
expect(deleteNode.mock.calls[0]).toBeUndefined();
});
});
4 changes: 2 additions & 2 deletions app/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ class Oligrapher {
this.root.dispatchProps.dispatch(deselectAll());
}

deleteSelection() {
this.root.dispatchProps.dispatch(deleteSelection(this.getSelection()));
deleteSelection(event) {
this.root.dispatchProps.dispatch(deleteSelection(event, this.getSelection()));
}

updateNode(nodeId, data) {
Expand Down

0 comments on commit 73f3806

Please sign in to comment.