Show More
@@ -42,12 +42,12 var IPython = (function (IPython) { | |||||
42 | // These apply to Firefox and Opera |
|
42 | // These apply to Firefox and Opera | |
43 | var _mozilla_keycodes = { |
|
43 | var _mozilla_keycodes = { | |
44 | '; :': 59, '= +': 61, '- _': 173, 'meta': 224 |
|
44 | '; :': 59, '= +': 61, '- _': 173, 'meta': 224 | |
45 | } |
|
45 | }; | |
46 |
|
46 | |||
47 | // This apply to Webkit and IE |
|
47 | // This apply to Webkit and IE | |
48 | var _ie_keycodes = { |
|
48 | var _ie_keycodes = { | |
49 | '; :': 186, '= +': 187, '- _': 189, |
|
49 | '; :': 186, '= +': 187, '- _': 189, | |
50 | } |
|
50 | }; | |
51 |
|
51 | |||
52 | var browser = IPython.utils.browser[0]; |
|
52 | var browser = IPython.utils.browser[0]; | |
53 | var platform = IPython.utils.platform; |
|
53 | var platform = IPython.utils.platform; | |
@@ -63,15 +63,15 var IPython = (function (IPython) { | |||||
63 | for (var name in _keycodes) { |
|
63 | for (var name in _keycodes) { | |
64 | var names = name.split(' '); |
|
64 | var names = name.split(' '); | |
65 | if (names.length === 1) { |
|
65 | if (names.length === 1) { | |
66 | var n = names[0] |
|
66 | var n = names[0]; | |
67 | keycodes[n] = _keycodes[n] |
|
67 | keycodes[n] = _keycodes[n]; | |
68 | inv_keycodes[_keycodes[n]] = n |
|
68 | inv_keycodes[_keycodes[n]] = n; | |
69 | } else { |
|
69 | } else { | |
70 | var primary = names[0]; |
|
70 | var primary = names[0]; | |
71 | var secondary = names[1]; |
|
71 | var secondary = names[1]; | |
72 | keycodes[primary] = _keycodes[name] |
|
72 | keycodes[primary] = _keycodes[name]; | |
73 | keycodes[secondary] = _keycodes[name] |
|
73 | keycodes[secondary] = _keycodes[name]; | |
74 | inv_keycodes[_keycodes[name]] = primary |
|
74 | inv_keycodes[_keycodes[name]] = primary; | |
75 | } |
|
75 | } | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
@@ -111,7 +111,7 var IPython = (function (IPython) { | |||||
111 | return false; |
|
111 | return false; | |
112 | } |
|
112 | } | |
113 | } |
|
113 | } | |
114 | } |
|
114 | }; | |
115 |
|
115 | |||
116 | if (platform === 'MacOS') { |
|
116 | if (platform === 'MacOS') { | |
117 | default_common_shortcuts['cmd+s'] = |
|
117 | default_common_shortcuts['cmd+s'] = | |
@@ -165,11 +165,11 var IPython = (function (IPython) { | |||||
165 | var cell = IPython.notebook.get_selected_cell(); |
|
165 | var cell = IPython.notebook.get_selected_cell(); | |
166 | if (cell && cell.at_top()) { |
|
166 | if (cell && cell.at_top()) { | |
167 | event.preventDefault(); |
|
167 | event.preventDefault(); | |
168 | IPython.notebook.command_mode() |
|
168 | IPython.notebook.command_mode(); | |
169 | IPython.notebook.select_prev(); |
|
169 | IPython.notebook.select_prev(); | |
170 | IPython.notebook.edit_mode(); |
|
170 | IPython.notebook.edit_mode(); | |
171 | return false; |
|
171 | return false; | |
172 |
} |
|
172 | } | |
173 | } |
|
173 | } | |
174 | }, |
|
174 | }, | |
175 | 'down' : { |
|
175 | 'down' : { | |
@@ -179,11 +179,11 var IPython = (function (IPython) { | |||||
179 | var cell = IPython.notebook.get_selected_cell(); |
|
179 | var cell = IPython.notebook.get_selected_cell(); | |
180 | if (cell && cell.at_bottom()) { |
|
180 | if (cell && cell.at_bottom()) { | |
181 | event.preventDefault(); |
|
181 | event.preventDefault(); | |
182 | IPython.notebook.command_mode() |
|
182 | IPython.notebook.command_mode(); | |
183 | IPython.notebook.select_next(); |
|
183 | IPython.notebook.select_next(); | |
184 | IPython.notebook.edit_mode(); |
|
184 | IPython.notebook.edit_mode(); | |
185 | return false; |
|
185 | return false; | |
186 |
} |
|
186 | } | |
187 | } |
|
187 | } | |
188 | }, |
|
188 | }, | |
189 | 'alt+-' : { |
|
189 | 'alt+-' : { | |
@@ -210,7 +210,7 var IPython = (function (IPython) { | |||||
210 | help : 'tooltip', |
|
210 | help : 'tooltip', | |
211 | help_index : 'ed', |
|
211 | help_index : 'ed', | |
212 | }, |
|
212 | }, | |
213 | } |
|
213 | }; | |
214 |
|
214 | |||
215 | if (platform === 'MacOS') { |
|
215 | if (platform === 'MacOS') { | |
216 | default_edit_shortcuts['cmd+/'] = |
|
216 | default_edit_shortcuts['cmd+/'] = | |
@@ -266,7 +266,7 var IPython = (function (IPython) { | |||||
266 | IPython.notebook.select_prev(); |
|
266 | IPython.notebook.select_prev(); | |
267 | var cell = IPython.notebook.get_selected_cell(); |
|
267 | var cell = IPython.notebook.get_selected_cell(); | |
268 | cell.focus_cell(); |
|
268 | cell.focus_cell(); | |
269 |
} |
|
269 | } | |
270 | return false; |
|
270 | return false; | |
271 | } |
|
271 | } | |
272 | }, |
|
272 | }, | |
@@ -279,7 +279,7 var IPython = (function (IPython) { | |||||
279 | IPython.notebook.select_next(); |
|
279 | IPython.notebook.select_next(); | |
280 | var cell = IPython.notebook.get_selected_cell(); |
|
280 | var cell = IPython.notebook.get_selected_cell(); | |
281 | cell.focus_cell(); |
|
281 | cell.focus_cell(); | |
282 |
} |
|
282 | } | |
283 | return false; |
|
283 | return false; | |
284 | } |
|
284 | } | |
285 | }, |
|
285 | }, | |
@@ -292,7 +292,7 var IPython = (function (IPython) { | |||||
292 | IPython.notebook.select_prev(); |
|
292 | IPython.notebook.select_prev(); | |
293 | var cell = IPython.notebook.get_selected_cell(); |
|
293 | var cell = IPython.notebook.get_selected_cell(); | |
294 | cell.focus_cell(); |
|
294 | cell.focus_cell(); | |
295 |
} |
|
295 | } | |
296 | return false; |
|
296 | return false; | |
297 | } |
|
297 | } | |
298 | }, |
|
298 | }, | |
@@ -305,7 +305,7 var IPython = (function (IPython) { | |||||
305 | IPython.notebook.select_next(); |
|
305 | IPython.notebook.select_next(); | |
306 | var cell = IPython.notebook.get_selected_cell(); |
|
306 | var cell = IPython.notebook.get_selected_cell(); | |
307 | cell.focus_cell(); |
|
307 | cell.focus_cell(); | |
308 |
} |
|
308 | } | |
309 | return false; |
|
309 | return false; | |
310 | } |
|
310 | } | |
311 | }, |
|
311 | }, | |
@@ -540,23 +540,23 var IPython = (function (IPython) { | |||||
540 | return false; |
|
540 | return false; | |
541 | } |
|
541 | } | |
542 | }, |
|
542 | }, | |
543 | } |
|
543 | }; | |
544 |
|
544 | |||
545 |
|
545 | |||
546 | // Shortcut manager class |
|
546 | // Shortcut manager class | |
547 |
|
547 | |||
548 | var ShortcutManager = function (delay) { |
|
548 | var ShortcutManager = function (delay) { | |
549 | this._shortcuts = {} |
|
549 | this._shortcuts = {}; | |
550 | this._counts = {} |
|
550 | this._counts = {}; | |
551 | this._timers = {} |
|
551 | this._timers = {}; | |
552 | this.delay = delay || 800; // delay in milliseconds |
|
552 | this.delay = delay || 800; // delay in milliseconds | |
553 | } |
|
553 | }; | |
554 |
|
554 | |||
555 | ShortcutManager.prototype.help = function () { |
|
555 | ShortcutManager.prototype.help = function () { | |
556 | var help = []; |
|
556 | var help = []; | |
557 | for (var shortcut in this._shortcuts) { |
|
557 | for (var shortcut in this._shortcuts) { | |
558 |
var help_string = this._shortcuts[shortcut] |
|
558 | var help_string = this._shortcuts[shortcut].help; | |
559 |
var help_index = this._shortcuts[shortcut] |
|
559 | var help_index = this._shortcuts[shortcut].help_index; | |
560 | if (help_string) { |
|
560 | if (help_string) { | |
561 | if (platform === 'MacOS') { |
|
561 | if (platform === 'MacOS') { | |
562 | shortcut = shortcut.replace('meta', 'cmd'); |
|
562 | shortcut = shortcut.replace('meta', 'cmd'); | |
@@ -576,45 +576,45 var IPython = (function (IPython) { | |||||
576 | return 0; |
|
576 | return 0; | |
577 | }); |
|
577 | }); | |
578 | return help; |
|
578 | return help; | |
579 | } |
|
579 | }; | |
580 |
|
580 | |||
581 | ShortcutManager.prototype.normalize_key = function (key) { |
|
581 | ShortcutManager.prototype.normalize_key = function (key) { | |
582 | return inv_keycodes[keycodes[key]]; |
|
582 | return inv_keycodes[keycodes[key]]; | |
583 | } |
|
583 | }; | |
584 |
|
584 | |||
585 | ShortcutManager.prototype.normalize_shortcut = function (shortcut) { |
|
585 | ShortcutManager.prototype.normalize_shortcut = function (shortcut) { | |
586 | // Sort a sequence of + separated modifiers into the order alt+ctrl+meta+shift |
|
586 | // Sort a sequence of + separated modifiers into the order alt+ctrl+meta+shift | |
587 | shortcut = shortcut.replace('cmd', 'meta').toLowerCase(); |
|
587 | shortcut = shortcut.replace('cmd', 'meta').toLowerCase(); | |
588 | var values = shortcut.split("+"); |
|
588 | var values = shortcut.split("+"); | |
589 | if (values.length === 1) { |
|
589 | if (values.length === 1) { | |
590 | return this.normalize_key(values[0]) |
|
590 | return this.normalize_key(values[0]); | |
591 | } else { |
|
591 | } else { | |
592 | var modifiers = values.slice(0,-1); |
|
592 | var modifiers = values.slice(0,-1); | |
593 | var key = this.normalize_key(values[values.length-1]); |
|
593 | var key = this.normalize_key(values[values.length-1]); | |
594 | modifiers.sort(); |
|
594 | modifiers.sort(); | |
595 | return modifiers.join('+') + '+' + key; |
|
595 | return modifiers.join('+') + '+' + key; | |
596 | } |
|
596 | } | |
597 | } |
|
597 | }; | |
598 |
|
598 | |||
599 | ShortcutManager.prototype.event_to_shortcut = function (event) { |
|
599 | ShortcutManager.prototype.event_to_shortcut = function (event) { | |
600 | // Convert a jQuery keyboard event to a strong based keyboard shortcut |
|
600 | // Convert a jQuery keyboard event to a strong based keyboard shortcut | |
601 | var shortcut = ''; |
|
601 | var shortcut = ''; | |
602 | var key = inv_keycodes[event.which] |
|
602 | var key = inv_keycodes[event.which]; | |
603 | if (event.altKey && key !== 'alt') {shortcut += 'alt+';} |
|
603 | if (event.altKey && key !== 'alt') {shortcut += 'alt+';} | |
604 | if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl+';} |
|
604 | if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl+';} | |
605 | if (event.metaKey && key !== 'meta') {shortcut += 'meta+';} |
|
605 | if (event.metaKey && key !== 'meta') {shortcut += 'meta+';} | |
606 | if (event.shiftKey && key !== 'shift') {shortcut += 'shift+';} |
|
606 | if (event.shiftKey && key !== 'shift') {shortcut += 'shift+';} | |
607 | shortcut += key; |
|
607 | shortcut += key; | |
608 | return shortcut |
|
608 | return shortcut; | |
609 | } |
|
609 | }; | |
610 |
|
610 | |||
611 | ShortcutManager.prototype.clear_shortcuts = function () { |
|
611 | ShortcutManager.prototype.clear_shortcuts = function () { | |
612 | this._shortcuts = {}; |
|
612 | this._shortcuts = {}; | |
613 | } |
|
613 | }; | |
614 |
|
614 | |||
615 | ShortcutManager.prototype.add_shortcut = function (shortcut, data) { |
|
615 | ShortcutManager.prototype.add_shortcut = function (shortcut, data) { | |
616 | if (typeof(data) === 'function') { |
|
616 | if (typeof(data) === 'function') { | |
617 | data = {help: '', help_index: '', handler: data} |
|
617 | data = {help: '', help_index: '', handler: data}; | |
618 | } |
|
618 | } | |
619 | data.help_index = data.help_index || ''; |
|
619 | data.help_index = data.help_index || ''; | |
620 | data.help = data.help || ''; |
|
620 | data.help = data.help || ''; | |
@@ -625,19 +625,19 var IPython = (function (IPython) { | |||||
625 | shortcut = this.normalize_shortcut(shortcut); |
|
625 | shortcut = this.normalize_shortcut(shortcut); | |
626 | this._counts[shortcut] = 0; |
|
626 | this._counts[shortcut] = 0; | |
627 | this._shortcuts[shortcut] = data; |
|
627 | this._shortcuts[shortcut] = data; | |
628 | } |
|
628 | }; | |
629 |
|
629 | |||
630 | ShortcutManager.prototype.add_shortcuts = function (data) { |
|
630 | ShortcutManager.prototype.add_shortcuts = function (data) { | |
631 | for (var shortcut in data) { |
|
631 | for (var shortcut in data) { | |
632 | this.add_shortcut(shortcut, data[shortcut]); |
|
632 | this.add_shortcut(shortcut, data[shortcut]); | |
633 | } |
|
633 | } | |
634 | } |
|
634 | }; | |
635 |
|
635 | |||
636 | ShortcutManager.prototype.remove_shortcut = function (shortcut) { |
|
636 | ShortcutManager.prototype.remove_shortcut = function (shortcut) { | |
637 | shortcut = this.normalize_shortcut(shortcut); |
|
637 | shortcut = this.normalize_shortcut(shortcut); | |
638 | delete this._counts[shortcut]; |
|
638 | delete this._counts[shortcut]; | |
639 | delete this._shortcuts[shortcut]; |
|
639 | delete this._shortcuts[shortcut]; | |
640 | } |
|
640 | }; | |
641 |
|
641 | |||
642 | ShortcutManager.prototype.count_handler = function (shortcut, event, data) { |
|
642 | ShortcutManager.prototype.count_handler = function (shortcut, event, data) { | |
643 | var that = this; |
|
643 | var that = this; | |
@@ -646,7 +646,7 var IPython = (function (IPython) { | |||||
646 | var timer = null; |
|
646 | var timer = null; | |
647 | if (c[shortcut] === data.count-1) { |
|
647 | if (c[shortcut] === data.count-1) { | |
648 | c[shortcut] = 0; |
|
648 | c[shortcut] = 0; | |
649 |
|
|
649 | timer = t[shortcut]; | |
650 | if (timer) {clearTimeout(timer); delete t[shortcut];} |
|
650 | if (timer) {clearTimeout(timer); delete t[shortcut];} | |
651 | return data.handler(event); |
|
651 | return data.handler(event); | |
652 | } else { |
|
652 | } else { | |
@@ -657,13 +657,13 var IPython = (function (IPython) { | |||||
657 | t[shortcut] = timer; |
|
657 | t[shortcut] = timer; | |
658 | } |
|
658 | } | |
659 | return false; |
|
659 | return false; | |
660 | } |
|
660 | }; | |
661 |
|
661 | |||
662 | ShortcutManager.prototype.call_handler = function (event) { |
|
662 | ShortcutManager.prototype.call_handler = function (event) { | |
663 | var shortcut = this.event_to_shortcut(event); |
|
663 | var shortcut = this.event_to_shortcut(event); | |
664 | var data = this._shortcuts[shortcut]; |
|
664 | var data = this._shortcuts[shortcut]; | |
665 | if (data) { |
|
665 | if (data) { | |
666 |
var handler = data |
|
666 | var handler = data.handler; | |
667 | if (handler) { |
|
667 | if (handler) { | |
668 | if (data.count === 1) { |
|
668 | if (data.count === 1) { | |
669 | return handler(event); |
|
669 | return handler(event); | |
@@ -673,7 +673,7 var IPython = (function (IPython) { | |||||
673 | } |
|
673 | } | |
674 | } |
|
674 | } | |
675 | return true; |
|
675 | return true; | |
676 | } |
|
676 | }; | |
677 |
|
677 | |||
678 |
|
678 | |||
679 |
|
679 | |||
@@ -701,14 +701,14 var IPython = (function (IPython) { | |||||
701 | KeyboardManager.prototype.handle_keydown = function (event) { |
|
701 | KeyboardManager.prototype.handle_keydown = function (event) { | |
702 | var notebook = IPython.notebook; |
|
702 | var notebook = IPython.notebook; | |
703 |
|
703 | |||
704 |
if (event.which === keycodes |
|
704 | if (event.which === keycodes.esc) { | |
705 | // Intercept escape at highest level to avoid closing |
|
705 | // Intercept escape at highest level to avoid closing | |
706 | // websocket connection with firefox |
|
706 | // websocket connection with firefox | |
707 | event.preventDefault(); |
|
707 | event.preventDefault(); | |
708 | } |
|
708 | } | |
709 |
|
709 | |||
710 | if (!this.enabled) { |
|
710 | if (!this.enabled) { | |
711 |
if (event.which === keycodes |
|
711 | if (event.which === keycodes.esc) { | |
712 | // ESC |
|
712 | // ESC | |
713 | notebook.command_mode(); |
|
713 | notebook.command_mode(); | |
714 | return false; |
|
714 | return false; | |
@@ -722,25 +722,25 var IPython = (function (IPython) { | |||||
722 | return this.command_shortcuts.call_handler(event); |
|
722 | return this.command_shortcuts.call_handler(event); | |
723 | } |
|
723 | } | |
724 | return true; |
|
724 | return true; | |
725 | } |
|
725 | }; | |
726 |
|
726 | |||
727 | KeyboardManager.prototype.edit_mode = function () { |
|
727 | KeyboardManager.prototype.edit_mode = function () { | |
728 | this.last_mode = this.mode; |
|
728 | this.last_mode = this.mode; | |
729 | this.mode = 'edit'; |
|
729 | this.mode = 'edit'; | |
730 | } |
|
730 | }; | |
731 |
|
731 | |||
732 | KeyboardManager.prototype.command_mode = function () { |
|
732 | KeyboardManager.prototype.command_mode = function () { | |
733 | this.last_mode = this.mode; |
|
733 | this.last_mode = this.mode; | |
734 | this.mode = 'command'; |
|
734 | this.mode = 'command'; | |
735 | } |
|
735 | }; | |
736 |
|
736 | |||
737 | KeyboardManager.prototype.enable = function () { |
|
737 | KeyboardManager.prototype.enable = function () { | |
738 | this.enabled = true; |
|
738 | this.enabled = true; | |
739 | } |
|
739 | }; | |
740 |
|
740 | |||
741 | KeyboardManager.prototype.disable = function () { |
|
741 | KeyboardManager.prototype.disable = function () { | |
742 | this.enabled = false; |
|
742 | this.enabled = false; | |
743 | } |
|
743 | }; | |
744 |
|
744 | |||
745 | KeyboardManager.prototype.register_events = function (e) { |
|
745 | KeyboardManager.prototype.register_events = function (e) { | |
746 | var that = this; |
|
746 | var that = this; | |
@@ -758,7 +758,7 var IPython = (function (IPython) { | |||||
758 | that.enable(); |
|
758 | that.enable(); | |
759 | } |
|
759 | } | |
760 | }); |
|
760 | }); | |
761 | } |
|
761 | }; | |
762 |
|
762 | |||
763 |
|
763 | |||
764 | IPython.keycodes = keycodes; |
|
764 | IPython.keycodes = keycodes; |
General Comments 0
You need to be logged in to leave comments.
Login now