Skip to content

Commit 7901d80

Browse files
committed
Perform actions on key press, not key release
Also, prevent default only for not recognized keyboard keys
1 parent 8655f2f commit 7901d80

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Graph.js

Lines changed: 6 additions & 3 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,12 +250,11 @@ 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();
@@ -285,6 +284,10 @@ class Graph extends React.Component {
285284
else if (event.key === '?') {
286285
this.props.onHelp();
287286
}
287+
else {
288+
return;
289+
}
290+
event.preventDefault();
288291
this.isDrawingEdge = false;
289292
}
290293

0 commit comments

Comments
 (0)