Show More
@@ -199,15 +199,32 var IPython = (function (IPython) { | |||
|
199 | 199 | this.complete.attr('id', 'complete'); |
|
200 | 200 | |
|
201 | 201 | this.sel = $('<select style="width: auto"/>').attr('multiple', 'true').attr('size', Math.min(10, this.raw_result.length)); |
|
202 | //var pos = this.editor.cursorCoords(); | |
|
203 | var cur = this.editor.getCursor(); | |
|
204 | cur.ch = cur.ch-matched_text.length; | |
|
205 | var pos = this.editor.cursorCoords(cur); | |
|
206 | this.complete.css('left', pos.left-3 + 'px'); | |
|
207 | this.complete.css('top', pos.bottom+1 + 'px'); | |
|
208 | 202 | this.complete.append(this.sel); |
|
209 | ||
|
210 | 203 | $('body').append(this.complete); |
|
204 | ||
|
205 | // After everything is on the page compute the postion. | |
|
206 | // We invert the completion list and put it above the code if it is too | |
|
207 | // close to the bottom of the page. | |
|
208 | var cur = this.editor.getCursor(); | |
|
209 | cur.ch = cur.ch-matched_text.length; | |
|
210 | var pos = this.editor.cursorCoords(cur); | |
|
211 | var invert = false; | |
|
212 | var left = pos.left-3; | |
|
213 | var top; | |
|
214 | var cheight = this.complete.height(); | |
|
215 | var wheight = $(window).height(); | |
|
216 | console.log(pos.bottom, cheight, wheight) | |
|
217 | if (pos.bottom+cheight+5 > wheight) { | |
|
218 | invert = true; | |
|
219 | top = pos.top-cheight-4; | |
|
220 | } else { | |
|
221 | invert = false; | |
|
222 | top = pos.bottom+1; | |
|
223 | } | |
|
224 | this.complete.css('left', left + 'px'); | |
|
225 | this.complete.css('top', top + 'px'); | |
|
226 | ||
|
227 | ||
|
211 | 228 | //build the container |
|
212 | 229 | var that = this; |
|
213 | 230 | this.sel.dblclick(function () { |
@@ -218,7 +235,7 var IPython = (function (IPython) { | |||
|
218 | 235 | that.keydown(event); |
|
219 | 236 | }); |
|
220 | 237 | |
|
221 | this.build_gui_list(this.raw_result); | |
|
238 | this.build_gui_list(this.raw_result, invert); | |
|
222 | 239 | |
|
223 | 240 | this.sel.focus(); |
|
224 | 241 | // Opera sometimes ignores focusing a freshly created node |
@@ -232,13 +249,23 var IPython = (function (IPython) { | |||
|
232 | 249 | this.editor.replaceRange(completion.str, completion.from, completion.to); |
|
233 | 250 | } |
|
234 | 251 | |
|
235 | Completer.prototype.build_gui_list = function (completions) { | |
|
236 | // Need to clear the all list | |
|
237 | for (var i = 0; i < completions.length; ++i) { | |
|
238 | var opt = $('<option/>').text(completions[i].str).addClass(completions[i].type); | |
|
239 | this.sel.append(opt); | |
|
252 | Completer.prototype.build_gui_list = function (completions, invert) { | |
|
253 | invert = invert || false; | |
|
254 | if (!invert) { | |
|
255 | for (var i = 0; i < completions.length; ++i) { | |
|
256 | var opt = $('<option/>').text(completions[i].str).addClass(completions[i].type); | |
|
257 | this.sel.append(opt); | |
|
258 | } | |
|
259 | this.sel.children().first().attr('selected', 'true'); | |
|
260 | this.sel.scrollTop(0); | |
|
261 | } else { | |
|
262 | for (var i = (completions.length-1); i > -1; --i) { | |
|
263 | var opt = $('<option/>').text(completions[i].str).addClass(completions[i].type); | |
|
264 | this.sel.append(opt); | |
|
265 | } | |
|
266 | this.sel.children().last().attr('selected', 'true'); | |
|
267 | this.sel.scrollTop(this.sel[0].scrollHeight); | |
|
240 | 268 | } |
|
241 | this.sel.children().first().attr('selected', 'true'); | |
|
242 | 269 | } |
|
243 | 270 | |
|
244 | 271 | Completer.prototype.close = function () { |
General Comments 0
You need to be logged in to leave comments.
Login now