Skip to content

Commit

Permalink
Merge pull request #3793 from jhamrick/master
Browse files Browse the repository at this point in the history
Disable autotooltip if no docstring 

This will disable the tooltip if there's no docstring, after ( is typed. Pressing tab to request the tooltip will still bring it up. This hasn't been tested against the Julia kernel, however.

Closes #3788
  • Loading branch information
Carreau committed Jul 26, 2013
2 parents 1aa49a8 + ef84af7 commit 4c80e0d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion IPython/html/static/notebook/js/codecell.js
Expand Up @@ -167,7 +167,9 @@ var IPython = (function (IPython) {
// triger on keypress (!) otherwise inconsistent event.which depending on plateform
// browser and keyboard layout !
// Pressing '(' , request tooltip, don't forget to reappend it
IPython.tooltip.pending(that);
// The second argument says to hide the tooltip if the docstring
// is actually empty
IPython.tooltip.pending(that, true);
} else if (event.which === key.UPARROW && event.type === 'keydown') {
// If we are not at the top, let CM handle the up arrow and
// prevent the global keydown handler from handling it.
Expand Down
20 changes: 14 additions & 6 deletions IPython/html/static/notebook/js/tooltip.js
Expand Up @@ -39,6 +39,9 @@ var IPython = (function (IPython) {
// 'sticky ?'
this._sticky = false;

// display tooltip if the docstring is empty?
this._hide_if_no_docstring = false;

// contain the button in the upper right corner
this.buttons = $('<div/>').addClass('tooltipbuttons');

Expand Down Expand Up @@ -178,10 +181,10 @@ var IPython = (function (IPython) {
}

// will trigger tooltip after timeout
Tooltip.prototype.pending = function (cell) {
Tooltip.prototype.pending = function (cell, hide_if_no_docstring) {
var that = this;
this._tooltip_timeout = setTimeout(function () {
that.request(cell)
that.request(cell, hide_if_no_docstring)
}, that.time_before_tooltip);
}

Expand Down Expand Up @@ -212,7 +215,7 @@ var IPython = (function (IPython) {
}

// make an imediate completion request
Tooltip.prototype.request = function (cell) {
Tooltip.prototype.request = function (cell, hide_if_no_docstring) {
// request(codecell)
// Deal with extracting the text from the cell and counting
// call in a row
Expand All @@ -224,6 +227,8 @@ var IPython = (function (IPython) {
ch: 0
}, cursor).trim();

this._hide_if_no_docstring = hide_if_no_docstring;

if(editor.somethingSelected()){
text = editor.getSelection();
}
Expand Down Expand Up @@ -312,8 +317,6 @@ var IPython = (function (IPython) {
this.arrow.animate({
'left': posarrowleft + 'px'
});
this.tooltip.fadeIn('fast');
this._hidden = false;

// build docstring
var defstring = reply.call_def;
Expand All @@ -331,10 +334,15 @@ var IPython = (function (IPython) {
if (docstring == null) {
docstring = reply.docstring;
}
if (docstring == null) {

if (docstring == null && this._hide_if_no_docstring) {
return;
} else {
docstring = "<empty docstring>";
}

this.tooltip.fadeIn('fast');
this._hidden = false;
this.text.children().remove();

var pre = $('<pre/>').html(utils.fixConsole(docstring));
Expand Down

0 comments on commit 4c80e0d

Please sign in to comment.