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