From 869e697c339cb20271de58bda8140ccc6aa14327 2014-03-17 22:48:36 From: Paul Ivanov Date: 2014-03-17 22:48:36 Subject: [PATCH] go to appropriate line when coming from another cell Sets the cursor on the last line of the cell when moved up from the top of the cell below, and sets the cursors to the first line when moving down from the bottom of a last line. Here, we retain the character that the cursor was on, so that users wishing to have up-down functionality like one document can still use this shortcut handler and simple adjust the at_top and at_bottom methods --- diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js index 04d1091..73e5198 100644 --- a/IPython/html/static/notebook/js/keyboardmanager.js +++ b/IPython/html/static/notebook/js/keyboardmanager.js @@ -107,12 +107,16 @@ var IPython = (function (IPython) { IPython.notebook.command_mode(); IPython.notebook.select_prev(); IPython.notebook.edit_mode(); + var cm = IPython.notebook.get_selected_cell().code_mirror; + var prev_cursor = cell.code_mirror.getCursor(); + cm.setCursor(cm.lastLine(), prev_cursor.ch) return false; } else if (cell) { var cm = cell.code_mirror; var cursor = cm.getCursor(); cursor.line -= 1; cm.setCursor(cursor); + return false; } } } @@ -129,12 +133,16 @@ var IPython = (function (IPython) { IPython.notebook.command_mode(); IPython.notebook.select_next(); IPython.notebook.edit_mode(); + var cm = IPython.notebook.get_selected_cell().code_mirror; + var prev_cursor = cell.code_mirror.getCursor(); + cm.setCursor(0, prev_cursor.ch); return false; } else if (cell) { var cm = cell.code_mirror; var cursor = cm.getCursor(); cursor.line += 1; cm.setCursor(cursor); + return false; } } }