##// END OF EJS Templates
notebook: up/down arrow keys move to begin/end of line at top/bottom of cell...
Bradley M. Froehle -
Show More
@@ -234,7 +234,7 b' var IPython = (function (IPython) {'
234
234
235 CodeCell.prototype.at_top = function () {
235 CodeCell.prototype.at_top = function () {
236 var cursor = this.code_mirror.getCursor();
236 var cursor = this.code_mirror.getCursor();
237 if (cursor.line === 0) {
237 if (cursor.line === 0 && cursor.ch === 0) {
238 return true;
238 return true;
239 } else {
239 } else {
240 return false;
240 return false;
@@ -244,7 +244,7 b' var IPython = (function (IPython) {'
244
244
245 CodeCell.prototype.at_bottom = function () {
245 CodeCell.prototype.at_bottom = function () {
246 var cursor = this.code_mirror.getCursor();
246 var cursor = this.code_mirror.getCursor();
247 if (cursor.line === (this.code_mirror.lineCount()-1)) {
247 if (cursor.line === (this.code_mirror.lineCount()-1) && cursor.ch === this.code_mirror.getLine(cursor.line).length) {
248 return true;
248 return true;
249 } else {
249 } else {
250 return false;
250 return false;
@@ -12,6 +12,7 b''
12 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
13
13
14 // TextCell base class
14 // TextCell base class
15 var key = IPython.utils.keycodes;
15
16
16 var TextCell = function () {
17 var TextCell = function () {
17 this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed';
18 this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed';
@@ -269,6 +270,36 b' var IPython = (function (IPython) {'
269 };
270 };
270
271
271
272
273 RawCell.prototype.handle_codemirror_keyevent = function (editor, event) {
274 // This method gets called in CodeMirror's onKeyDown/onKeyPress
275 // handlers and is used to provide custom key handling. Its return
276 // value is used to determine if CodeMirror should ignore the event:
277 // true = ignore, false = don't ignore.
278
279 var that = this;
280 if (event.which === key.UPARROW && event.type === 'keydown') {
281 // If we are not at the top, let CM handle the up arrow and
282 // prevent the global keydown handler from handling it.
283 if (!that.at_top()) {
284 event.stop();
285 return false;
286 } else {
287 return true;
288 };
289 } else if (event.which === key.DOWNARROW && event.type === 'keydown') {
290 // If we are not at the bottom, let CM handle the down arrow and
291 // prevent the global keydown handler from handling it.
292 if (!that.at_bottom()) {
293 event.stop();
294 return false;
295 } else {
296 return true;
297 };
298 };
299 return false;
300 };
301
302
272 RawCell.prototype.select = function () {
303 RawCell.prototype.select = function () {
273 IPython.Cell.prototype.select.apply(this);
304 IPython.Cell.prototype.select.apply(this);
274 this.code_mirror.refresh();
305 this.code_mirror.refresh();
@@ -278,7 +309,7 b' var IPython = (function (IPython) {'
278
309
279 RawCell.prototype.at_top = function () {
310 RawCell.prototype.at_top = function () {
280 var cursor = this.code_mirror.getCursor();
311 var cursor = this.code_mirror.getCursor();
281 if (cursor.line === 0) {
312 if (cursor.line === 0 && cursor.ch === 0) {
282 return true;
313 return true;
283 } else {
314 } else {
284 return false;
315 return false;
@@ -288,7 +319,7 b' var IPython = (function (IPython) {'
288
319
289 RawCell.prototype.at_bottom = function () {
320 RawCell.prototype.at_bottom = function () {
290 var cursor = this.code_mirror.getCursor();
321 var cursor = this.code_mirror.getCursor();
291 if (cursor.line === (this.code_mirror.lineCount()-1)) {
322 if (cursor.line === (this.code_mirror.lineCount()-1) && cursor.ch === this.code_mirror.getLine(cursor.line).length) {
292 return true;
323 return true;
293 } else {
324 } else {
294 return false;
325 return false;
General Comments 0
You need to be logged in to leave comments. Login now