##// END OF EJS Templates
tooltip on <tab>
Matthias BUSSONNIER -
Show More
@@ -47,44 +47,55 b' var IPython = (function (IPython) {'
47 this.collapse()
47 this.collapse()
48 };
48 };
49
49
50 //TODO, try to diminish the number of parameters.
51 CodeCell.prototype.request_tooltip_after_time = function (pre_cursor,time,that){
52 if (pre_cursor === "" || pre_cursor === "(" ) {
53 // don't do anything if line beggin with '(' or is empty
54 } else {
55 // Will set a timer to request tooltip in `time`
56 that.tooltip_timeout = setTimeout(function(){
57 IPython.notebook.request_tool_tip(that, pre_cursor)
58 },time);
59 }
60 };
50
61
51 CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) {
62 CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) {
52 // This method gets called in CodeMirror's onKeyDown/onKeyPress
63 // This method gets called in CodeMirror's onKeyDown/onKeyPress
53 // handlers and is used to provide custom key handling. Its return
64 // handlers and is used to provide custom key handling. Its return
54 // value is used to determine if CodeMirror should ignore the event:
65 // value is used to determine if CodeMirror should ignore the event:
55 // true = ignore, false = don't ignore.
66 // true = ignore, false = don't ignore.
67 tooltip_wait_time = 2000;
68 tooltip_on_tab = true;
69 var that = this;
56
70
57 // whatever key is pressed, first, cancel the tooltip request before
71 // whatever key is pressed, first, cancel the tooltip request before
58 // they are sent, and remove tooltip if any
72 // they are sent, and remove tooltip if any
59 if(event.type === 'keydown' && this.tooltip_timeout != null){
73 if(event.type === 'keydown' && this.tooltip_timeout != null){
60 CodeCell.prototype.remove_and_cancell_tooltip(this.tooltip_timeout);
74 CodeCell.prototype.remove_and_cancell_tooltip(that.tooltip_timeout);
61 this.tooltip_timeout=null;
75 that.tooltip_timeout=null;
62 }
76 }
77
63 if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) {
78 if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) {
64 // Always ignore shift-enter in CodeMirror as we handle it.
79 // Always ignore shift-enter in CodeMirror as we handle it.
65 return true;
80 return true;
66 }else if (event.keyCode === 53 && event.type === 'keydown') {
81 }else if (event.keyCode === 53 && event.type === 'keydown' && tooltip_wait_time >= 0) {
82 // Pressing '(' , request tooltip
67 var cursor = editor.getCursor();
83 var cursor = editor.getCursor();
68 var pre_cursor = editor.getRange({line:cursor.line,ch:0},cursor).trim();
84 var pre_cursor = editor.getRange({line:cursor.line,ch:0},cursor).trim();
69 if (pre_cursor === "") {
85 CodeCell.prototype.request_tooltip_after_time(pre_cursor,tooltip_wait_time,that);
70 // don't do anything if line beggin with '('
71 } else {
72 var that = this;
73 // Will set a timer to request tooltip in 1200ms
74 this.tooltip_timeout = setTimeout(function(){
75 IPython.notebook.request_tool_tip(that, pre_cursor)
76 },1200);
77 }
78
79 } else if (event.keyCode === 9 && event.type == 'keydown') {
86 } else if (event.keyCode === 9 && event.type == 'keydown') {
80 // Tab completion.
87 // Tab completion.
81 var cur = editor.getCursor();
88 var cur = editor.getCursor();
82 var pre_cursor = editor.getRange({line:cur.line,ch:0},cur).trim();
89 //Do not trim here because of tooltip
83 if (pre_cursor === "") {
90 var pre_cursor = editor.getRange({line:cur.line,ch:0},cur);
91 if (pre_cursor.trim() === "") {
84 // Don't autocomplete if the part of the line before the cursor
92 // Don't autocomplete if the part of the line before the cursor
85 // is empty. In this case, let CodeMirror handle indentation.
93 // is empty. In this case, let CodeMirror handle indentation.
86 return false;
94 return false;
95 } else if (pre_cursor.substr(-1) === "(" && tooltip_on_tab ) {
96 CodeCell.prototype.request_tooltip_after_time(pre_cursor,0,that);
87 } else {
97 } else {
98 pre_cursor.trim();
88 // Autocomplete the current line.
99 // Autocomplete the current line.
89 event.stop();
100 event.stop();
90 var line = editor.getLine(cur.line);
101 var line = editor.getLine(cur.line);
@@ -705,7 +705,6 b' var IPython = (function (IPython) {'
705 rep = reply.content;
705 rep = reply.content;
706 if(rep.found)
706 if(rep.found)
707 {
707 {
708 console.log("object as been found");
709 cell.finish_tooltip(rep.definition,rep.docstring);
708 cell.finish_tooltip(rep.definition,rep.docstring);
710 }
709 }
711 } else {
710 } else {
@@ -884,10 +883,12 b' var IPython = (function (IPython) {'
884
883
885
884
886 Notebook.prototype.request_tool_tip = function (cell,func) {
885 Notebook.prototype.request_tool_tip = function (cell,func) {
887 // select last part of expression
886 //remove ending '(' if any
887 //there should be a way to do it in the regexp
888 if(func.substr(-1) === '('){func=func.substr(0, func.length-1);}
889 // regexp to select last part of expression
888 var re = /[a-zA-Z._]+$/g;
890 var re = /[a-zA-Z._]+$/g;
889 var lastpart=re.exec(func);
891 var msg_id = this.kernel.object_info_request(re.exec(func));
890 var msg_id = this.kernel.object_info_request(lastpart);
891 this.msg_cell_map[msg_id] = cell.cell_id;
892 this.msg_cell_map[msg_id] = cell.cell_id;
892 };
893 };
893
894
General Comments 0
You need to be logged in to leave comments. Login now