##// END OF EJS Templates
Lots of updates and changes....
Brian E. Granger -
Show More
@@ -120,8 +120,37 b' var IPython = (function (IPython) {'
120 120 };
121 121 });
122 122 that.element.focusout(function (event) {
123 var is_or_has = function (a, b) {
124 // Is b a child of a or a itself?
125 return a.has(b).length !==0 || a.is(b);
126 }
123 127 if (that.mode === 'edit') {
124 $([IPython.events]).trigger('command_mode.Cell', {'cell':that});
128 setTimeout(function () {
129 var trigger = true;
130 var target = $(document.activeElement);
131 var completer = that.element.find($('div.completions'));
132 var tooltip = $('div#tooltip')
133 if (target.length > 0) {
134 // If the focused element (target) is inside the cell
135 // (that.element) don't enter command mode.
136 if (is_or_has(that.element, target)) {
137 trigger = false;
138 // The focused element is outside the cell
139 } else {
140 // If the focused element is the tooltip or completer
141 // don't enter command mode, otherwise do.
142 trigger = true;
143 if (tooltip.length > 0 && is_or_has(tooltip, target)) {
144 trigger = false;
145 } else if (completer.length > 0 && is_or_has(completer, target)) {
146 trigger = false;
147 }
148 }
149 }
150 if (trigger) {
151 $([IPython.events]).trigger('command_mode.Cell', {'cell':that});
152 }
153 }, 1);
125 154 };
126 155 });
127 156 if (this.code_mirror) {
@@ -74,7 +74,7 b' var IPython = (function (IPython) {'
74 74
75 75
76 76 var cm_overwrite_options = {
77 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
77 onKeyEvent: $.proxy(this.handle_keyevent,this)
78 78 };
79 79
80 80 options = this.mergeopt(CodeCell, options, {cm_config:cm_overwrite_options});
@@ -149,6 +149,17 b' var IPython = (function (IPython) {'
149 149 );
150 150 };
151 151
152 CodeCell.prototype.handle_keyevent = function (editor, event) {
153
154 console.log('CM', this.mode, event.which, event.type)
155
156 if (this.mode === 'command') {
157 return true;
158 } else if (this.mode === 'edit') {
159 return this.handle_codemirror_keyevent(editor, event);
160 }
161 };
162
152 163 /**
153 164 * This method gets called in CodeMirror's onKeyDown/onKeyPress
154 165 * handlers and is used to provide custom key handling. Its return
@@ -157,61 +168,55 b' var IPython = (function (IPython) {'
157 168 * @method handle_codemirror_keyevent
158 169 */
159 170 CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) {
171
160 172 var that = this;
173 // whatever key is pressed, first, cancel the tooltip request before
174 // they are sent, and remove tooltip if any, except for tab again
175 if (event.type === 'keydown' && event.which != key.TAB ) {
176 IPython.tooltip.remove_and_cancel_tooltip();
177 }
161 178
162 if (this.mode === 'command') {
163 return true;
164 } else if (this.mode === 'edit') {
165 // whatever key is pressed, first, cancel the tooltip request before
166 // they are sent, and remove tooltip if any, except for tab again
167 if (event.type === 'keydown' && event.which != key.TAB ) {
168 IPython.tooltip.remove_and_cancel_tooltip();
169 };
170
171 var cur = editor.getCursor();
172 if (event.keyCode === key.ENTER){
173 this.auto_highlight();
174 }
179 var cur = editor.getCursor();
180 if (event.keyCode === key.ENTER){
181 this.auto_highlight();
182 }
175 183
176 if (event.keyCode === key.ENTER && (event.shiftKey || event.ctrlKey || event.altKey)) {
177 // Always ignore shift-enter in CodeMirror as we handle it.
184 if (event.keyCode === key.ENTER && (event.shiftKey || event.ctrlKey)) {
185 // Always ignore shift-enter in CodeMirror as we handle it.
186 return true;
187 } else if (event.which === 40 && event.type === 'keypress' && IPython.tooltip.time_before_tooltip >= 0) {
188 // triger on keypress (!) otherwise inconsistent event.which depending on plateform
189 // browser and keyboard layout !
190 // Pressing '(' , request tooltip, don't forget to reappend it
191 // The second argument says to hide the tooltip if the docstring
192 // is actually empty
193 IPython.tooltip.pending(that, true);
194 } else if (event.which === key.UPARROW && event.type === 'keydown') {
195 // If we are not at the top, let CM handle the up arrow and
196 // prevent the global keydown handler from handling it.
197 if (!that.at_top()) {
198 event.stop();
199 return false;
200 } else {
178 201 return true;
179
180 } else if (event.which === 40 && event.type === 'keypress' && IPython.tooltip.time_before_tooltip >= 0) {
181 // triger on keypress (!) otherwise inconsistent event.which depending on plateform
182 // browser and keyboard layout !
183 // Pressing '(' , request tooltip, don't forget to reappend it
184 // The second argument says to hide the tooltip if the docstring
185 // is actually empty
186 IPython.tooltip.pending(that, true);
187 } else if (event.which === key.UPARROW && event.type === 'keydown') {
188 // If we are not at the top, let CM handle the up arrow and
189 // prevent the global keydown handler from handling it.
190 if (!that.at_top()) {
191 event.stop();
192 return false;
193 } else {
194 return true;
195 };
196 } else if (event.which === key.ESC) {
197 IPython.tooltip.remove_and_cancel_tooltip(true);
202 }
203 } else if (event.which === key.ESC) {
204 return IPython.tooltip.remove_and_cancel_tooltip(true);
205 } else if (event.which === key.DOWNARROW && event.type === 'keydown') {
206 // If we are not at the bottom, let CM handle the down arrow and
207 // prevent the global keydown handler from handling it.
208 if (!that.at_bottom()) {
209 event.stop();
210 return false;
211 } else {
198 212 return true;
199 } else if (event.which === key.DOWNARROW && event.type === 'keydown') {
200 // If we are not at the bottom, let CM handle the down arrow and
201 // prevent the global keydown handler from handling it.
202 if (!that.at_bottom()) {
203 event.stop();
204 return false;
205 } else {
206 return true;
207 };
208 } else if (event.keyCode === key.TAB && event.type == 'keydown' && event.shiftKey) {
209 if (editor.somethingSelected()){
210 var anchor = editor.getCursor("anchor");
211 var head = editor.getCursor("head");
212 if( anchor.line != head.line){
213 return false;
214 }
213 }
214 } else if (event.keyCode === key.TAB && event.type == 'keydown' && event.shiftKey) {
215 if (editor.somethingSelected()){
216 var anchor = editor.getCursor("anchor");
217 var head = editor.getCursor("head");
218 if( anchor.line != head.line){
219 return false;
215 220 }
216 221 }
217 222 IPython.tooltip.request(that);
@@ -229,16 +234,18 b' var IPython = (function (IPython) {'
229 234 // is empty. In this case, let CodeMirror handle indentation.
230 235 return false;
231 236 } else {
232 // keypress/keyup also trigger on TAB press, and we don't want to
233 // use those to disable tab completion.
234 return false;
235 };
237 event.stop();
238 this.completer.startCompletion();
239 return true;
240 }
241 } else {
242 // keypress/keyup also trigger on TAB press, and we don't want to
243 // use those to disable tab completion.
236 244 return false;
237 245 }
238 246 return false;
239 247 };
240 248
241
242 249 // Kernel related calls.
243 250
244 251 CodeCell.prototype.set_kernel = function (kernel) {
@@ -244,28 +244,24 b' var IPython = (function (IPython) {'
244 244
245 245 //build the container
246 246 var that = this;
247 // this.sel.dblclick(function () {
248 // that.pick();
249 // });
250 // this.sel.blur(this.close);
251 // this.sel.keydown(function (event) {
252 // that.keydown(event);
253 // });
247 this.sel.dblclick(function () {
248 that.pick();
249 });
250 this.sel.blur(this.close);
251 this.sel.keydown(function (event) {
252 that.keydown(event);
253 });
254 254
255 255 this.build_gui_list(this.raw_result);
256 256
257 setTimeout(function () {
258 console.log('doing it');
259 that.sel.focus();
260 }, 100);
261 // this.sel.focus();
257 this.sel.focus();
262 258 // This needs to be after the focus() call because that puts the notebook into
263 259 // command mode.
264 // IPython.keyboard_manager.null_mode();
260 IPython.keyboard_manager.null_mode();
265 261 // Opera sometimes ignores focusing a freshly created node
266 // if (window.opera) setTimeout(function () {
267 // if (!this.done) this.sel.focus();
268 // }, 100);
262 if (window.opera) setTimeout(function () {
263 if (!this.done) this.sel.focus();
264 }, 100);
269 265 return true;
270 266 }
271 267
@@ -286,7 +282,6 b' var IPython = (function (IPython) {'
286 282 if (this.done) return;
287 283 this.done = true;
288 284 $('.completions').remove();
289 console.log('closing...')
290 285 IPython.keyboard_manager.edit_mode();
291 286 }
292 287
@@ -301,7 +296,6 b' var IPython = (function (IPython) {'
301 296
302 297
303 298 Completer.prototype.keydown = function (event) {
304 console.log('keydown', event.keyCode);
305 299 var code = event.keyCode;
306 300 var that = this;
307 301 var special_key = false;
@@ -15,8 +15,8 b' var IPython = (function (IPython) {'
15 15 var key = IPython.utils.keycodes;
16 16
17 17 var KeyboardManager = function () {
18 this.mode = 'null';
19 this.last_mode = 'null';
18 this.mode = 'command';
19 this.last_mode = 'command';
20 20 this.bind_events();
21 21 };
22 22
@@ -30,7 +30,7 b' var IPython = (function (IPython) {'
30 30 KeyboardManager.prototype.handle_keydown = function (event) {
31 31 var notebook = IPython.notebook;
32 32
33 console.log('keyboard_manager', this.mode, event);
33 console.log('keyboard_manager', this.mode, event.keyCode);
34 34
35 35 if (event.which === key.ESC) {
36 36 // Intercept escape at highest level to avoid closing
@@ -39,7 +39,7 b' var IPython = (function (IPython) {'
39 39 }
40 40
41 41 if (this.mode === 'null') {
42 return this.handle_edit_mode(event);
42 return this.handle_null_mode(event);
43 43 }
44 44
45 45 // Event handlers for both command and edit mode
@@ -252,16 +252,19 b' var IPython = (function (IPython) {'
252 252 };
253 253
254 254 KeyboardManager.prototype.edit_mode = function () {
255 console.log('KeyboardManager', 'changing to edit mode');
255 256 this.last_mode = this.mode;
256 257 this.mode = 'edit';
257 258 }
258 259
259 260 KeyboardManager.prototype.command_mode = function () {
261 console.log('KeyboardManager', 'changing to command mode');
260 262 this.last_mode = this.mode;
261 263 this.mode = 'command';
262 264 }
263 265
264 266 KeyboardManager.prototype.null_mode = function () {
267 console.log('KeyboardManager', 'changing to null mode');
265 268 this.last_mode = this.mode;
266 269 this.mode = 'null';
267 270 }
@@ -38,6 +38,8 b' var IPython = (function (IPython) {'
38 38 this.undelete_index = null;
39 39 this.undelete_below = false;
40 40 this.paste_enabled = false;
41 // It is important to start out in command mode to match the intial mode
42 // of the KeyboardManager.
41 43 this.mode = 'command';
42 44 this.set_dirty(false);
43 45 this.metadata = {};
@@ -521,27 +523,27 b' var IPython = (function (IPython) {'
521 523
522 524 Notebook.prototype.command_mode = function () {
523 525 if (this.mode !== 'command') {
526 console.log('\nNotebook', 'changing to command mode');
524 527 var index = this.get_edit_index();
525 528 var cell = this.get_cell(index);
526 529 if (cell) {
527 530 cell.command_mode();
528 this.mode = 'command';
529 531 };
532 this.mode = 'command';
533 IPython.keyboard_manager.command_mode();
530 534 };
531 IPython.keyboard_manager.command_mode();
532 535 };
533 536
534 537 Notebook.prototype.edit_mode = function () {
535 538 if (this.mode !== 'edit') {
536 // We are in command mode so get_edit_index() is null!!!
537 var index = this.get_selected_index();
538 if (index === null) {return;} // No cell is selected
539 var cell = this.get_cell(index);
540 if (cell) {
541 cell.edit_mode();
542 this.mode = 'edit';
543 };
539 console.log('\nNotebook', 'changing to edit mode');
540 var cell = this.get_selected_cell();
541 if (cell === null) {return;} // No cell is selected
542 // We need to set the mode to edit to prevent reentering this method
543 // when cell.edit_mode() is called below.
544 this.mode = 'edit';
544 545 IPython.keyboard_manager.edit_mode();
546 cell.edit_mode();
545 547 };
546 548 };
547 549
@@ -41,7 +41,7 b' var IPython = (function (IPython) {'
41 41
42 42 // we cannot put this as a class key as it has handle to "this".
43 43 var cm_overwrite_options = {
44 onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
44 onKeyEvent: $.proxy(this.handle_keyevent,this)
45 45 };
46 46
47 47 options = this.mergeopt(TextCell,options,{cm_config:cm_overwrite_options});
@@ -109,6 +109,16 b' var IPython = (function (IPython) {'
109 109 });
110 110 };
111 111
112 TextCell.prototype.handle_keyevent = function (editor, event) {
113
114 console.log('CM', this.mode, event.which, event.type)
115
116 if (this.mode === 'command') {
117 return true;
118 } else if (this.mode === 'edit') {
119 return this.handle_codemirror_keyevent(editor, event);
120 }
121 };
112 122
113 123 /**
114 124 * This method gets called in CodeMirror's onKeyDown/onKeyPress
@@ -123,33 +133,29 b' var IPython = (function (IPython) {'
123 133 */
124 134 TextCell.prototype.handle_codemirror_keyevent = function (editor, event) {
125 135 var that = this;
126 if (this.mode === 'command') {
127 return false
128 } else if (this.mode === 'edit') {
129 if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey || event.altKey)) {
130 // Always ignore shift-enter in CodeMirror as we handle it.
136
137 if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey || event.altKey)) {
138 // Always ignore shift-enter in CodeMirror as we handle it.
139 return true;
140 } else if (event.which === key.UPARROW && event.type === 'keydown') {
141 // If we are not at the top, let CM handle the up arrow and
142 // prevent the global keydown handler from handling it.
143 if (!that.at_top()) {
144 event.stop();
145 return false;
146 } else {
131 147 return true;
132 } else if (event.which === key.UPARROW && event.type === 'keydown') {
133 // If we are not at the top, let CM handle the up arrow and
134 // prevent the global keydown handler from handling it.
135 if (!that.at_top()) {
136 event.stop();
137 return false;
138 } else {
139 return true;
140 };
141 } else if (event.which === key.DOWNARROW && event.type === 'keydown') {
142 // If we are not at the bottom, let CM handle the down arrow and
143 // prevent the global keydown handler from handling it.
144 if (!that.at_bottom()) {
145 event.stop();
146 return false;
147 } else {
148 return true;
149 };
150 }
151 return false;
152 };
148 };
149 } else if (event.which === key.DOWNARROW && event.type === 'keydown') {
150 // If we are not at the bottom, let CM handle the down arrow and
151 // prevent the global keydown handler from handling it.
152 if (!that.at_bottom()) {
153 event.stop();
154 return false;
155 } else {
156 return true;
157 };
158 }
153 159 return false;
154 160 };
155 161
General Comments 0
You need to be logged in to leave comments. Login now