Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions IPython/frontend/html/notebook/static/js/completer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ 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)
Expand All @@ -17,14 +23,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();
Expand All @@ -35,10 +53,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
Expand Down Expand Up @@ -257,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<tab><tab>
// to erase py
var sh = shared_start(this.raw_result);
var sh = shared_start(this.raw_result, true);
if (sh) {
this.insert(sh);
}
Expand Down