From 73f38064ccc4d4ab650274a7f5230d27e5e808be Mon Sep 17 00:00:00 2001 From: Jess Date: Thu, 12 May 2016 13:06:18 -0400 Subject: [PATCH 1/2] added delete + backspace to remove selection hotkey list and prevent default so browser doesn't navigate back --- app/actions.js | 3 ++- app/components/Root.jsx | 4 ++-- app/components/__tests__/Edge-test.jsx | 10 ++++++++++ app/components/__tests__/Node-test.jsx | 12 ++++++++++++ app/main.jsx | 4 ++-- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/app/actions.js b/app/actions.js index e5e7e20..c2a1ef8 100644 --- a/app/actions.js +++ b/app/actions.js @@ -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 }; } diff --git a/app/components/Root.jsx b/app/components/Root.jsx index 704f9d3..bd4aef6 100644 --- a/app/components/Root.jsx +++ b/app/components/Root.jsx @@ -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 = { @@ -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 = { diff --git a/app/components/__tests__/Edge-test.jsx b/app/components/__tests__/Edge-test.jsx index 8ff6768..709f7c7 100644 --- a/app/components/__tests__/Edge-test.jsx +++ b/app/components/__tests__/Edge-test.jsx @@ -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( + + ); + let element = ReactDOM.findDOMNode(edge); + TestUtils.Simulate.keyDown(element, {key: "Delete", keyCode: 46, which: 46}); + expect(deleteEdge.mock.calls[0]).toBeUndefined(); + }); }); \ No newline at end of file diff --git a/app/components/__tests__/Node-test.jsx b/app/components/__tests__/Node-test.jsx index 3d3f84e..be3179e 100644 --- a/app/components/__tests__/Node-test.jsx +++ b/app/components/__tests__/Node-test.jsx @@ -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", () => { @@ -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( + + ); + let element = wrapper.find("g.node"); + TestUtils.Simulate.keyDown(element, {key: "Delete", keyCode: 46, which: 46}); + expect(deleteNode.mock.calls[0]).toBeUndefined(); + }); }); \ No newline at end of file diff --git a/app/main.jsx b/app/main.jsx index bd40316..98fa5dd 100644 --- a/app/main.jsx +++ b/app/main.jsx @@ -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) { From aa663d071ed27b4479a12f9d7ab03a3afb087ebd Mon Sep 17 00:00:00 2001 From: Matthew Skomarovsky Date: Thu, 12 May 2016 19:58:29 -0400 Subject: [PATCH 2/2] small change to delete key handling --- app/actions.js | 3 +-- app/components/Root.jsx | 5 ++++- app/components/__tests__/Edge-test.jsx | 10 ---------- app/components/__tests__/Node-test.jsx | 10 ---------- app/main.jsx | 4 ++-- 5 files changed, 7 insertions(+), 25 deletions(-) diff --git a/app/actions.js b/app/actions.js index c2a1ef8..e5e7e20 100644 --- a/app/actions.js +++ b/app/actions.js @@ -156,8 +156,7 @@ export function deleteCaption(captionId) { return { type: DELETE_CAPTION, captionId }; } -export function deleteSelection(event, selection) { - event.preventDefault(); +export function deleteSelection(selection) { return { type: DELETE_SELECTION, selection }; } diff --git a/app/components/Root.jsx b/app/components/Root.jsx index bd4aef6..2c22d71 100644 --- a/app/components/Root.jsx +++ b/app/components/Root.jsx @@ -73,7 +73,10 @@ class Root extends Component { 'resetZoom': () => dispatch(resetZoom()), 'shiftDown': () => this.setState({ shiftKey: true }), 'shiftUp': () => this.setState({ shiftKey: false }), - 'delete': (event) => dispatch(deleteSelection(event, selection)) + 'delete': (event) => { + event.preventDefault(); + dispatch(deleteSelection(selection)); + } }; let graphApi = { diff --git a/app/components/__tests__/Edge-test.jsx b/app/components/__tests__/Edge-test.jsx index 709f7c7..8ff6768 100644 --- a/app/components/__tests__/Edge-test.jsx +++ b/app/components/__tests__/Edge-test.jsx @@ -72,14 +72,4 @@ 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( - - ); - let element = ReactDOM.findDOMNode(edge); - TestUtils.Simulate.keyDown(element, {key: "Delete", keyCode: 46, which: 46}); - expect(deleteEdge.mock.calls[0]).toBeUndefined(); - }); }); \ No newline at end of file diff --git a/app/components/__tests__/Node-test.jsx b/app/components/__tests__/Node-test.jsx index be3179e..429e278 100644 --- a/app/components/__tests__/Node-test.jsx +++ b/app/components/__tests__/Node-test.jsx @@ -81,14 +81,4 @@ 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( - - ); - let element = wrapper.find("g.node"); - TestUtils.Simulate.keyDown(element, {key: "Delete", keyCode: 46, which: 46}); - expect(deleteNode.mock.calls[0]).toBeUndefined(); - }); }); \ No newline at end of file diff --git a/app/main.jsx b/app/main.jsx index 98fa5dd..bd40316 100644 --- a/app/main.jsx +++ b/app/main.jsx @@ -201,8 +201,8 @@ class Oligrapher { this.root.dispatchProps.dispatch(deselectAll()); } - deleteSelection(event) { - this.root.dispatchProps.dispatch(deleteSelection(event, this.getSelection())); + deleteSelection() { + this.root.dispatchProps.dispatch(deleteSelection(this.getSelection())); } updateNode(nodeId, data) {