Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Better handling of up/down arrows for CodeCells.

  • Loading branch information...
commit e27040303a16d228abe740bd8d52bf74bbb639ad 1 parent f5911d3
@ellisonbg ellisonbg authored
Showing with 36 additions and 6 deletions.
  1. +36 −6 IPython/frontend/html/notebook/static/js/notebook.js
View
42 IPython/frontend/html/notebook/static/js/notebook.js
@@ -88,12 +88,22 @@ Notebook.prototype.bind_events = function () {
var that = this;
$(document).keydown(function (event) {
// console.log(event);
- if (event.which == 38 && event.shiftKey) {
- event.preventDefault();
- that.select_prev();
- } else if (event.which == 40 && event.shiftKey) {
- event.preventDefault();
- that.select_next();
+ if (event.which == 38) {
+ var cell = that.selected_cell();
+ if (cell instanceof CodeCell) {
+ if (cell.at_top()) {
+ event.preventDefault();
+ that.select_prev();
+ };
+ };
+ } else if (event.which == 40) {
+ var cell = that.selected_cell();
+ if (cell instanceof CodeCell) {
+ if (cell.at_bottom()) {
+ event.preventDefault();
+ that.select_next();
+ };
+ };
} else if (event.which == 13 && event.shiftKey) {
// The focus is not quite working here.
var cell = that.selected_cell();
@@ -782,6 +792,26 @@ CodeCell.prototype.set_code = function (code) {
};
+CodeCell.prototype.at_top = function () {
+ var cursor = this.code_mirror.getCursor();
+ if (cursor.line === 0) {
+ return true;
+ } else {
+ return false;
+ }
+};
+
+
+CodeCell.prototype.at_bottom = function () {
+ var cursor = this.code_mirror.getCursor();
+ if (cursor.line === (this.code_mirror.lineCount()-1)) {
+ return true;
+ } else {
+ return false;
+ }
+};
+
+
CodeCell.prototype.fromJSON = function (data) {
if (data.cell_type === 'code') {
this.set_code(data.code);
Please sign in to comment.
Something went wrong with that request. Please try again.