From a3f1e57e8615c67ba93f5181289af1142d14646a Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Fri, 1 Jun 2012 14:39:36 +0200 Subject: [PATCH 1/2] don't care about lleading prct in completion mainly to avoid weird shared start with cell magics --- .../html/notebook/static/js/completer.js | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/completer.js b/IPython/frontend/html/notebook/static/js/completer.js index a51c8b079c9..04e01b23be8 100644 --- a/IPython/frontend/html/notebook/static/js/completer.js +++ b/IPython/frontend/html/notebook/static/js/completer.js @@ -8,6 +8,13 @@ var IPython = (function (IPython) { // easyier key mapping var key = IPython.utils.keycodes; + function prepend_n_prc(str,n) + { + for( var i =0; i< n;i++) + { str = '%'+str } + return str; + } + function _existing_completion(item, completion_array){ for( var c in completion_array ) { if(completion_array[c].substr(-item.length) == item) @@ -17,14 +24,26 @@ var IPython = (function (IPython) { } // what is the common start of all completions - function shared_start(B) { + function shared_start(B,drop_prct) { if (B.length == 1) { return B[0]; } var A = new Array(); + var common; + var min_lead_prct = 10; for (var i = 0; i < B.length; i++) { - A.push(B[i].str); + var str = B[i].str + var localmin = 0 + if(drop_prct == true){ + while ( str.substr(0,1) == '%') { + localmin = localmin+1; + str = str.substring(1); + } + } + min_lead_prct = Math.min(min_lead_prct,localmin); + A.push(str); } + if (A.length > 1) { var tem1, tem2, s; A = A.slice(0).sort(); @@ -35,10 +54,10 @@ var IPython = (function (IPython) { tem1 = tem1.substring(0, --s); } if (tem1 == "" || tem2.indexOf(tem1) != 0) { - return null; + return prepend_n_prc('',min_lead_prct); } return { - str: tem1, + str: prepend_n_prc(tem1,min_lead_prct), type: "computed", from: B[0].from, to: B[0].to @@ -257,7 +276,7 @@ var IPython = (function (IPython) { //Check that shared start is not null which can append with prefixed completion // like %pylab , pylab have no shred start, and ff will result in py // to erase py - var sh = shared_start(this.raw_result); + var sh = shared_start(this.raw_result,true); if (sh) { this.insert(sh); } From 4904b2de2efec332a93d02a933fb763de6d08f2a Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Mon, 4 Jun 2012 23:17:18 +0200 Subject: [PATCH 2/2] pep8 --- .../html/notebook/static/js/completer.js | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/completer.js b/IPython/frontend/html/notebook/static/js/completer.js index 04e01b23be8..1e2a2874fa9 100644 --- a/IPython/frontend/html/notebook/static/js/completer.js +++ b/IPython/frontend/html/notebook/static/js/completer.js @@ -8,9 +8,8 @@ var IPython = (function (IPython) { // easyier key mapping var key = IPython.utils.keycodes; - function prepend_n_prc(str,n) - { - for( var i =0; i< n;i++) + function prepend_n_prc(str, n) { + for( var i =0 ; i< n ; i++) { str = '%'+str } return str; } @@ -24,7 +23,7 @@ var IPython = (function (IPython) { } // what is the common start of all completions - function shared_start(B,drop_prct) { + function shared_start(B, drop_prct) { if (B.length == 1) { return B[0]; } @@ -32,15 +31,15 @@ var IPython = (function (IPython) { var common; var min_lead_prct = 10; for (var i = 0; i < B.length; i++) { - var str = B[i].str - var localmin = 0 + var str = B[i].str; + var localmin = 0; if(drop_prct == true){ - while ( str.substr(0,1) == '%') { + while ( str.substr(0, 1) == '%') { localmin = localmin+1; str = str.substring(1); } } - min_lead_prct = Math.min(min_lead_prct,localmin); + min_lead_prct = Math.min(min_lead_prct, localmin); A.push(str); } @@ -54,10 +53,10 @@ var IPython = (function (IPython) { tem1 = tem1.substring(0, --s); } if (tem1 == "" || tem2.indexOf(tem1) != 0) { - return prepend_n_prc('',min_lead_prct); + return prepend_n_prc('', min_lead_prct); } return { - str: prepend_n_prc(tem1,min_lead_prct), + str: prepend_n_prc(tem1, min_lead_prct), type: "computed", from: B[0].from, to: B[0].to @@ -276,7 +275,7 @@ var IPython = (function (IPython) { //Check that shared start is not null which can append with prefixed completion // like %pylab , pylab have no shred start, and ff will result in py // to erase py - var sh = shared_start(this.raw_result,true); + var sh = shared_start(this.raw_result, true); if (sh) { this.insert(sh); }