##// END OF EJS Templates
more cleaning
Matthias BUSSONNIER -
Show More
@@ -18,7 +18,6 b' var IPython = (function (IPython) {'
18 var CodeCell = function (notebook) {
18 var CodeCell = function (notebook) {
19 this.code_mirror = null;
19 this.code_mirror = null;
20 this.input_prompt_number = null;
20 this.input_prompt_number = null;
21 this.completion_cursor = null;
22 this.outputs = [];
21 this.outputs = [];
23 this.collapsed = false;
22 this.collapsed = false;
24 this.tooltip_timeout = null;
23 this.tooltip_timeout = null;
@@ -254,9 +253,7 b' var IPython = (function (IPython) {'
254 };
253 };
255
254
256
255
257 // called when completion came back from the kernel. this will inspect the
256 // called when completion came back from the kernel. just forward
258 // curent cell for (more) completion merge the resuults with the ones
259 // comming from the kernel and forward it to the completer
260 CodeCell.prototype.finish_completing = function (matched_text, matches) {
257 CodeCell.prototype.finish_completing = function (matched_text, matches) {
261 this.completer.finish_completing(matched_text,matches);
258 this.completer.finish_completing(matched_text,matches);
262 }
259 }
@@ -1,7 +1,6 b''
1 // function completer.
1 // function completer.
2 //
2 //
3 // completer should be a class that take an cell instance
3 // completer should be a class that take an cell instance
4 //
5
4
6 var IPython = (function(IPython ) {
5 var IPython = (function(IPython ) {
7 // that will prevent us from misspelling
6 // that will prevent us from misspelling
@@ -45,11 +44,9 b' var IPython = (function(IPython ) {'
45 }
44 }
46
45
47 Completer.prototype.kernelCompletionRequest = function(){
46 Completer.prototype.kernelCompletionRequest = function(){
48 var cur = this.editor.getCursor();
47 var cur = this.editor.getCursor();
49 // Autocomplete the current line.
50 var line = this.editor.getLine(cur.line);
48 var line = this.editor.getLine(cur.line);
51 // one could fork here and directly call finish completing
49 // one could fork here and directly call finish completing if kernel is busy
52 // if kernel is busy
53 IPython.notebook.complete_cell(this.cell, line, cur.ch);
50 IPython.notebook.complete_cell(this.cell, line, cur.ch);
54 }
51 }
55
52
@@ -65,12 +62,11 b' var IPython = (function(IPython ) {'
65 this.carryOnCompletion(true);
62 this.carryOnCompletion(true);
66 }
63 }
67
64
68 Completer.prototype.carryOnCompletion = function(ff)
65 Completer.prototype.carryOnCompletion = function(ff) {
69 {
66 // Pass true as parameter if you want the commpleter to autopick when
70 // pass true as parameter if you want the commpleter to autopick
67 // only one completion. This function is automatically reinvoked at
71 // when only one completion
68 // each keystroke with ff = false
72 // as this function is automatically reinvoked at each keystroke with
69
73 // ff = false
74 var cur = this.editor.getCursor();
70 var cur = this.editor.getCursor();
75 var pre_cursor = this.editor.getRange({line:cur.line,ch:cur.ch-1},cur);
71 var pre_cursor = this.editor.getRange({line:cur.line,ch:cur.ch-1},cur);
76
72
@@ -80,9 +76,8 b' var IPython = (function(IPython ) {'
80
76
81 this.autopick = false;
77 this.autopick = false;
82 if( ff != 'undefined' && ff==true)
78 if( ff != 'undefined' && ff==true)
83 {
79 { this.autopick=true; }
84 this.autopick=true;
80
85 }
86 // We want a single cursor position.
81 // We want a single cursor position.
87 if (this.editor.somethingSelected()) return;
82 if (this.editor.somethingSelected()) return;
88
83
@@ -91,25 +86,23 b' var IPython = (function(IPython ) {'
91 }
86 }
92
87
93 Completer.prototype.finish_completing =function (matched_text, matches) {
88 Completer.prototype.finish_completing =function (matched_text, matches) {
94 // let's build a function that wrap all that stuff into what is needed for the
89 // let's build a function that wrap all that stuff into what is needed
95 // new completer:
90 // for the new completer:
96 //
91
97 var cur = this.editor.getCursor();
92 var cur = this.editor.getCursor();
98 var results = CodeMirror.contextHint(this.editor);
93 var results = CodeMirror.contextHint(this.editor);
99
94
100 // append the introspection result, in order, at
95 // append the introspection result, in order, at at the beginning of
101 // at the beginning of the table and compute the replacement rance
96 // the table and compute the replacement range from current cursor
102 // from current cursor positon and matched_text length.
97 // positon and matched_text length.
103 for(var i= matches.length-1; i>=0 ;--i)
98 for(var i= matches.length-1; i>=0 ;--i)
104 {
99 {
105 results.unshift(
100 results.unshift(
106 {
101 { str : matches[i],
107 str : matches[i],
108 type : "introspection",
102 type : "introspection",
109 from : {line: cur.line, ch: cur.ch-matched_text.length},
103 from : {line: cur.line, ch: cur.ch-matched_text.length},
110 to : {line: cur.line, ch: cur.ch}
104 to : {line: cur.line, ch: cur.ch}
111 }
105 })
112 )
113 }
106 }
114
107
115 // one the 2 sources results have been merge, deal with it
108 // one the 2 sources results have been merge, deal with it
@@ -127,15 +120,13 b' var IPython = (function(IPython ) {'
127
120
128 if (this.raw_result.length == 1)
121 if (this.raw_result.length == 1)
129 {
122 {
130 // test if first and only completion totally matches
123 // test if first and only completion totally matches
131 // what is typed, in this case dismiss
124 // what is typed, in this case dismiss
132 var str = this.raw_result[0].str
125 var str = this.raw_result[0].str
133 var cur = this.editor.getCursor();
126 var cur = this.editor.getCursor();
134 var pre_cursor = this.editor.getRange({line:cur.line,ch:cur.ch-str.length},cur);
127 var pre_cursor = this.editor.getRange({line:cur.line,ch:cur.ch-str.length},cur);
135 if(pre_cursor == str){
128 if(pre_cursor == str)
136 this.close();
129 { this.close(); return ; }
137 return ;
138 }
139 }
130 }
140
131
141 this.complete = $('<div/>').addClass('completions');
132 this.complete = $('<div/>').addClass('completions');
@@ -160,12 +151,10 b' var IPython = (function(IPython ) {'
160 this.sel.keydown(function(event){that.keydown(event)});
151 this.sel.keydown(function(event){that.keydown(event)});
161
152
162 this.build_gui_list(this.raw_result);
153 this.build_gui_list(this.raw_result);
163 //CodeMirror.connect(that.sel, "dblclick", function(){that.pick()});
164
154
165 this.sel.focus();
155 this.sel.focus();
166 // Opera sometimes ignores focusing a freshly created node
156 // Opera sometimes ignores focusing a freshly created node
167 if (window.opera) setTimeout(function(){if (!this.done) this.sel.focus();}, 100);
157 if (window.opera) setTimeout(function(){if (!this.done) this.sel.focus();}, 100);
168 // why do we return true ?
169 return true;
158 return true;
170 }
159 }
171
160
@@ -182,11 +171,6 b' var IPython = (function(IPython ) {'
182 this.sel.append(opt);
171 this.sel.append(opt);
183 }
172 }
184 this.sel.children().first().attr('selected','true');
173 this.sel.children().first().attr('selected','true');
185
186 //sel.size = Math.min(10, completions.length);
187 // Hack to hide the scrollbar.
188 //if (completions.length <= 10)
189 //this.complete.style.width = (this.sel.clientWidth - 1) + "px";
190 }
174 }
191
175
192 Completer.prototype.close = function() {
176 Completer.prototype.close = function() {
General Comments 0
You need to be logged in to leave comments. Login now