Skip to content

Commit 1ba7284

Browse files
authored
Merge pull request #17 from magjac/select-all
Select all
2 parents 7e615a1 + c490863 commit 1ba7284

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/Graph.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class Graph extends React.Component {
229229

230230
d3_select(window).on("resize", this.resizeSVG.bind(this));
231231
this.div.on("click", this.handleClickDiv.bind(this));
232-
d3_select(document).on("keyup", this.handleKeyUpDocument.bind(this));
232+
d3_select(document).on("keydown", this.handleKeyDownDocument.bind(this));
233233
this.div.on("mousemove", this.handleMouseMoveDiv.bind(this));
234234
this.div.on("contextmenu", this.handleRightClickDiv.bind(this));
235235
this.svg.on("mousedown", this.handleMouseDownSvg.bind(this));
@@ -250,41 +250,52 @@ class Graph extends React.Component {
250250
this.unSelectComponents();
251251
}
252252

253-
handleKeyUpDocument(d, i, nodes) {
253+
handleKeyDownDocument(d, i, nodes) {
254254
var event = d3_event;
255255
if (event.target.nodeName !== 'BODY') {
256256
return;
257257
}
258-
event.preventDefault();
259258
if (event.key === 'Escape') {
260259
this.graphviz.removeDrawnEdge();
261260
this.unSelectComponents();
262261
}
263-
if (event.key === 'Delete') {
262+
else if (event.key === 'Delete') {
264263
this.deleteSelectedComponents.call(this);
265264
this.graphviz.removeDrawnEdge();
266265
}
267-
if (event.ctrlKey && event.key === 'c') {
266+
else if (event.ctrlKey && event.key === 'c') {
268267
let nodes = this.selectedComponents.filter('.node');
269268
if (nodes.size() > 0) {
270269
let nodeName = nodes.selectWithoutDataPropagation("title").text();
271270
this.latestNodeAttributes = this.dotGraph.getNodeAttributes(nodeName);
272271
}
273272
}
274-
if (event.ctrlKey && event.key === 'v') {
273+
else if (event.ctrlKey && event.key === 'v') {
275274
this.insertNodeWithLatestAttributes();
276275
}
277-
if (event.ctrlKey && event.key === 'x') {
276+
else if (event.ctrlKey && event.key === 'x') {
278277
let nodes = this.selectedComponents.filter('.node');
279278
if (nodes.size() > 0) {
280279
let nodeName = nodes.selectWithoutDataPropagation("title").text();
281280
this.latestNodeAttributes = this.dotGraph.getNodeAttributes(nodeName);
282281
}
283282
this.deleteSelectedComponents.call(this);
284283
}
285-
if (event.key === '?') {
284+
else if (event.key === 'a') {
285+
let components = this.graph0.selectAll('.node,.edge');
286+
this.selectComponents(components);
287+
}
288+
else if (event.key === 'A') {
289+
let components = this.graph0.selectAll('.edge');
290+
this.selectComponents(components);
291+
}
292+
else if (event.key === '?') {
286293
this.props.onHelp();
287294
}
295+
else {
296+
return;
297+
}
298+
event.preventDefault();
288299
this.isDrawingEdge = false;
289300
}
290301

src/KeyboardShortcutsDialog.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import TableRow from '@material-ui/core/TableRow';
1414
import CloseIcon from '@material-ui/icons/Close';
1515

1616
const keyboardShortcuts = [
17+
{key: 'Ctrl-A', description: 'Select all nodes and edges.'},
18+
{key: 'Ctrl-Shift-A', description: 'Select all edges.'},
1719
{key: 'Ctrl-C', description: 'Copy the selected node.'},
1820
{key: 'Ctrl-V', description: 'Paste the cut/copied node.'},
1921
{key: 'Ctrl-X', description: 'Cut the selected node.'},

0 commit comments

Comments
 (0)