mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-24 12:05:22 +08:00
Improve tooltip tringgering,make it configurable
As until now, when pressing tab and a white space was preceding the cursor The completion was triggerd with the whole namespace in it. Now if a whitespace or an opening bracket is just befor the cursor it will try to display a tooltip. The logic to find what object_info_request is send have been sightly changed to try to match the expression just before the last unmached openig bracket before the cursor (without considering what is after the cursor). example (_|_ represent the cursor): >>> his_|_<tab> # completion >>> hist(_|_<tab> # tooltip on hist >>> hist(rand(20),bins=range(_|_ <tab> #tooltip on range >>> hist(rand(20),bins=range(10), _|_ <tab> # tooltip on hist (whitespace before cursor) >>> hist(rand(20),bins=range(10),_|_ <tab> # completion as we dont care of what is after the cursor: >>> hist(rand(5000), bins=50, _|_orientaion='horizontal') # and tab, equivalent to >>> hist(rand(5000), bins=50, _|_<tab> # onte the space again >>> hist(_|_rand(5000), bins=50, orientaion='horizontal') # and tab, equivalent to >>> hist(_|_ the 4 give tooltip on hist note that you can get tooltip on things that aren't function by appending a '(' like >>> matplotlib(<tab> Which is kinda weird... so we might want to bound another shortcut for tooltip, but which matches without bracket... additionnaly I have added a "Config" pannel in the left pannel with a checkbox bind to wether or not activate this functionnality Note, (rebase and edited commit, might not work perfetly xwithout the following ones)
This commit is contained in:
parent
45db8cce13
commit
6c86474bdb
@ -115,6 +115,10 @@ span.section_row_buttons a {
|
|||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#tooltipontab_span {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
.checkbox_label {
|
.checkbox_label {
|
||||||
font-size: 85%;
|
font-size: 85%;
|
||||||
float: right;
|
float: right;
|
||||||
|
@ -85,7 +85,6 @@ var IPython = (function (IPython) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Subclasses must implement create_element.
|
// Subclasses must implement create_element.
|
||||||
Cell.prototype.create_element = function () {};
|
Cell.prototype.create_element = function () {};
|
||||||
|
|
||||||
|
@ -65,7 +65,8 @@ var IPython = (function (IPython) {
|
|||||||
// value is used to determine if CodeMirror should ignore the event:
|
// value is used to determine if CodeMirror should ignore the event:
|
||||||
// true = ignore, false = don't ignore.
|
// true = ignore, false = don't ignore.
|
||||||
tooltip_wait_time = 2000;
|
tooltip_wait_time = 2000;
|
||||||
tooltip_on_tab = true;
|
|
||||||
|
tooltip_on_tab = this.notebook.tooltip_on_tab;
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
// whatever key is pressed, first, cancel the tooltip request before
|
// whatever key is pressed, first, cancel the tooltip request before
|
||||||
@ -79,9 +80,9 @@ var IPython = (function (IPython) {
|
|||||||
// Always ignore shift-enter in CodeMirror as we handle it.
|
// Always ignore shift-enter in CodeMirror as we handle it.
|
||||||
return true;
|
return true;
|
||||||
}else if (event.keyCode === 53 && event.type === 'keydown' && tooltip_wait_time >= 0) {
|
}else if (event.keyCode === 53 && event.type === 'keydown' && tooltip_wait_time >= 0) {
|
||||||
// Pressing '(' , request tooltip
|
// Pressing '(' , request tooltip, don't forget to reappend it
|
||||||
var cursor = editor.getCursor();
|
var cursor = editor.getCursor();
|
||||||
var pre_cursor = editor.getRange({line:cursor.line,ch:0},cursor).trim();
|
var pre_cursor = editor.getRange({line:cursor.line,ch:0},cursor).trim()+'(';
|
||||||
CodeCell.prototype.request_tooltip_after_time(pre_cursor,tooltip_wait_time,that);
|
CodeCell.prototype.request_tooltip_after_time(pre_cursor,tooltip_wait_time,that);
|
||||||
} else if (event.keyCode === 9 && event.type == 'keydown') {
|
} else if (event.keyCode === 9 && event.type == 'keydown') {
|
||||||
// Tab completion.
|
// Tab completion.
|
||||||
@ -92,7 +93,7 @@ var IPython = (function (IPython) {
|
|||||||
// Don't autocomplete if the part of the line before the cursor
|
// Don't autocomplete if the part of the line before the cursor
|
||||||
// is empty. In this case, let CodeMirror handle indentation.
|
// is empty. In this case, let CodeMirror handle indentation.
|
||||||
return false;
|
return false;
|
||||||
} else if (pre_cursor.substr(-1) === "(" && tooltip_on_tab ) {
|
} else if ((pre_cursor.substr(-1) === "("|| pre_cursor.substr(-1) === " ") && tooltip_on_tab ) {
|
||||||
CodeCell.prototype.request_tooltip_after_time(pre_cursor,0,that);
|
CodeCell.prototype.request_tooltip_after_time(pre_cursor,0,that);
|
||||||
} else {
|
} else {
|
||||||
pre_cursor.trim();
|
pre_cursor.trim();
|
||||||
|
@ -27,6 +27,7 @@ var IPython = (function (IPython) {
|
|||||||
this.style();
|
this.style();
|
||||||
this.create_elements();
|
this.create_elements();
|
||||||
this.bind_events();
|
this.bind_events();
|
||||||
|
this.set_tooltipontab(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -621,6 +622,11 @@ var IPython = (function (IPython) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Notebook.prototype.set_tooltipontab = function (state) {
|
||||||
|
console.log("change tooltip on tab to : "+state);
|
||||||
|
this.tooltip_on_tab = state;
|
||||||
|
};
|
||||||
|
|
||||||
Notebook.prototype.set_autoindent = function (state) {
|
Notebook.prototype.set_autoindent = function (state) {
|
||||||
var cells = this.cells();
|
var cells = this.cells();
|
||||||
len = cells.length;
|
len = cells.length;
|
||||||
@ -883,10 +889,22 @@ var IPython = (function (IPython) {
|
|||||||
|
|
||||||
|
|
||||||
Notebook.prototype.request_tool_tip = function (cell,func) {
|
Notebook.prototype.request_tool_tip = function (cell,func) {
|
||||||
//remove ending '(' if any
|
// Feel free to shorten this logic if you are better
|
||||||
//there should be a way to do it in the regexp
|
// than me in regEx
|
||||||
if(func.substr(-1) === '('){func=func.substr(0, func.length-1);}
|
// basicaly you shoul be able to get xxx.xxx.xxx from
|
||||||
// regexp to select last part of expression
|
// something(range(10), kwarg=smth) ; xxx.xxx.xxx( firstarg, rand(234,23), kwarg1=2,
|
||||||
|
// remove everything between matchin bracket (need to iterate)
|
||||||
|
matchBracket = /\([^\(\)]+\)/g;
|
||||||
|
oldfunc = func;
|
||||||
|
func = func.replace(matchBracket,"");
|
||||||
|
while( oldfunc != func )
|
||||||
|
{
|
||||||
|
oldfunc = func;
|
||||||
|
func = func.replace(matchBracket,"");
|
||||||
|
}
|
||||||
|
// remove everythin after last open bracket
|
||||||
|
endBracket = /\([^\(]*$/g;
|
||||||
|
func = func.replace(endBracket,"");
|
||||||
var re = /[a-zA-Z._]+$/g;
|
var re = /[a-zA-Z._]+$/g;
|
||||||
var msg_id = this.kernel.object_info_request(re.exec(func));
|
var msg_id = this.kernel.object_info_request(re.exec(func));
|
||||||
this.msg_cell_map[msg_id] = cell.cell_id;
|
this.msg_cell_map[msg_id] = cell.cell_id;
|
||||||
|
@ -51,6 +51,7 @@ $(document).ready(function () {
|
|||||||
IPython.quick_help.element.addClass('hidden'); // shortcuts are disabled in read_only
|
IPython.quick_help.element.addClass('hidden'); // shortcuts are disabled in read_only
|
||||||
$('button#new_notebook').addClass('hidden');
|
$('button#new_notebook').addClass('hidden');
|
||||||
$('div#cell_section').addClass('hidden');
|
$('div#cell_section').addClass('hidden');
|
||||||
|
$('div#config_section').addClass('hidden');
|
||||||
$('div#kernel_section').addClass('hidden');
|
$('div#kernel_section').addClass('hidden');
|
||||||
$('span#login_widget').removeClass('hidden');
|
$('span#login_widget').removeClass('hidden');
|
||||||
// left panel starts collapsed, but the collapse must happen after
|
// left panel starts collapsed, but the collapse must happen after
|
||||||
|
@ -251,6 +251,20 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="config_section">
|
||||||
|
<div class="section_header">
|
||||||
|
<h3>Config</h3>
|
||||||
|
</div>
|
||||||
|
<div class="section_content">
|
||||||
|
<div class="section_row">
|
||||||
|
<span id="tooltipontab_span">
|
||||||
|
<input type="checkbox" id="tooltipontab" checked="true"></input>
|
||||||
|
</span>
|
||||||
|
<span class="checkbox_label" id="tooltipontab_label">Tooltip on tab:</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div id="left_panel_splitter"></div>
|
<div id="left_panel_splitter"></div>
|
||||||
<div id="notebook_panel">
|
<div id="notebook_panel">
|
||||||
|
Loading…
Reference in New Issue
Block a user