diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js
index f9906f0..6170df5 100644
--- a/IPython/frontend/html/notebook/static/js/codecell.js
+++ b/IPython/frontend/html/notebook/static/js/codecell.js
@@ -47,44 +47,55 @@ var IPython = (function (IPython) {
this.collapse()
};
+ //TODO, try to diminish the number of parameters.
+ CodeCell.prototype.request_tooltip_after_time = function (pre_cursor,time,that){
+ if (pre_cursor === "" || pre_cursor === "(" ) {
+ // don't do anything if line beggin with '(' or is empty
+ } else {
+ // Will set a timer to request tooltip in `time`
+ that.tooltip_timeout = setTimeout(function(){
+ IPython.notebook.request_tool_tip(that, pre_cursor)
+ },time);
+ }
+ };
CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) {
// This method gets called in CodeMirror's onKeyDown/onKeyPress
// handlers and is used to provide custom key handling. Its return
// value is used to determine if CodeMirror should ignore the event:
// true = ignore, false = don't ignore.
+ tooltip_wait_time = 2000;
+ tooltip_on_tab = true;
+ var that = this;
// whatever key is pressed, first, cancel the tooltip request before
// they are sent, and remove tooltip if any
if(event.type === 'keydown' && this.tooltip_timeout != null){
- CodeCell.prototype.remove_and_cancell_tooltip(this.tooltip_timeout);
- this.tooltip_timeout=null;
+ CodeCell.prototype.remove_and_cancell_tooltip(that.tooltip_timeout);
+ that.tooltip_timeout=null;
}
+
if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) {
// Always ignore shift-enter in CodeMirror as we handle it.
return true;
- }else if (event.keyCode === 53 && event.type === 'keydown') {
+ }else if (event.keyCode === 53 && event.type === 'keydown' && tooltip_wait_time >= 0) {
+ // Pressing '(' , request tooltip
var cursor = editor.getCursor();
var pre_cursor = editor.getRange({line:cursor.line,ch:0},cursor).trim();
- if (pre_cursor === "") {
- // don't do anything if line beggin with '('
- } else {
- var that = this;
- // Will set a timer to request tooltip in 1200ms
- this.tooltip_timeout = setTimeout(function(){
- IPython.notebook.request_tool_tip(that, pre_cursor)
- },1200);
- }
-
+ CodeCell.prototype.request_tooltip_after_time(pre_cursor,tooltip_wait_time,that);
} else if (event.keyCode === 9 && event.type == 'keydown') {
// Tab completion.
var cur = editor.getCursor();
- var pre_cursor = editor.getRange({line:cur.line,ch:0},cur).trim();
- if (pre_cursor === "") {
+ //Do not trim here because of tooltip
+ var pre_cursor = editor.getRange({line:cur.line,ch:0},cur);
+ if (pre_cursor.trim() === "") {
// Don't autocomplete if the part of the line before the cursor
// is empty. In this case, let CodeMirror handle indentation.
return false;
+ } else if (pre_cursor.substr(-1) === "(" && tooltip_on_tab ) {
+ CodeCell.prototype.request_tooltip_after_time(pre_cursor,0,that);
} else {
+ pre_cursor.trim();
// Autocomplete the current line.
event.stop();
var line = editor.getLine(cur.line);
diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js
index b291a74..1c5d079 100644
--- a/IPython/frontend/html/notebook/static/js/notebook.js
+++ b/IPython/frontend/html/notebook/static/js/notebook.js
@@ -705,7 +705,6 @@ var IPython = (function (IPython) {
rep = reply.content;
if(rep.found)
{
- console.log("object as been found");
cell.finish_tooltip(rep.definition,rep.docstring);
}
} else {
@@ -884,10 +883,12 @@ var IPython = (function (IPython) {
Notebook.prototype.request_tool_tip = function (cell,func) {
- // select last part of expression
+ //remove ending '(' if any
+ //there should be a way to do it in the regexp
+ if(func.substr(-1) === '('){func=func.substr(0, func.length-1);}
+ // regexp to select last part of expression
var re = /[a-zA-Z._]+$/g;
- var lastpart=re.exec(func);
- var msg_id = this.kernel.object_info_request(lastpart);
+ var msg_id = this.kernel.object_info_request(re.exec(func));
this.msg_cell_map[msg_id] = cell.cell_id;
};