Show More
@@ -47,44 +47,55 b' var IPython = (function (IPython) {' | |||
|
47 | 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 | 62 | CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) { |
|
52 | 63 | // This method gets called in CodeMirror's onKeyDown/onKeyPress |
|
53 | 64 | // handlers and is used to provide custom key handling. Its return |
|
54 | 65 | // value is used to determine if CodeMirror should ignore the event: |
|
55 | 66 | // true = ignore, false = don't ignore. |
|
67 | tooltip_wait_time = 2000; | |
|
68 | tooltip_on_tab = true; | |
|
69 | var that = this; | |
|
56 | 70 | |
|
57 | 71 | // whatever key is pressed, first, cancel the tooltip request before |
|
58 | 72 | // they are sent, and remove tooltip if any |
|
59 | 73 | if(event.type === 'keydown' && this.tooltip_timeout != null){ |
|
60 |
CodeCell.prototype.remove_and_cancell_tooltip(th |
|
|
61 |
th |
|
|
74 | CodeCell.prototype.remove_and_cancell_tooltip(that.tooltip_timeout); | |
|
75 | that.tooltip_timeout=null; | |
|
62 | 76 | } |
|
77 | ||
|
63 | 78 | if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) { |
|
64 | 79 | // Always ignore shift-enter in CodeMirror as we handle it. |
|
65 | 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 | 83 | var cursor = editor.getCursor(); |
|
68 | 84 | var pre_cursor = editor.getRange({line:cursor.line,ch:0},cursor).trim(); |
|
69 | if (pre_cursor === "") { | |
|
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 | ||
|
85 | CodeCell.prototype.request_tooltip_after_time(pre_cursor,tooltip_wait_time,that); | |
|
79 | 86 | } else if (event.keyCode === 9 && event.type == 'keydown') { |
|
80 | 87 | // Tab completion. |
|
81 | 88 | var cur = editor.getCursor(); |
|
82 | var pre_cursor = editor.getRange({line:cur.line,ch:0},cur).trim(); | |
|
83 | if (pre_cursor === "") { | |
|
89 | //Do not trim here because of tooltip | |
|
90 | var pre_cursor = editor.getRange({line:cur.line,ch:0},cur); | |
|
91 | if (pre_cursor.trim() === "") { | |
|
84 | 92 | // Don't autocomplete if the part of the line before the cursor |
|
85 | 93 | // is empty. In this case, let CodeMirror handle indentation. |
|
86 | 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 | 97 | } else { |
|
98 | pre_cursor.trim(); | |
|
88 | 99 | // Autocomplete the current line. |
|
89 | 100 | event.stop(); |
|
90 | 101 | var line = editor.getLine(cur.line); |
@@ -705,7 +705,6 b' var IPython = (function (IPython) {' | |||
|
705 | 705 | rep = reply.content; |
|
706 | 706 | if(rep.found) |
|
707 | 707 | { |
|
708 | console.log("object as been found"); | |
|
709 | 708 | cell.finish_tooltip(rep.definition,rep.docstring); |
|
710 | 709 | } |
|
711 | 710 | } else { |
@@ -884,10 +883,12 b' var IPython = (function (IPython) {' | |||
|
884 | 883 | |
|
885 | 884 | |
|
886 | 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 | 890 | var re = /[a-zA-Z._]+$/g; |
|
889 | var lastpart=re.exec(func); | |
|
890 | var msg_id = this.kernel.object_info_request(lastpart); | |
|
891 | var msg_id = this.kernel.object_info_request(re.exec(func)); | |
|
891 | 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