diff --git a/IPython/html/static/base/js/utils.js b/IPython/html/static/base/js/utils.js
index c4659ab..05ea389 100644
--- a/IPython/html/static/base/js/utils.js
+++ b/IPython/html/static/base/js/utils.js
@@ -507,11 +507,12 @@ define([
/**
* turn absolute cursor postion into CodeMirror col, ch cursor
*/
- var i, line;
+ var i, line, next_line;
var offset = 0;
- for (i = 0, line=cm.getLine(i); line !== undefined; i++, line=cm.getLine(i)) {
- if (offset + line.length < cursor_pos) {
- offset += line.length + 1;
+ for (i = 0, next_line=cm.getLine(i); next_line !== undefined; i++, next_line=cm.getLine(i)) {
+ line = next_line;
+ if (offset + next_line.length < cursor_pos) {
+ offset += next_line.length + 1;
} else {
return {
line : i,
@@ -521,8 +522,8 @@ define([
}
// reached end, return endpoint
return {
- ch : line.length - 1,
line : i - 1,
+ ch : line.length - 1,
};
};
diff --git a/IPython/html/static/notebook/js/completer.js b/IPython/html/static/notebook/js/completer.js
index 17f8919..0fb433e 100644
--- a/IPython/html/static/notebook/js/completer.js
+++ b/IPython/html/static/notebook/js/completer.js
@@ -323,9 +323,10 @@ define([
Completer.prototype.keydown = function (event) {
var code = event.keyCode;
- var that = this;
// Enter
+ var options;
+ var index;
if (code == keycodes.enter) {
event.codemirrorIgnore = true;
event._ipkmIgnore = true;
@@ -343,14 +344,11 @@ define([
// like %pylab , pylab have no shred start, and ff will result in py
// to erase py
var sh = shared_start(this.raw_result, true);
- if (sh) {
+ if (sh.str !== '') {
this.insert(sh);
}
this.close();
- //reinvoke self
- setTimeout(function () {
- that.carry_on_completion();
- }, 50);
+ this.carry_on_completion();
} else if (code == keycodes.up || code == keycodes.down) {
// need to do that to be able to move the arrow
// when on the first or last line ofo a code cell
@@ -358,8 +356,8 @@ define([
event._ipkmIgnore = true;
event.preventDefault();
- var options = this.sel.find('option');
- var index = this.sel[0].selectedIndex;
+ options = this.sel.find('option');
+ index = this.sel[0].selectedIndex;
if (code == keycodes.up) {
index--;
}
@@ -371,8 +369,8 @@ define([
} else if (code == keycodes.pageup || code == keycodes.pagedown) {
event._ipkmIgnore = true;
- var options = this.sel.find('option');
- var index = this.sel[0].selectedIndex;
+ options = this.sel.find('option');
+ index = this.sel[0].selectedIndex;
if (code == keycodes.pageup) {
index -= 10; // As 10 is the hard coded size of the drop down menu
} else {