mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-06 11:35:24 +08:00
Merge pull request #1829 from Carreau/notebook_cellmagic_completion
[notebook] don't care about leading prct in completion
This commit is contained in:
commit
cdfc81c542
@ -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)
|
||||
@ -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();
|
||||
@ -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
|
||||
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user