##// END OF EJS Templates
Misc work on shortcuts:...
Brian E. Granger -
Show More
@@ -276,9 +276,17 b' var IPython = (function (IPython) {'
276 276 return false;
277 277 }
278 278 },
279 'shift+v' : {
280 help : 'paste cell above',
281 help_index : 'eg',
282 handler : function (event) {
283 IPython.notebook.paste_cell_above();
284 return false;
285 }
286 },
279 287 'v' : {
280 288 help : 'paste cell below',
281 help_index : 'eg',
289 help_index : 'eh',
282 290 handler : function (event) {
283 291 IPython.notebook.paste_cell_below();
284 292 return false;
@@ -286,18 +294,10 b' var IPython = (function (IPython) {'
286 294 },
287 295 'd' : {
288 296 help : 'delete cell (press twice)',
289 help_index : 'ei',
297 help_index : 'ej',
298 count: 2,
290 299 handler : function (event) {
291 var dc = IPython.keyboard_manager._delete_count;
292 if (dc === 0) {
293 IPython.keyboard_manager._delete_count = 1;
294 setTimeout(function () {
295 IPython.keyboard_manager._delete_count = 0;
296 }, 800);
297 } else if (dc === 1) {
298 IPython.notebook.delete_cell();
299 IPython.keyboard_manager._delete_count = 0;
300 }
300 IPython.notebook.delete_cell();
301 301 return false;
302 302 }
303 303 },
@@ -337,7 +337,7 b' var IPython = (function (IPython) {'
337 337 return false;
338 338 }
339 339 },
340 't' : {
340 'r' : {
341 341 help : 'to raw',
342 342 help_index : 'cc',
343 343 handler : function (event) {
@@ -442,16 +442,18 b' var IPython = (function (IPython) {'
442 442 }
443 443 },
444 444 'i' : {
445 help : 'interrupt kernel',
445 help : 'interrupt kernel (press twice)',
446 446 help_index : 'ha',
447 count: 2,
447 448 handler : function (event) {
448 449 IPython.notebook.kernel.interrupt();
449 450 return false;
450 451 }
451 452 },
452 '.' : {
453 help : 'restart kernel',
453 '0' : {
454 help : 'restart kernel (press twice)',
454 455 help_index : 'hb',
456 count: 2,
455 457 handler : function (event) {
456 458 IPython.notebook.restart_kernel();
457 459 return false;
@@ -467,7 +469,7 b' var IPython = (function (IPython) {'
467 469 },
468 470 'z' : {
469 471 help : 'undo last delete',
470 help_index : 'eh',
472 help_index : 'ei',
471 473 handler : function (event) {
472 474 IPython.notebook.undelete_cell();
473 475 return false;
@@ -475,7 +477,7 b' var IPython = (function (IPython) {'
475 477 },
476 478 'shift+=' : {
477 479 help : 'merge cell below',
478 help_index : 'ej',
480 help_index : 'ek',
479 481 handler : function (event) {
480 482 IPython.notebook.merge_cell_below();
481 483 return false;
@@ -486,8 +488,10 b' var IPython = (function (IPython) {'
486 488
487 489 // Shortcut manager class
488 490
489 var ShortcutManager = function () {
491 var ShortcutManager = function (delay) {
490 492 this._shortcuts = {}
493 this._counts = {}
494 this.delay = delay || 800; // delay in milliseconds
491 495 }
492 496
493 497 ShortcutManager.prototype.help = function () {
@@ -552,10 +556,12 b' var IPython = (function (IPython) {'
552 556 }
553 557 data.help_index = data.help_index || '';
554 558 data.help = data.help || '';
559 data.count = data.count || 1;
555 560 if (data.help_index === '') {
556 561 data.help_index = 'zz';
557 562 }
558 563 shortcut = this.normalize_shortcut(shortcut);
564 this._counts[shortcut] = 0;
559 565 this._shortcuts[shortcut] = data;
560 566 }
561 567
@@ -567,16 +573,37 b' var IPython = (function (IPython) {'
567 573
568 574 ShortcutManager.prototype.remove_shortcut = function (shortcut) {
569 575 shortcut = this.normalize_shortcut(shortcut);
576 delete this._counts[shortcut];
570 577 delete this._shortcuts[shortcut];
571 578 }
572 579
580 ShortcutManager.prototype.count_handler = function (shortcut, event, handler) {
581 var that = this;
582 var c = this._counts;
583 if (c[shortcut] === 0) {
584 c[shortcut] = 1;
585 setTimeout(function () {
586 c[shortcut] = 0;
587 }, that.delay);
588 } else if (c[shortcut] === 1) {
589 c[shortcut] = 0;
590 return handler(event);
591 }
592 return false;
593
594 }
595
573 596 ShortcutManager.prototype.call_handler = function (event) {
574 597 var shortcut = this.event_to_shortcut(event);
575 598 var data = this._shortcuts[shortcut];
576 if (data !== undefined) {
599 if (data) {
577 600 var handler = data['handler'];
578 if (handler !== undefined) {
579 return handler(event);
601 if (handler) {
602 if (data.count === 1) {
603 return handler(event);
604 } else if (data.count > 1) {
605 return this.count_handler(shortcut, event, handler);
606 }
580 607 }
581 608 }
582 609 return true;
@@ -589,7 +616,6 b' var IPython = (function (IPython) {'
589 616 var KeyboardManager = function () {
590 617 this.mode = 'command';
591 618 this.enabled = true;
592 this._delete_count = 0;
593 619 this.bind_events();
594 620 this.command_shortcuts = new ShortcutManager();
595 621 this.command_shortcuts.add_shortcuts(default_common_shortcuts);
General Comments 0
You need to be logged in to leave comments. Login now