Show More
@@ -52,7 +52,7 b' var IPython = (function (IPython) {' | |||||
52 | // construct a completer |
|
52 | // construct a completer | |
53 | // And give it the function to call to get the completion list |
|
53 | // And give it the function to call to get the completion list | |
54 | var that = this; |
|
54 | var that = this; | |
55 |
this.completer = new IPython.Completer( |
|
55 | this.completer = new IPython.Completer(that); | |
56 | }; |
|
56 | }; | |
57 |
|
57 | |||
58 | //TODO, try to diminish the number of parameters. |
|
58 | //TODO, try to diminish the number of parameters. | |
@@ -260,6 +260,7 b' var IPython = (function (IPython) {' | |||||
260 | // be reclled by finish_completing |
|
260 | // be reclled by finish_completing | |
261 | CodeCell.prototype.requestCompletion= function(callback) |
|
261 | CodeCell.prototype.requestCompletion= function(callback) | |
262 | { |
|
262 | { | |
|
263 | console.log('requestiong through cell'); | |||
263 | this._compcallback = callback; |
|
264 | this._compcallback = callback; | |
264 | var cur = this.code_mirror.getCursor(); |
|
265 | var cur = this.code_mirror.getCursor(); | |
265 | var pre_cursor = this.code_mirror.getRange({line:cur.line,ch:0},cur); |
|
266 | var pre_cursor = this.code_mirror.getRange({line:cur.line,ch:0},cur); | |
@@ -275,28 +276,8 b' var IPython = (function (IPython) {' | |||||
275 | // curent cell for (more) completion merge the resuults with the ones |
|
276 | // curent cell for (more) completion merge the resuults with the ones | |
276 | // comming from the kernel and forward it to the completer |
|
277 | // comming from the kernel and forward it to the completer | |
277 | CodeCell.prototype.finish_completing = function (matched_text, matches) { |
|
278 | CodeCell.prototype.finish_completing = function (matched_text, matches) { | |
278 | // let's build a function that wrap all that stuff into what is needed for the |
|
279 | this.completer.finish_completing(matched_text,matches); | |
279 | // new completer: |
|
280 | } | |
280 | // |
|
|||
281 | var cur = this.code_mirror.getCursor(); |
|
|||
282 | var res = CodeMirror.contextHint(this.code_mirror); |
|
|||
283 |
|
||||
284 | // append the introspection result, in order, at |
|
|||
285 | // at the beginning of the table and compute the replacement rance |
|
|||
286 | // from current cursor positon and matched_text length. |
|
|||
287 | for(var i= matches.length-1; i>=0 ;--i) |
|
|||
288 | { |
|
|||
289 | res.unshift( |
|
|||
290 | { |
|
|||
291 | str : matches[i], |
|
|||
292 | type : "introspection", |
|
|||
293 | from : {line: cur.line, ch: cur.ch-matched_text.length}, |
|
|||
294 | to : {line: cur.line, ch: cur.ch} |
|
|||
295 | } |
|
|||
296 | ) |
|
|||
297 | } |
|
|||
298 | this._compcallback(res); |
|
|||
299 | }; |
|
|||
300 |
|
281 | |||
301 |
|
282 | |||
302 | CodeCell.prototype.select = function () { |
|
283 | CodeCell.prototype.select = function () { |
@@ -49,14 +49,50 b' var IPython = (function(IPython ) {' | |||||
49 | return null; |
|
49 | return null; | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | // user to nsert the given completion |
|
52 | ||
53 |
var Completer = function( |
|
53 | var Completer = function(cell) { | |
54 |
this. |
|
54 | this.cell = cell; | |
55 | this.hintfunc = getHints; |
|
55 | this.editor = cell.code_mirror; | |
|
56 | console.log(this.editor); | |||
56 | // if last caractere before cursor is not in this, we stop completing |
|
57 | // if last caractere before cursor is not in this, we stop completing | |
57 | this.reg = /[A-Za-z.]/; |
|
58 | this.reg = /[A-Za-z.]/; | |
58 | } |
|
59 | } | |
59 |
|
60 | |||
|
61 | Completer.prototype.kernelCompletionRequest = function(){ | |||
|
62 | var cur = this.editor.getCursor(); | |||
|
63 | var pre_cursor = this.editor.getRange({line:cur.line,ch:0},cur); | |||
|
64 | pre_cursor.trim(); | |||
|
65 | // Autocomplete the current line. | |||
|
66 | var line = this.editor.getLine(cur.line); | |||
|
67 | // one could fork here and directly call finish completing | |||
|
68 | // if kernel is busy | |||
|
69 | IPython.notebook.complete_cell(this.cell, line, cur.ch); | |||
|
70 | } | |||
|
71 | ||||
|
72 | Completer.prototype.finish_completing =function (matched_text, matches) { | |||
|
73 | // let's build a function that wrap all that stuff into what is needed for the | |||
|
74 | // new completer: | |||
|
75 | // | |||
|
76 | var cur = this.editor.getCursor(); | |||
|
77 | var res = CodeMirror.contextHint(this.editor); | |||
|
78 | ||||
|
79 | // append the introspection result, in order, at | |||
|
80 | // at the beginning of the table and compute the replacement rance | |||
|
81 | // from current cursor positon and matched_text length. | |||
|
82 | for(var i= matches.length-1; i>=0 ;--i) | |||
|
83 | { | |||
|
84 | res.unshift( | |||
|
85 | { | |||
|
86 | str : matches[i], | |||
|
87 | type : "introspection", | |||
|
88 | from : {line: cur.line, ch: cur.ch-matched_text.length}, | |||
|
89 | to : {line: cur.line, ch: cur.ch} | |||
|
90 | } | |||
|
91 | ) | |||
|
92 | } | |||
|
93 | this._resume_completion(res); | |||
|
94 | }; | |||
|
95 | ||||
60 | Completer.prototype.startCompletion = function() |
|
96 | Completer.prototype.startCompletion = function() | |
61 | { |
|
97 | { | |
62 | // call for a 'first' completion, that will set the editor and do some |
|
98 | // call for a 'first' completion, that will set the editor and do some | |
@@ -93,7 +129,7 b' var IPython = (function(IPython ) {' | |||||
93 | // lets assume for now only one source |
|
129 | // lets assume for now only one source | |
94 | // |
|
130 | // | |
95 | var that = this; |
|
131 | var that = this; | |
96 | this.hintfunc(function(result){that._resume_completion(result)}); |
|
132 | this.kernelCompletionRequest(); | |
97 | } |
|
133 | } | |
98 | Completer.prototype._resume_completion = function(results) |
|
134 | Completer.prototype._resume_completion = function(results) | |
99 | { |
|
135 | { |
General Comments 0
You need to be logged in to leave comments.
Login now