From 49fa32f43bfc2d26f10e3b35d37599fa77bcc785 2011-08-15 06:41:54
From: Brian E. Granger <ellisonbg@gmail.com>
Date: 2011-08-15 06:41:54
Subject: [PATCH] A single tab-completion match is now automatically selected.

---

diff --git a/IPython/frontend/html/notebook/notebookmanager.py b/IPython/frontend/html/notebook/notebookmanager.py
index 0d8bb26..2cc56cb 100644
--- a/IPython/frontend/html/notebook/notebookmanager.py
+++ b/IPython/frontend/html/notebook/notebookmanager.py
@@ -220,7 +220,7 @@ class NotebookManager(LoggingConfigurable):
             else:
                 i = i+1
         notebook_id = self.new_notebook_id(name)
-        nb = current.new_notebook(name=name, id=notebook_id)
+        nb = current.new_notebook(name=name)
         with open(path,'w') as f:
             current.write(nb, f, u'xml')
         return notebook_id
diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js
index 4873fd2..17a178a 100644
--- a/IPython/frontend/html/notebook/static/js/codecell.js
+++ b/IPython/frontend/html/notebook/static/js/codecell.js
@@ -94,6 +94,21 @@ var IPython = (function (IPython) {
 
         var that = this;
         var cur = this.completion_cursor;
+
+        var insert = function (selected_text) {
+            that.code_mirror.replaceRange(
+                selected_text,
+                {line: cur.line, ch: (cur.ch-matched_text.length)},
+                {line: cur.line, ch: cur.ch}
+            );
+        };
+
+        if (matches.length === 1) {
+            insert(matches[0]);
+            setTimeout(function(){that.code_mirror.focus();}, 50);
+            return;
+        };
+
         var complete = $('<div/>').addClass('completions');
         var select = $('<select/>').attr('multiple','true');
         for (var i=0; i<matches.length; ++i) {
@@ -109,14 +124,6 @@ var IPython = (function (IPython) {
         $('body').append(complete);
         var done = false;
 
-        var insert = function (selected_text) {
-            that.code_mirror.replaceRange(
-                selected_text,
-                {line: cur.line, ch: (cur.ch-matched_text.length)},
-                {line: cur.line, ch: cur.ch}
-            );
-        };
-
         var close = function () {
             if (done) return;
             done = true;
diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js
index 6a465a2..f2878e8 100644
--- a/IPython/frontend/html/notebook/static/js/textcell.js
+++ b/IPython/frontend/html/notebook/static/js/textcell.js
@@ -127,7 +127,6 @@ var IPython = (function (IPython) {
 
 
     TextCell.prototype.fromJSON = function (data) {
-        console.log(data);
         if (data.cell_type === this.cell_type) {
             if (data.source !== undefined) {
                 this.set_source(data.source);