mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-24 12:05:22 +08:00
clean code, remove duplicate unused lines
This commit is contained in:
parent
6a658a6fa8
commit
cf19389cdd
@ -50,9 +50,7 @@ var IPython = (function (IPython) {
|
||||
this.collapse();
|
||||
|
||||
// construct a completer
|
||||
// And give it the function to call to get the completion list
|
||||
var that = this;
|
||||
this.completer = new IPython.Completer(that);
|
||||
this.completer = new IPython.Completer(this);
|
||||
};
|
||||
|
||||
//TODO, try to diminish the number of parameters.
|
||||
@ -255,22 +253,6 @@ var IPython = (function (IPython) {
|
||||
// setTimeout(that.remove_and_cancel_tooltip, 5000);
|
||||
};
|
||||
|
||||
// As you type completer
|
||||
// this should be called by the completer, that in return will
|
||||
// be reclled by finish_completing
|
||||
CodeCell.prototype.requestCompletion= function(callback)
|
||||
{
|
||||
console.log('requestiong through cell');
|
||||
this._compcallback = callback;
|
||||
var cur = this.code_mirror.getCursor();
|
||||
var pre_cursor = this.code_mirror.getRange({line:cur.line,ch:0},cur);
|
||||
pre_cursor.trim();
|
||||
// Autocomplete the current line.
|
||||
var line = this.code_mirror.getLine(cur.line);
|
||||
// one could fork here and directly call finish completing
|
||||
// if kernel is busy
|
||||
IPython.notebook.complete_cell(this, line, cur.ch);
|
||||
}
|
||||
|
||||
// called when completion came back from the kernel. this will inspect the
|
||||
// curent cell for (more) completion merge the resuults with the ones
|
||||
|
@ -1,23 +1,10 @@
|
||||
// function completer.
|
||||
//
|
||||
// completer should be a class that take an editor instance, and a list of
|
||||
// function to call to get the list of completion.
|
||||
//
|
||||
// the function that send back the list of completion should received the
|
||||
// editor handle as sole argument, and should return a json object with the
|
||||
// following structure
|
||||
|
||||
// {list: clist, # list of n string containing the completions
|
||||
// type : rp, # list of n string containingtype/ origin of the completion
|
||||
// # (will be set as the class of the <option> to be able to style
|
||||
// # them according to the origin of the completion)
|
||||
// from: {line: cur.line, ch: token.start},
|
||||
// to: {line: cur.line, ch: token.end}
|
||||
// };
|
||||
// completer should be a class that take an cell instance
|
||||
//
|
||||
|
||||
var IPython = (function(IPython ) {
|
||||
// that will prevent us froom missspelling
|
||||
// that will prevent us from misspelling
|
||||
"use strict";
|
||||
|
||||
// easyier key mapping
|
||||
@ -53,15 +40,12 @@ var IPython = (function(IPython ) {
|
||||
var Completer = function(cell) {
|
||||
this.cell = cell;
|
||||
this.editor = cell.code_mirror;
|
||||
console.log(this.editor);
|
||||
// if last caractere before cursor is not in this, we stop completing
|
||||
this.reg = /[A-Za-z.]/;
|
||||
}
|
||||
|
||||
Completer.prototype.kernelCompletionRequest = function(){
|
||||
var cur = this.editor.getCursor();
|
||||
var pre_cursor = this.editor.getRange({line:cur.line,ch:0},cur);
|
||||
pre_cursor.trim();
|
||||
// Autocomplete the current line.
|
||||
var line = this.editor.getLine(cur.line);
|
||||
// one could fork here and directly call finish completing
|
||||
@ -69,29 +53,6 @@ var IPython = (function(IPython ) {
|
||||
IPython.notebook.complete_cell(this.cell, line, cur.ch);
|
||||
}
|
||||
|
||||
Completer.prototype.finish_completing =function (matched_text, matches) {
|
||||
// let's build a function that wrap all that stuff into what is needed for the
|
||||
// new completer:
|
||||
//
|
||||
var cur = this.editor.getCursor();
|
||||
var res = CodeMirror.contextHint(this.editor);
|
||||
|
||||
// append the introspection result, in order, at
|
||||
// at the beginning of the table and compute the replacement rance
|
||||
// from current cursor positon and matched_text length.
|
||||
for(var i= matches.length-1; i>=0 ;--i)
|
||||
{
|
||||
res.unshift(
|
||||
{
|
||||
str : matches[i],
|
||||
type : "introspection",
|
||||
from : {line: cur.line, ch: cur.ch-matched_text.length},
|
||||
to : {line: cur.line, ch: cur.ch}
|
||||
}
|
||||
)
|
||||
}
|
||||
this._resume_completion(res);
|
||||
};
|
||||
|
||||
Completer.prototype.startCompletion = function()
|
||||
{
|
||||
@ -108,12 +69,12 @@ var IPython = (function(IPython ) {
|
||||
{
|
||||
// pass true as parameter if you want the commpleter to autopick
|
||||
// when only one completion
|
||||
// as this function is auto;atically reinvoked at each keystroke with
|
||||
// as this function is automatically reinvoked at each keystroke with
|
||||
// ff = false
|
||||
var cur = this.editor.getCursor();
|
||||
var pre_cursor = this.editor.getRange({line:cur.line,ch:cur.ch-1},cur);
|
||||
|
||||
// we nned to check that we are still on a word boundary
|
||||
// we need to check that we are still on a word boundary
|
||||
// because while typing the completer is still reinvoking itself
|
||||
if(!this.reg.test(pre_cursor)){ this.close(); return;}
|
||||
|
||||
@ -125,21 +86,38 @@ var IPython = (function(IPython ) {
|
||||
// We want a single cursor position.
|
||||
if (this.editor.somethingSelected()) return;
|
||||
|
||||
// there we will need to gather the results for all the function (and merge them ?)
|
||||
// lets assume for now only one source
|
||||
//
|
||||
var that = this;
|
||||
//one kernel completion came back, finish_completing will be called with the results
|
||||
this.kernelCompletionRequest();
|
||||
}
|
||||
Completer.prototype._resume_completion = function(results)
|
||||
{
|
||||
|
||||
Completer.prototype.finish_completing =function (matched_text, matches) {
|
||||
// let's build a function that wrap all that stuff into what is needed for the
|
||||
// new completer:
|
||||
//
|
||||
var cur = this.editor.getCursor();
|
||||
var results = CodeMirror.contextHint(this.editor);
|
||||
|
||||
// append the introspection result, in order, at
|
||||
// at the beginning of the table and compute the replacement rance
|
||||
// from current cursor positon and matched_text length.
|
||||
for(var i= matches.length-1; i>=0 ;--i)
|
||||
{
|
||||
results.unshift(
|
||||
{
|
||||
str : matches[i],
|
||||
type : "introspection",
|
||||
from : {line: cur.line, ch: cur.ch-matched_text.length},
|
||||
to : {line: cur.line, ch: cur.ch}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// one the 2 sources results have been merge, deal with it
|
||||
this.raw_result = results;
|
||||
|
||||
// if empty result return
|
||||
if (!this.raw_result || !this.raw_result.length) return;
|
||||
|
||||
|
||||
|
||||
// When there is only one completion, use it directly.
|
||||
if (this.autopick == true && this.raw_result.length == 1)
|
||||
{
|
||||
@ -182,7 +160,6 @@ var IPython = (function(IPython ) {
|
||||
this.sel.keydown(function(event){that.keydown(event)});
|
||||
|
||||
this.build_gui_list(this.raw_result);
|
||||
var that=this;
|
||||
//CodeMirror.connect(that.sel, "dblclick", function(){that.pick()});
|
||||
|
||||
this.sel.focus();
|
||||
|
Loading…
Reference in New Issue
Block a user