Show More
@@ -0,0 +1,78 b'' | |||
|
1 | // Copyright (c) IPython Development Team. | |
|
2 | // Distributed under the terms of the Modified BSD License. | |
|
3 | define([], function(){ | |
|
4 | "use strict"; | |
|
5 | ||
|
6 | var ScrollManager = function (notebook) { | |
|
7 | // Public constructor. | |
|
8 | this.notebook = notebook; | |
|
9 | }; | |
|
10 | ||
|
11 | ScrollManager.prototype.scroll = function (delta) { | |
|
12 | // Scroll the document. | |
|
13 | // | |
|
14 | // Parameters | |
|
15 | // ---------- | |
|
16 | // delta: integer | |
|
17 | // direction to scroll the document. Positive is downwards. | |
|
18 | ||
|
19 | // If one or more slides exist, scroll to the slide. | |
|
20 | var $slide_cells = $('.slideshow-slide'); | |
|
21 | if ($slide_cells.length > 0) { | |
|
22 | var i, cell; | |
|
23 | ||
|
24 | // Get the active slide cell index. | |
|
25 | var selected_index = this.notebook.find_cell_index(this.notebook.get_selected_cell()); | |
|
26 | var active_slide = -1; | |
|
27 | var cells = this.notebook.get_cells(); | |
|
28 | for (i = selected_index; i >= 0; i--) { | |
|
29 | cell = cells[i]; | |
|
30 | var ns = cell.metadata.slideshow; | |
|
31 | if (ns && ns.slide_type == 'slide') { | |
|
32 | active_slide = i; | |
|
33 | break; | |
|
34 | } | |
|
35 | } | |
|
36 | ||
|
37 | // Translate cell index into slide cell index. | |
|
38 | if (active_slide != -1) { | |
|
39 | for (i = 0; i < $slide_cells.length; i++) { | |
|
40 | if (cells[active_slide].element[0] == $slide_cells[i]) { | |
|
41 | active_slide = i; | |
|
42 | break; | |
|
43 | } | |
|
44 | } | |
|
45 | } | |
|
46 | ||
|
47 | // Scroll. | |
|
48 | if (active_slide != -1 || delta > 0) { | |
|
49 | active_slide += delta; | |
|
50 | active_slide = Math.max(0, Math.min($slide_cells.length-1, active_slide)); | |
|
51 | ||
|
52 | var cell_element = $slide_cells[active_slide]; | |
|
53 | cell = $(cell_element).data('cell'); | |
|
54 | this.notebook.select(this.notebook.find_cell_index(cell)); | |
|
55 | ||
|
56 | this.scroll_to(cell_element); | |
|
57 | //cell_element.scrollIntoView(true); | |
|
58 | } | |
|
59 | ||
|
60 | // Cancel browser keyboard scroll. | |
|
61 | return false; | |
|
62 | ||
|
63 | // No slides exist, default browser scroll | |
|
64 | } else { | |
|
65 | return true; | |
|
66 | } | |
|
67 | }; | |
|
68 | ||
|
69 | ScrollManager.prototype.scroll_to = function(destination) { | |
|
70 | $('html, body').animate({'scrollTop': element.offset().top}, 'slow', 'swing'); | |
|
71 | }; | |
|
72 | ||
|
73 | // For convinience, add the ScrollManager class to the global namespace | |
|
74 | IPython.ScrollManager = ScrollManager; | |
|
75 | // Return naemspace for require.js loads | |
|
76 | return ScrollManager; | |
|
77 | ||
|
78 | }); |
This diff has been collapsed as it changes many lines, (715 lines changed) Show them Hide them | |||
@@ -1,566 +1,581 b'' | |||
|
1 | // Copyright (c) IPython Development Team. | |
|
2 | // Distributed under the terms of the Modified BSD License. | |
|
1 | //---------------------------------------------------------------------------- | |
|
2 | // Copyright (C) 2011 The IPython Development Team | |
|
3 | // | |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
|
5 | // the file COPYING, distributed as part of this software. | |
|
6 | //---------------------------------------------------------------------------- | |
|
3 | 7 | |
|
4 | define([ | |
|
5 | 'base/js/namespace', | |
|
6 | 'jquery', | |
|
7 | 'base/js/utils', | |
|
8 | 'base/js/keyboard', | |
|
9 | ], function(IPython, $, utils, keyboard) { | |
|
8 | //============================================================================ | |
|
9 | // Keyboard management | |
|
10 | //============================================================================ | |
|
11 | ||
|
12 | var IPython = (function (IPython) { | |
|
10 | 13 | "use strict"; |
|
11 | ||
|
14 | ||
|
12 | 15 | var browser = utils.browser[0]; |
|
13 | 16 | var platform = utils.platform; |
|
14 | 17 | |
|
15 | 18 | // Main keyboard manager for the notebook |
|
16 | 19 | var keycodes = keyboard.keycodes; |
|
17 | 20 | |
|
18 | 21 | var KeyboardManager = function (options) { |
|
19 | 22 | // Constructor |
|
20 | 23 | // |
|
21 | 24 | // Parameters: |
|
22 | 25 | // options: dictionary |
|
23 | 26 | // Dictionary of keyword arguments. |
|
24 | 27 | // events: $(Events) instance |
|
25 | 28 | // pager: Pager instance |
|
26 | 29 | this.mode = 'command'; |
|
27 | 30 | this.enabled = true; |
|
28 | 31 | this.pager = options.pager; |
|
29 | 32 | this.quick_help = undefined; |
|
30 | 33 | this.notebook = undefined; |
|
31 | 34 | this.bind_events(); |
|
32 | 35 | this.command_shortcuts = new keyboard.ShortcutManager(undefined, options.events); |
|
33 | 36 | this.command_shortcuts.add_shortcuts(this.get_default_common_shortcuts()); |
|
34 | 37 | this.command_shortcuts.add_shortcuts(this.get_default_command_shortcuts()); |
|
35 | 38 | this.edit_shortcuts = new keyboard.ShortcutManager(undefined, options.events); |
|
36 | 39 | this.edit_shortcuts.add_shortcuts(this.get_default_common_shortcuts()); |
|
37 | 40 | this.edit_shortcuts.add_shortcuts(this.get_default_edit_shortcuts()); |
|
38 | 41 | }; |
|
39 | 42 | |
|
40 | 43 | KeyboardManager.prototype.get_default_common_shortcuts = function() { |
|
41 | 44 | var that = this; |
|
42 | 45 | var shortcuts = { |
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
|
46 | 'shift' : { | |
|
47 | help : '', | |
|
48 | help_index : '', | |
|
49 | handler : function (event) { | |
|
50 | // ignore shift keydown | |
|
51 | return true; | |
|
52 | } | |
|
53 | }, | |
|
54 | 'shift-enter' : { | |
|
55 | help : 'run cell, select below', | |
|
56 | help_index : 'ba', | |
|
57 | handler : function (event) { | |
|
55 | 58 | that.notebook.execute_cell_and_select_below(); |
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
|
59 | return false; | |
|
60 | } | |
|
61 | }, | |
|
62 | 'ctrl-enter' : { | |
|
63 | help : 'run cell', | |
|
64 | help_index : 'bb', | |
|
65 | handler : function (event) { | |
|
63 | 66 | that.notebook.execute_cell(); |
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
|
67 | return false; | |
|
68 | } | |
|
69 | }, | |
|
70 | 'alt-enter' : { | |
|
71 | help : 'run cell, insert below', | |
|
72 | help_index : 'bc', | |
|
73 | handler : function (event) { | |
|
71 | 74 | that.notebook.execute_cell_and_insert_below(); |
|
72 |
|
|
|
73 | } | |
|
75 | return false; | |
|
74 | 76 | } |
|
75 |
} |
|
|
77 | } | |
|
78 | }; | |
|
76 | 79 | |
|
77 |
|
|
|
80 | if (platform === 'MacOS') { | |
|
78 | 81 | shortcuts['cmd-s'] = |
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
82 | { | |
|
83 | help : 'save notebook', | |
|
84 | help_index : 'fb', | |
|
85 | handler : function (event) { | |
|
83 | 86 | that.notebook.save_checkpoint(); |
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
87 | event.preventDefault(); | |
|
88 | return false; | |
|
89 | } | |
|
90 | }; | |
|
91 | } else { | |
|
89 | 92 | shortcuts['ctrl-s'] = |
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
|
93 | { | |
|
94 | help : 'save notebook', | |
|
95 | help_index : 'fb', | |
|
96 | handler : function (event) { | |
|
94 | 97 | that.notebook.save_checkpoint(); |
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
98 | event.preventDefault(); | |
|
99 | return false; | |
|
100 | } | |
|
101 | }; | |
|
102 | } | |
|
100 | 103 | return shortcuts; |
|
101 | 104 | }; |
|
102 | 105 | |
|
103 | 106 | KeyboardManager.prototype.get_default_edit_shortcuts = function() { |
|
104 | 107 | var that = this; |
|
105 | 108 | return { |
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
|
109 | 'esc' : { | |
|
110 | help : 'command mode', | |
|
111 | help_index : 'aa', | |
|
112 | handler : function (event) { | |
|
110 | 113 | that.notebook.command_mode(); |
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
114 | return false; | |
|
115 | } | |
|
116 | }, | |
|
117 | 'ctrl-m' : { | |
|
118 | help : 'command mode', | |
|
119 | help_index : 'ab', | |
|
120 | handler : function (event) { | |
|
118 | 121 | that.notebook.command_mode(); |
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
|
122 | return false; | |
|
123 | } | |
|
124 | }, | |
|
125 | 'up' : { | |
|
126 | help : '', | |
|
127 | help_index : '', | |
|
128 | handler : function (event) { | |
|
126 | 129 | var index = that.notebook.get_selected_index(); |
|
127 | 130 | var cell = that.notebook.get_cell(index); |
|
128 |
|
|
|
129 |
|
|
|
131 | if (cell && cell.at_top() && index !== 0) { | |
|
132 | event.preventDefault(); | |
|
130 | 133 | that.notebook.command_mode(); |
|
131 | 134 | that.notebook.select_prev(); |
|
132 | 135 | that.notebook.edit_mode(); |
|
133 | 136 | var cm = that.notebook.get_selected_cell().code_mirror; |
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 | } | |
|
137 | cm.setCursor(cm.lastLine(), 0); | |
|
138 | return false; | |
|
139 | } else if (cell) { | |
|
140 | var cm = cell.code_mirror; | |
|
141 | cm.execCommand('goLineUp'); | |
|
142 | return false; | |
|
141 | 143 | } |
|
142 |
} |
|
|
143 | 'down' : { | |
|
144 | help : '', | |
|
145 |
|
|
|
146 | handler : function (event) { | |
|
144 | } | |
|
145 | }, | |
|
146 | 'down' : { | |
|
147 | help : '', | |
|
148 | help_index : '', | |
|
149 | handler : function (event) { | |
|
147 | 150 | var index = that.notebook.get_selected_index(); |
|
148 | 151 | var cell = that.notebook.get_cell(index); |
|
149 | 152 | if (cell.at_bottom() && index !== (that.notebook.ncells()-1)) { |
|
150 |
|
|
|
153 | event.preventDefault(); | |
|
151 | 154 | that.notebook.command_mode(); |
|
152 | 155 | that.notebook.select_next(); |
|
153 | 156 | that.notebook.edit_mode(); |
|
154 | 157 | var cm = that.notebook.get_selected_cell().code_mirror; |
|
155 |
|
|
|
156 | return false; | |
|
157 | } else { | |
|
158 | var cm = cell.code_mirror; | |
|
159 | cm.execCommand('goLineDown'); | |
|
160 | return false; | |
|
161 | } | |
|
162 | } | |
|
163 | }, | |
|
164 | 'ctrl-shift--' : { | |
|
165 | help : 'split cell', | |
|
166 | help_index : 'ea', | |
|
167 | handler : function (event) { | |
|
168 | that.notebook.split_cell(); | |
|
158 | cm.setCursor(0, 0); | |
|
169 | 159 | return false; |
|
170 | } | |
|
171 | }, | |
|
172 | 'ctrl-shift-subtract' : { | |
|
173 | help : '', | |
|
174 | help_index : 'eb', | |
|
175 | handler : function (event) { | |
|
176 | that.notebook.split_cell(); | |
|
160 | } else { | |
|
161 | var cm = cell.code_mirror; | |
|
162 | cm.execCommand('goLineDown'); | |
|
177 | 163 | return false; |
|
178 | 164 | } |
|
179 |
} |
|
|
180 |
} |
|
|
165 | } | |
|
166 | }, | |
|
167 | 'ctrl-shift--' : { | |
|
168 | help : 'split cell', | |
|
169 | help_index : 'ea', | |
|
170 | handler : function (event) { | |
|
171 | that.notebook.split_cell(); | |
|
172 | return false; | |
|
173 | } | |
|
174 | }, | |
|
175 | 'ctrl-shift-subtract' : { | |
|
176 | help : '', | |
|
177 | help_index : 'eb', | |
|
178 | handler : function (event) { | |
|
179 | that.notebook.split_cell(); | |
|
180 | return false; | |
|
181 | } | |
|
182 | }, | |
|
183 | }; | |
|
181 | 184 | }; |
|
182 | 185 | |
|
183 | 186 | KeyboardManager.prototype.get_default_command_shortcuts = function() { |
|
184 | 187 | var that = this; |
|
185 | 188 | return { |
|
186 |
|
|
|
187 | help : 'edit mode', | |
|
188 | help_index : 'aa', | |
|
189 | handler : function (event) { | |
|
189 | 'space': { | |
|
190 | help: "Scroll down to next H1 cell", | |
|
191 | handler: function(event) { | |
|
192 | return that.notebook.scrollmanager.scroll(1); | |
|
193 | }, | |
|
194 | }, | |
|
195 | 'shift-space': { | |
|
196 | help: "Scroll up to previous H1 cell", | |
|
197 | handler: function(event) { | |
|
198 | return that.notebook.scrollmanager.scroll(-1); | |
|
199 | }, | |
|
200 | }, | |
|
201 | 'enter' : { | |
|
202 | help : 'edit mode', | |
|
203 | help_index : 'aa', | |
|
204 | handler : function (event) { | |
|
190 | 205 | that.notebook.edit_mode(); |
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
|
206 | return false; | |
|
207 | } | |
|
208 | }, | |
|
209 | 'up' : { | |
|
210 | help : 'select previous cell', | |
|
211 | help_index : 'da', | |
|
212 | handler : function (event) { | |
|
198 | 213 | var index = that.notebook.get_selected_index(); |
|
199 |
|
|
|
214 | if (index !== 0 && index !== null) { | |
|
200 | 215 | that.notebook.select_prev(); |
|
201 | 216 | that.notebook.focus_cell(); |
|
202 | } | |
|
203 | return false; | |
|
204 | 217 | } |
|
205 | }, | |
|
206 |
|
|
|
207 | help : 'select next cell', | |
|
208 | help_index : 'db', | |
|
209 | handler : function (event) { | |
|
218 | return false; | |
|
219 | } | |
|
220 | }, | |
|
221 | 'down' : { | |
|
222 | help : 'select next cell', | |
|
223 | help_index : 'db', | |
|
224 | handler : function (event) { | |
|
210 | 225 | var index = that.notebook.get_selected_index(); |
|
211 | 226 | if (index !== (that.notebook.ncells()-1) && index !== null) { |
|
212 | 227 | that.notebook.select_next(); |
|
213 | 228 | that.notebook.focus_cell(); |
|
214 | } | |
|
215 | return false; | |
|
216 | 229 | } |
|
217 | }, | |
|
218 |
|
|
|
219 | help : 'select previous cell', | |
|
220 | help_index : 'dc', | |
|
221 | handler : function (event) { | |
|
230 | return false; | |
|
231 | } | |
|
232 | }, | |
|
233 | 'k' : { | |
|
234 | help : 'select previous cell', | |
|
235 | help_index : 'dc', | |
|
236 | handler : function (event) { | |
|
222 | 237 | var index = that.notebook.get_selected_index(); |
|
223 |
|
|
|
238 | if (index !== 0 && index !== null) { | |
|
224 | 239 | that.notebook.select_prev(); |
|
225 | 240 | that.notebook.focus_cell(); |
|
226 | } | |
|
227 | return false; | |
|
228 | 241 | } |
|
229 | }, | |
|
230 |
|
|
|
231 | help : 'select next cell', | |
|
232 | help_index : 'dd', | |
|
233 | handler : function (event) { | |
|
242 | return false; | |
|
243 | } | |
|
244 | }, | |
|
245 | 'j' : { | |
|
246 | help : 'select next cell', | |
|
247 | help_index : 'dd', | |
|
248 | handler : function (event) { | |
|
234 | 249 | var index = that.notebook.get_selected_index(); |
|
235 | 250 | if (index !== (that.notebook.ncells()-1) && index !== null) { |
|
236 | 251 | that.notebook.select_next(); |
|
237 | 252 | that.notebook.focus_cell(); |
|
238 | } | |
|
239 | return false; | |
|
240 | 253 | } |
|
241 | }, | |
|
242 |
|
|
|
243 | help : 'cut cell', | |
|
244 | help_index : 'ee', | |
|
245 | handler : function (event) { | |
|
254 | return false; | |
|
255 | } | |
|
256 | }, | |
|
257 | 'x' : { | |
|
258 | help : 'cut cell', | |
|
259 | help_index : 'ee', | |
|
260 | handler : function (event) { | |
|
246 | 261 | that.notebook.cut_cell(); |
|
247 |
|
|
|
248 |
|
|
|
249 |
|
|
|
250 |
|
|
|
251 |
|
|
|
252 |
|
|
|
253 |
|
|
|
262 | return false; | |
|
263 | } | |
|
264 | }, | |
|
265 | 'c' : { | |
|
266 | help : 'copy cell', | |
|
267 | help_index : 'ef', | |
|
268 | handler : function (event) { | |
|
254 | 269 | that.notebook.copy_cell(); |
|
255 |
|
|
|
256 |
|
|
|
257 |
|
|
|
258 |
|
|
|
259 |
|
|
|
260 |
|
|
|
261 |
|
|
|
270 | return false; | |
|
271 | } | |
|
272 | }, | |
|
273 | 'shift-v' : { | |
|
274 | help : 'paste cell above', | |
|
275 | help_index : 'eg', | |
|
276 | handler : function (event) { | |
|
262 | 277 | that.notebook.paste_cell_above(); |
|
263 |
|
|
|
264 |
|
|
|
265 |
|
|
|
266 |
|
|
|
267 |
|
|
|
268 |
|
|
|
269 |
|
|
|
278 | return false; | |
|
279 | } | |
|
280 | }, | |
|
281 | 'v' : { | |
|
282 | help : 'paste cell below', | |
|
283 | help_index : 'eh', | |
|
284 | handler : function (event) { | |
|
270 | 285 | that.notebook.paste_cell_below(); |
|
271 |
|
|
|
272 |
|
|
|
273 |
|
|
|
274 |
|
|
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
|
278 |
|
|
|
286 | return false; | |
|
287 | } | |
|
288 | }, | |
|
289 | 'd' : { | |
|
290 | help : 'delete cell (press twice)', | |
|
291 | help_index : 'ej', | |
|
292 | count: 2, | |
|
293 | handler : function (event) { | |
|
279 | 294 | that.notebook.delete_cell(); |
|
280 |
|
|
|
281 |
|
|
|
282 |
|
|
|
283 |
|
|
|
284 |
|
|
|
285 |
|
|
|
286 |
|
|
|
295 | return false; | |
|
296 | } | |
|
297 | }, | |
|
298 | 'a' : { | |
|
299 | help : 'insert cell above', | |
|
300 | help_index : 'ec', | |
|
301 | handler : function (event) { | |
|
287 | 302 | that.notebook.insert_cell_above(); |
|
288 | 303 | that.notebook.select_prev(); |
|
289 | 304 | that.notebook.focus_cell(); |
|
290 |
|
|
|
291 |
|
|
|
292 |
|
|
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
|
296 |
|
|
|
305 | return false; | |
|
306 | } | |
|
307 | }, | |
|
308 | 'b' : { | |
|
309 | help : 'insert cell below', | |
|
310 | help_index : 'ed', | |
|
311 | handler : function (event) { | |
|
297 | 312 | that.notebook.insert_cell_below(); |
|
298 | 313 | that.notebook.select_next(); |
|
299 | 314 | that.notebook.focus_cell(); |
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
|
315 | return false; | |
|
316 | } | |
|
317 | }, | |
|
318 | 'y' : { | |
|
319 | help : 'to code', | |
|
320 | help_index : 'ca', | |
|
321 | handler : function (event) { | |
|
307 | 322 | that.notebook.to_code(); |
|
308 |
|
|
|
309 |
|
|
|
310 |
|
|
|
311 |
|
|
|
312 |
|
|
|
313 |
|
|
|
314 |
|
|
|
323 | return false; | |
|
324 | } | |
|
325 | }, | |
|
326 | 'm' : { | |
|
327 | help : 'to markdown', | |
|
328 | help_index : 'cb', | |
|
329 | handler : function (event) { | |
|
315 | 330 | that.notebook.to_markdown(); |
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
|
319 |
|
|
|
320 |
|
|
|
321 |
|
|
|
322 |
|
|
|
331 | return false; | |
|
332 | } | |
|
333 | }, | |
|
334 | 'r' : { | |
|
335 | help : 'to raw', | |
|
336 | help_index : 'cc', | |
|
337 | handler : function (event) { | |
|
323 | 338 | that.notebook.to_raw(); |
|
324 |
|
|
|
325 |
|
|
|
326 |
|
|
|
327 |
|
|
|
328 |
|
|
|
329 |
|
|
|
330 |
|
|
|
339 | return false; | |
|
340 | } | |
|
341 | }, | |
|
342 | '1' : { | |
|
343 | help : 'to heading 1', | |
|
344 | help_index : 'cd', | |
|
345 | handler : function (event) { | |
|
331 | 346 | that.notebook.to_heading(undefined, 1); |
|
332 |
|
|
|
333 |
|
|
|
334 |
|
|
|
335 |
|
|
|
336 |
|
|
|
337 |
|
|
|
338 |
|
|
|
347 | return false; | |
|
348 | } | |
|
349 | }, | |
|
350 | '2' : { | |
|
351 | help : 'to heading 2', | |
|
352 | help_index : 'ce', | |
|
353 | handler : function (event) { | |
|
339 | 354 | that.notebook.to_heading(undefined, 2); |
|
340 |
|
|
|
341 |
|
|
|
342 |
|
|
|
343 |
|
|
|
344 |
|
|
|
345 |
|
|
|
346 |
|
|
|
355 | return false; | |
|
356 | } | |
|
357 | }, | |
|
358 | '3' : { | |
|
359 | help : 'to heading 3', | |
|
360 | help_index : 'cf', | |
|
361 | handler : function (event) { | |
|
347 | 362 | that.notebook.to_heading(undefined, 3); |
|
348 |
|
|
|
349 |
|
|
|
350 |
|
|
|
351 |
|
|
|
352 |
|
|
|
353 |
|
|
|
354 |
|
|
|
363 | return false; | |
|
364 | } | |
|
365 | }, | |
|
366 | '4' : { | |
|
367 | help : 'to heading 4', | |
|
368 | help_index : 'cg', | |
|
369 | handler : function (event) { | |
|
355 | 370 | that.notebook.to_heading(undefined, 4); |
|
356 |
|
|
|
357 |
|
|
|
358 |
|
|
|
359 |
|
|
|
360 |
|
|
|
361 |
|
|
|
362 |
|
|
|
371 | return false; | |
|
372 | } | |
|
373 | }, | |
|
374 | '5' : { | |
|
375 | help : 'to heading 5', | |
|
376 | help_index : 'ch', | |
|
377 | handler : function (event) { | |
|
363 | 378 | that.notebook.to_heading(undefined, 5); |
|
364 |
|
|
|
365 |
|
|
|
366 |
|
|
|
367 |
|
|
|
368 |
|
|
|
369 |
|
|
|
370 |
|
|
|
379 | return false; | |
|
380 | } | |
|
381 | }, | |
|
382 | '6' : { | |
|
383 | help : 'to heading 6', | |
|
384 | help_index : 'ci', | |
|
385 | handler : function (event) { | |
|
371 | 386 | that.notebook.to_heading(undefined, 6); |
|
372 |
|
|
|
373 |
|
|
|
374 |
|
|
|
375 |
|
|
|
376 |
|
|
|
377 |
|
|
|
378 |
|
|
|
387 | return false; | |
|
388 | } | |
|
389 | }, | |
|
390 | 'o' : { | |
|
391 | help : 'toggle output', | |
|
392 | help_index : 'gb', | |
|
393 | handler : function (event) { | |
|
379 | 394 | that.notebook.toggle_output(); |
|
380 |
|
|
|
381 |
|
|
|
382 |
|
|
|
383 |
|
|
|
384 |
|
|
|
385 |
|
|
|
386 |
|
|
|
395 | return false; | |
|
396 | } | |
|
397 | }, | |
|
398 | 'shift-o' : { | |
|
399 | help : 'toggle output scrolling', | |
|
400 | help_index : 'gc', | |
|
401 | handler : function (event) { | |
|
387 | 402 | that.notebook.toggle_output_scroll(); |
|
388 |
|
|
|
389 |
|
|
|
390 |
|
|
|
391 |
|
|
|
392 |
|
|
|
393 |
|
|
|
394 |
|
|
|
403 | return false; | |
|
404 | } | |
|
405 | }, | |
|
406 | 's' : { | |
|
407 | help : 'save notebook', | |
|
408 | help_index : 'fa', | |
|
409 | handler : function (event) { | |
|
395 | 410 | that.notebook.save_checkpoint(); |
|
396 |
|
|
|
397 |
|
|
|
398 |
|
|
|
399 |
|
|
|
400 |
|
|
|
401 |
|
|
|
402 |
|
|
|
411 | return false; | |
|
412 | } | |
|
413 | }, | |
|
414 | 'ctrl-j' : { | |
|
415 | help : 'move cell down', | |
|
416 | help_index : 'eb', | |
|
417 | handler : function (event) { | |
|
403 | 418 | that.notebook.move_cell_down(); |
|
404 |
|
|
|
405 |
|
|
|
406 |
|
|
|
407 |
|
|
|
408 |
|
|
|
409 |
|
|
|
410 |
|
|
|
419 | return false; | |
|
420 | } | |
|
421 | }, | |
|
422 | 'ctrl-k' : { | |
|
423 | help : 'move cell up', | |
|
424 | help_index : 'ea', | |
|
425 | handler : function (event) { | |
|
411 | 426 | that.notebook.move_cell_up(); |
|
412 |
|
|
|
413 |
|
|
|
414 |
|
|
|
415 |
|
|
|
416 |
|
|
|
417 |
|
|
|
418 |
|
|
|
427 | return false; | |
|
428 | } | |
|
429 | }, | |
|
430 | 'l' : { | |
|
431 | help : 'toggle line numbers', | |
|
432 | help_index : 'ga', | |
|
433 | handler : function (event) { | |
|
419 | 434 | that.notebook.cell_toggle_line_numbers(); |
|
420 |
|
|
|
421 |
|
|
|
422 |
|
|
|
423 |
|
|
|
424 |
|
|
|
425 |
|
|
|
426 |
|
|
|
427 |
|
|
|
435 | return false; | |
|
436 | } | |
|
437 | }, | |
|
438 | 'i' : { | |
|
439 | help : 'interrupt kernel (press twice)', | |
|
440 | help_index : 'ha', | |
|
441 | count: 2, | |
|
442 | handler : function (event) { | |
|
428 | 443 | that.notebook.kernel.interrupt(); |
|
429 |
|
|
|
430 |
|
|
|
431 |
|
|
|
432 |
|
|
|
433 |
|
|
|
434 |
|
|
|
435 |
|
|
|
436 |
|
|
|
444 | return false; | |
|
445 | } | |
|
446 | }, | |
|
447 | '0' : { | |
|
448 | help : 'restart kernel (press twice)', | |
|
449 | help_index : 'hb', | |
|
450 | count: 2, | |
|
451 | handler : function (event) { | |
|
437 | 452 | that.notebook.restart_kernel(); |
|
438 |
|
|
|
439 |
|
|
|
440 |
|
|
|
441 |
|
|
|
442 |
|
|
|
443 |
|
|
|
444 |
|
|
|
453 | return false; | |
|
454 | } | |
|
455 | }, | |
|
456 | 'h' : { | |
|
457 | help : 'keyboard shortcuts', | |
|
458 | help_index : 'ge', | |
|
459 | handler : function (event) { | |
|
445 | 460 | that.quick_help.show_keyboard_shortcuts(); |
|
446 |
|
|
|
447 |
|
|
|
448 |
|
|
|
449 |
|
|
|
450 |
|
|
|
451 |
|
|
|
452 |
|
|
|
461 | return false; | |
|
462 | } | |
|
463 | }, | |
|
464 | 'z' : { | |
|
465 | help : 'undo last delete', | |
|
466 | help_index : 'ei', | |
|
467 | handler : function (event) { | |
|
453 | 468 | that.notebook.undelete_cell(); |
|
454 |
|
|
|
455 |
|
|
|
456 |
|
|
|
457 |
|
|
|
458 |
|
|
|
459 |
|
|
|
460 |
|
|
|
469 | return false; | |
|
470 | } | |
|
471 | }, | |
|
472 | 'shift-m' : { | |
|
473 | help : 'merge cell below', | |
|
474 | help_index : 'ek', | |
|
475 | handler : function (event) { | |
|
461 | 476 | that.notebook.merge_cell_below(); |
|
462 |
|
|
|
463 |
|
|
|
464 |
|
|
|
465 |
|
|
|
466 |
|
|
|
467 |
|
|
|
468 |
|
|
|
477 | return false; | |
|
478 | } | |
|
479 | }, | |
|
480 | 'q' : { | |
|
481 | help : 'close pager', | |
|
482 | help_index : 'gd', | |
|
483 | handler : function (event) { | |
|
469 | 484 | that.pager.collapse(); |
|
470 |
|
|
|
471 |
|
|
|
472 |
|
|
|
473 |
|
|
|
485 | return false; | |
|
486 | } | |
|
487 | }, | |
|
488 | }; | |
|
474 | 489 | }; |
|
475 | 490 | |
|
476 | 491 | KeyboardManager.prototype.bind_events = function () { |
|
477 | 492 | var that = this; |
|
478 | 493 | $(document).keydown(function (event) { |
|
479 | 494 | return that.handle_keydown(event); |
|
480 | 495 | }); |
|
481 | 496 | }; |
|
482 | 497 | |
|
483 | 498 | KeyboardManager.prototype.handle_keydown = function (event) { |
|
484 | 499 | var notebook = this.notebook; |
|
485 | 500 | |
|
486 | 501 | if (event.which === keycodes.esc) { |
|
487 | 502 | // Intercept escape at highest level to avoid closing |
|
488 | 503 | // websocket connection with firefox |
|
489 | 504 | event.preventDefault(); |
|
490 | 505 | } |
|
491 | 506 | |
|
492 | 507 | if (!this.enabled) { |
|
493 | 508 | if (event.which === keycodes.esc) { |
|
494 | 509 | // ESC |
|
495 | 510 | notebook.command_mode(); |
|
496 | 511 | return false; |
|
497 | 512 | } |
|
498 | 513 | return true; |
|
499 | 514 | } |
|
500 | 515 | |
|
501 | 516 | if (this.mode === 'edit') { |
|
502 | 517 | return this.edit_shortcuts.call_handler(event); |
|
503 | 518 | } else if (this.mode === 'command') { |
|
504 | 519 | return this.command_shortcuts.call_handler(event); |
|
505 | 520 | } |
|
506 | 521 | return true; |
|
507 | 522 | }; |
|
508 | 523 | |
|
509 | 524 | KeyboardManager.prototype.edit_mode = function () { |
|
510 | 525 | this.last_mode = this.mode; |
|
511 | 526 | this.mode = 'edit'; |
|
512 | 527 | }; |
|
513 | 528 | |
|
514 | 529 | KeyboardManager.prototype.command_mode = function () { |
|
515 | 530 | this.last_mode = this.mode; |
|
516 | 531 | this.mode = 'command'; |
|
517 | 532 | }; |
|
518 | 533 | |
|
519 | 534 | KeyboardManager.prototype.enable = function () { |
|
520 | 535 | this.enabled = true; |
|
521 | 536 | }; |
|
522 | 537 | |
|
523 | 538 | KeyboardManager.prototype.disable = function () { |
|
524 | 539 | this.enabled = false; |
|
525 | 540 | }; |
|
526 | 541 | |
|
527 | 542 | KeyboardManager.prototype.register_events = function (e) { |
|
528 | 543 | var that = this; |
|
529 | 544 | var handle_focus = function () { |
|
530 | 545 | that.disable(); |
|
531 | 546 | }; |
|
532 | 547 | var handle_blur = function () { |
|
533 | 548 | that.enable(); |
|
534 | 549 | }; |
|
535 | 550 | e.on('focusin', handle_focus); |
|
536 | 551 | e.on('focusout', handle_blur); |
|
537 | 552 | // TODO: Very strange. The focusout event does not seem fire for the |
|
538 | 553 | // bootstrap textboxes on FF25&26... This works around that by |
|
539 | 554 | // registering focus and blur events recursively on all inputs within |
|
540 | 555 | // registered element. |
|
541 | 556 | e.find('input').blur(handle_blur); |
|
542 | 557 | e.on('DOMNodeInserted', function (event) { |
|
543 | 558 | var target = $(event.target); |
|
544 | 559 | if (target.is('input')) { |
|
545 | 560 | target.blur(handle_blur); |
|
546 | 561 | } else { |
|
547 | 562 | target.find('input').blur(handle_blur); |
|
548 | 563 | } |
|
549 | 564 | }); |
|
550 | 565 | // There are times (raw_input) where we remove the element from the DOM before |
|
551 | 566 | // focusout is called. In this case we bind to the remove event of jQueryUI, |
|
552 | 567 | // which gets triggered upon removal, iff it is focused at the time. |
|
553 | 568 | // is_focused must be used to check for the case where an element within |
|
554 | 569 | // the element being removed is focused. |
|
555 | 570 | e.on('remove', function () { |
|
556 | 571 | if (utils.is_focused(e[0])) { |
|
557 | 572 | that.enable(); |
|
558 | 573 | } |
|
559 | 574 | }); |
|
560 | 575 | }; |
|
561 | 576 | |
|
562 | 577 | // For backwards compatability. |
|
563 | 578 | IPython.KeyboardManager = KeyboardManager; |
|
564 | 579 | |
|
565 | 580 | return {'KeyboardManager': KeyboardManager}; |
|
566 | 581 | }); |
@@ -1,139 +1,143 b'' | |||
|
1 | 1 | // Copyright (c) IPython Development Team. |
|
2 | 2 | // Distributed under the terms of the Modified BSD License. |
|
3 | 3 | |
|
4 | 4 | require([ |
|
5 | 5 | 'base/js/namespace', |
|
6 | 6 | 'jquery', |
|
7 | 7 | 'notebook/js/notebook', |
|
8 | 8 | 'base/js/utils', |
|
9 | 9 | 'base/js/page', |
|
10 | 10 | 'notebook/js/layoutmanager', |
|
11 | 11 | 'base/js/events', |
|
12 | 12 | 'auth/js/loginwidget', |
|
13 | 13 | 'notebook/js/maintoolbar', |
|
14 | 14 | 'notebook/js/pager', |
|
15 | 15 | 'notebook/js/quickhelp', |
|
16 | 16 | 'notebook/js/menubar', |
|
17 | 17 | 'notebook/js/notificationarea', |
|
18 | 18 | 'notebook/js/savewidget', |
|
19 | 19 | 'notebook/js/keyboardmanager', |
|
20 | 20 | 'notebook/js/config', |
|
21 | 21 | 'notebook/js/kernelselector', |
|
22 | 'notebook/js/scrollmanager' | |
|
22 | 23 | // only loaded, not used: |
|
23 | 24 | 'custom/custom', |
|
24 | 25 | ], function( |
|
25 | 26 | IPython, |
|
26 | 27 | $, |
|
27 | 28 | notebook, |
|
28 | 29 | utils, |
|
29 | 30 | page, |
|
30 | 31 | layoutmanager, |
|
31 | 32 | events, |
|
32 | 33 | loginwidget, |
|
33 | 34 | maintoolbar, |
|
34 | 35 | pager, |
|
35 | 36 | quickhelp, |
|
36 | 37 | menubar, |
|
37 | 38 | notificationarea, |
|
38 | 39 | savewidget, |
|
39 | 40 | keyboardmanager, |
|
40 | 41 | config, |
|
41 | kernelselector | |
|
42 | kernelselector, | |
|
43 | scrollmanager | |
|
42 | 44 | ) { |
|
43 | 45 | "use strict"; |
|
44 | 46 | |
|
45 | 47 | var common_options = { |
|
46 | 48 | base_url : utils.get_body_data("baseUrl"), |
|
47 | 49 | ws_url : IPython.utils.get_body_data("wsUrl"), |
|
48 | 50 | notebook_path : utils.get_body_data("notebookPath"), |
|
49 | 51 | notebook_name : utils.get_body_data('notebookName') |
|
50 | 52 | }; |
|
51 | 53 | |
|
52 | 54 | var user_config = $.extend({}, config.default_config); |
|
53 | 55 | var page = new page.Page(); |
|
54 | 56 | var layout_manager = new layoutmanager.LayoutManager(); |
|
55 | 57 | var pager = new pager.Pager('div#pager', 'div#pager_splitter', { |
|
56 | 58 | layout_manager: layout_manager, |
|
57 | 59 | events: events}); |
|
58 | 60 | var keyboard_manager = new keyboardmanager.KeyboardManager({ |
|
59 | 61 | pager: pager, |
|
60 | 62 | events: events}); |
|
61 | 63 | var save_widget = new savewidget.SaveWidget('span#save_widget', { |
|
62 | 64 | events: events, |
|
63 | 65 | keyboard_manager: keyboard_manager}); |
|
64 | 66 | var notebook = new notebook.Notebook('div#notebook', $.extend({ |
|
65 | 67 | events: events, |
|
66 | 68 | keyboard_manager: keyboard_manager, |
|
67 | 69 | save_widget: save_widget, |
|
68 | 70 | config: user_config}, |
|
69 | 71 | common_options)); |
|
72 | var scrollmanager = new scrollmanager.ScrollManager(notebook); | |
|
70 | 73 | var login_widget = new loginwidget.LoginWidget('span#login_widget', common_options); |
|
71 | 74 | var toolbar = new maintoolbar.MainToolBar('#maintoolbar-container', { |
|
72 | 75 | notebook: notebook, |
|
73 | 76 | events: events}); |
|
74 | 77 | var quick_help = new quickhelp.QuickHelp({ |
|
75 | 78 | keyboard_manager: keyboard_manager, |
|
76 | 79 | events: events, |
|
77 | 80 | notebook: notebook}); |
|
78 | 81 | var menubar = new menubar.MenuBar('#menubar', $.extend({ |
|
79 | 82 | notebook: notebook, |
|
80 | 83 | layout_manager: layout_manager, |
|
81 | 84 | events: events, |
|
82 | 85 | save_widget: save_widget, |
|
83 | 86 | quick_help: quick_help}, |
|
84 | 87 | common_options)); |
|
85 | 88 | var notification_area = new notificationarea.NotificationArea( |
|
86 | 89 | '#notification_area', { |
|
87 | 90 | events: events, |
|
88 | 91 | save_widget: save_widget, |
|
89 | 92 | notebook: notebook, |
|
90 | 93 | keyboard_manager: keyboard_manager}); |
|
91 | 94 | notification_area.init_notification_widgets(); |
|
92 | 95 | var kernel_selector = new kernelselector.KernelSelector( |
|
93 | 96 | '#kernel_selector_widget', notebook); |
|
94 | 97 | |
|
95 | 98 | $('body').append('<div id="fonttest"><pre><span id="test1">x</span>'+ |
|
96 | 99 | '<span id="test2" style="font-weight: bold;">x</span>'+ |
|
97 | 100 | '<span id="test3" style="font-style: italic;">x</span></pre></div>'); |
|
98 | 101 | var nh = $('#test1').innerHeight(); |
|
99 | 102 | var bh = $('#test2').innerHeight(); |
|
100 | 103 | var ih = $('#test3').innerHeight(); |
|
101 | 104 | if(nh != bh || nh != ih) { |
|
102 | 105 | $('head').append('<style>.CodeMirror span { vertical-align: bottom; }</style>'); |
|
103 | 106 | } |
|
104 | 107 | $('#fonttest').remove(); |
|
105 | 108 | |
|
106 | 109 | page.show(); |
|
107 | 110 | |
|
108 | 111 | layout_manager.do_resize(); |
|
109 | 112 | var first_load = function () { |
|
110 | 113 | layout_manager.do_resize(); |
|
111 | 114 | var hash = document.location.hash; |
|
112 | 115 | if (hash) { |
|
113 | 116 | document.location.hash = ''; |
|
114 | 117 | document.location.hash = hash; |
|
115 | 118 | } |
|
116 | 119 | notebook.set_autosave_interval(notebook.minimum_autosave_interval); |
|
117 | 120 | // only do this once |
|
118 | 121 | events.off('notebook_loaded.Notebook', first_load); |
|
119 | 122 | }; |
|
120 | 123 | events.on('notebook_loaded.Notebook', first_load); |
|
121 | 124 | |
|
122 | 125 | IPython.page = page; |
|
123 | 126 | IPython.layout_manager = layout_manager; |
|
124 | 127 | IPython.notebook = notebook; |
|
125 | 128 | IPython.pager = pager; |
|
126 | 129 | IPython.quick_help = quick_help; |
|
127 | 130 | IPython.login_widget = login_widget; |
|
128 | 131 | IPython.menubar = menubar; |
|
129 | 132 | IPython.toolbar = toolbar; |
|
130 | 133 | IPython.notification_area = notification_area; |
|
131 | 134 | IPython.keyboard_manager = keyboard_manager; |
|
132 | 135 | IPython.save_widget = save_widget; |
|
133 | 136 | IPython.config = user_config; |
|
134 | 137 | IPython.tooltip = notebook.tooltip; |
|
138 | IPython.scrollmanager = scrollmanager; | |
|
135 | 139 | |
|
136 | 140 | events.trigger('app_initialized.NotebookApp'); |
|
137 | 141 | notebook.load_notebook(common_options.notebook_name, common_options.notebook_path); |
|
138 | 142 | |
|
139 | 143 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now