Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee155c7

Browse files
committed
Prevent repeat events
1 parent c9fe71c commit ee155c7

File tree

1 file changed

+12
-0
lines changed
  • lib/matplotlib/backends/web_backend

1 file changed

+12
-0
lines changed

lib/matplotlib/backends/web_backend/mpl.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ mpl.figure = function(figure_id, websocket, ondownload, parent_element) {
8080
this.ws.onmessage = this._make_on_message_function(this);
8181

8282
this.ondownload = ondownload;
83+
84+
this._key = null;
8385
}
8486

8587
mpl.figure.prototype._init_header = function() {
@@ -463,6 +465,16 @@ mpl.figure.prototype.mouse_event = function(event, name) {
463465
}
464466

465467
mpl.figure.prototype.key_event = function(event, name) {
468+
// prevent repeat events
469+
if (name == 'key_press')
470+
if (event.keyCode === this._key) {
471+
return;
472+
} else {
473+
this._key = event.keyCode;
474+
}
475+
}
476+
if (name == 'key_release')
477+
this._key = null;
466478

467479
var value = '';
468480
if (event.ctrlKey && event.keyCode != 17) {

0 commit comments

Comments
 (0)