Merge pull request #5146 from jdfreder/modal-fix

Dual mode bug fixes.
pull/37/head
Brian E. Granger 12 years ago
commit 88fc1a0737

@ -48,7 +48,7 @@ var IPython = (function (IPython) {
this.cell_id = utils.uuid();
this._options = options;
// For JS VM engines optimisation, attributes should be all set (even
// For JS VM engines optimization, attributes should be all set (even
// to null) in the constructor, and if possible, if different subclass
// have new attributes with same name, they should be created in the
// same order. Easiest is to create and set to null in parent class.
@ -57,7 +57,6 @@ var IPython = (function (IPython) {
this.cell_type = this.cell_type || null;
this.code_mirror = null;
this.create_element();
if (this.element !== null) {
this.element.data("cell", this);
@ -76,8 +75,7 @@ var IPython = (function (IPython) {
// FIXME: Workaround CM Bug #332 (Safari segfault on drag)
// by disabling drag/drop altogether on Safari
// https://github.com/marijnh/CodeMirror/issues/332
// https://github.com/marijnh/CodeMirror/issues/332
if (utils.browser[0] == "Safari") {
Cell.options_default.cm_config.dragDrop = false;
}
@ -85,11 +83,8 @@ var IPython = (function (IPython) {
Cell.prototype.mergeopt = function(_class, options, overwrite){
options = options || {};
overwrite = overwrite || {};
return $.extend(true, {}, _class.options_default, options, overwrite)
}
return $.extend(true, {}, _class.options_default, options, overwrite);
};
/**
* Empty. Subclasses must implement create_element.
@ -118,8 +113,7 @@ var IPython = (function (IPython) {
} else {
this.element.addClass('command_mode');
}
}
};
/**
* Subclasses can implement override bind_events.
@ -133,12 +127,12 @@ var IPython = (function (IPython) {
that.element.click(function (event) {
if (!that.selected) {
$([IPython.events]).trigger('select.Cell', {'cell':that});
};
}
});
that.element.focusin(function (event) {
if (!that.selected) {
$([IPython.events]).trigger('select.Cell', {'cell':that});
};
}
});
if (this.code_mirror) {
this.code_mirror.on("change", function(cm, change) {
@ -152,17 +146,9 @@ var IPython = (function (IPython) {
}
if (this.code_mirror) {
this.code_mirror.on('blur', function(cm, change) {
if (that.mode === 'edit') {
setTimeout(function () {
var isf = IPython.utils.is_focused;
var trigger = true;
if (isf('div#tooltip') || isf('div.completions')) {
trigger = false;
}
if (trigger) {
$([IPython.events]).trigger('command_mode.Cell', {cell: that});
}
}, 1);
// Check if this unfocus event is legit.
if (!that.should_cancel_blur()) {
$([IPython.events]).trigger('command_mode.Cell', {cell: that});
}
});
}
@ -273,7 +259,18 @@ var IPython = (function (IPython) {
} else {
return false;
}
}
};
/**
* Determine whether or not the unfocus event should be aknowledged.
*
* @method should_cancel_blur
*
* @return results {bool} Whether or not to ignore the cell's blur event.
**/
Cell.prototype.should_cancel_blur = function () {
return false;
};
/**
* Focus the cell in the DOM sense
@ -281,24 +278,19 @@ var IPython = (function (IPython) {
*/
Cell.prototype.focus_cell = function () {
this.element.focus();
}
};
/**
* Focus the editor area so a user can type
*
* NOTE: If codemirror is focused via a mouse click event, you don't want to
* call this because it will cause a page jump.
* @method focus_editor
*/
Cell.prototype.focus_editor = function () {
var that = this;
this.refresh();
// Only focus the CM editor if it is not focused already. This prevents jumps
// related to the previous prompt position.
setTimeout(function () {
var isf = IPython.utils.is_focused;
if (!isf(that.element.find('div.CodeMirror'))) {
that.code_mirror.focus();
}
}, 1);
}
this.code_mirror.focus();
};
/**
* Refresh codemirror instance
@ -375,7 +367,7 @@ var IPython = (function (IPython) {
var text = this.code_mirror.getRange({line:0, ch:0}, cursor);
text = text.replace(/^\n+/, '').replace(/\n+$/, '');
return text;
}
};
/**
@ -386,7 +378,7 @@ var IPython = (function (IPython) {
var cursor = this.code_mirror.getCursor();
var last_line_num = this.code_mirror.lineCount()-1;
var last_line_len = this.code_mirror.getLine(last_line_num).length;
var end = {line:last_line_num, ch:last_line_len}
var end = {line:last_line_num, ch:last_line_len};
var text = this.code_mirror.getRange(cursor, end);
text = text.replace(/^\n+/, '').replace(/\n+$/, '');
return text;
@ -430,9 +422,10 @@ var IPython = (function (IPython) {
**/
Cell.prototype._auto_highlight = function (modes) {
//Here we handle manually selected modes
if( this.user_highlight != undefined && this.user_highlight != 'auto' )
var mode;
if( this.user_highlight !== undefined && this.user_highlight != 'auto' )
{
var mode = this.user_highlight;
mode = this.user_highlight;
CodeMirror.autoLoadMode(this.code_mirror, mode);
this.code_mirror.setOption('mode', mode);
return;
@ -440,22 +433,22 @@ var IPython = (function (IPython) {
var current_mode = this.code_mirror.getOption('mode', mode);
var first_line = this.code_mirror.getLine(0);
// loop on every pairs
for( var mode in modes) {
var regs = modes[mode]['reg'];
for(mode in modes) {
var regs = modes[mode].reg;
// only one key every time but regexp can't be keys...
for(var i=0; i<regs.length; i++) {
// here we handle non magic_modes
if(first_line.match(regs[i]) != null) {
if(first_line.match(regs[i]) !== null) {
if(current_mode == mode){
return;
}
if (mode.search('magic_') != 0) {
if (mode.search('magic_') !== 0) {
this.code_mirror.setOption('mode', mode);
CodeMirror.autoLoadMode(this.code_mirror, mode);
return;
}
var open = modes[mode]['open']|| "%%";
var close = modes[mode]['close']|| "%%end";
var open = modes[mode].open || "%%";
var close = modes[mode].close || "%%end";
var mmode = mode;
mode = mmode.substr(6);
if(current_mode == mode){
@ -482,14 +475,14 @@ var IPython = (function (IPython) {
}
}
// fallback on default
var default_mode
var default_mode;
try {
default_mode = this._options.cm_config.mode;
} catch(e) {
default_mode = 'text/plain';
}
if( current_mode === default_mode){
return
return;
}
this.code_mirror.setOption('mode', default_mode);
};

@ -402,13 +402,20 @@ var IPython = (function (IPython) {
return false;
};
CodeCell.prototype.edit_mode = function () {
var cont = IPython.Cell.prototype.edit_mode.apply(this);
if (cont) {
this.focus_editor();
}
return cont;
}
/**
* Determine whether or not the unfocus event should be aknowledged.
*
* @method should_cancel_blur
*
* @return results {bool} Whether or not to ignore the cell's blur event.
**/
CodeCell.prototype.should_cancel_blur = function () {
// Cancel this unfocus event if the base wants to cancel or the cell
// completer is open or the tooltip is open.
return IPython.Cell.prototype.should_cancel_blur.apply(this) ||
(this.completer && this.completer.is_visible()) ||
(IPython.tooltip && IPython.tooltip.is_visible());
};
CodeCell.prototype.select_all = function () {
var start = {line: 0, ch: 0};

@ -73,6 +73,7 @@ var IPython = (function (IPython) {
var Completer = function (cell) {
this._visible = false;
this.cell = cell;
this.editor = cell.code_mirror;
var that = this;
@ -84,6 +85,10 @@ var IPython = (function (IPython) {
});
};
Completer.prototype.is_visible = function () {
// Return whether or not the completer is visible.
return this._visible;
};
Completer.prototype.startCompletion = function () {
// call for a 'first' completion, that will set the editor and do some
@ -225,6 +230,7 @@ var IPython = (function (IPython) {
.attr('multiple', 'true')
.attr('size', Math.min(10, this.raw_result.length));
this.complete.append(this.sel);
this._visible = true;
$('body').append(this.complete);
// After everything is on the page, compute the postion.
@ -282,6 +288,7 @@ var IPython = (function (IPython) {
};
Completer.prototype.close = function () {
this._visible = false;
if (this.done) return;
this.done = true;
$('.completions').remove();

@ -42,12 +42,12 @@ var IPython = (function (IPython) {
// These apply to Firefox and Opera
var _mozilla_keycodes = {
'; :': 59, '= +': 61, '- _': 173, 'meta': 224
}
};
// This apply to Webkit and IE
var _ie_keycodes = {
'; :': 186, '= +': 187, '- _': 189,
}
};
var browser = IPython.utils.browser[0];
var platform = IPython.utils.platform;
@ -63,15 +63,15 @@ var IPython = (function (IPython) {
for (var name in _keycodes) {
var names = name.split(' ');
if (names.length === 1) {
var n = names[0]
keycodes[n] = _keycodes[n]
inv_keycodes[_keycodes[n]] = n
var n = names[0];
keycodes[n] = _keycodes[n];
inv_keycodes[_keycodes[n]] = n;
} else {
var primary = names[0];
var secondary = names[1];
keycodes[primary] = _keycodes[name]
keycodes[secondary] = _keycodes[name]
inv_keycodes[_keycodes[name]] = primary
keycodes[primary] = _keycodes[name];
keycodes[secondary] = _keycodes[name];
inv_keycodes[_keycodes[name]] = primary;
}
}
@ -111,7 +111,7 @@ var IPython = (function (IPython) {
return false;
}
}
}
};
if (platform === 'MacOS') {
default_common_shortcuts['cmd+s'] =
@ -165,11 +165,11 @@ var IPython = (function (IPython) {
var cell = IPython.notebook.get_selected_cell();
if (cell && cell.at_top()) {
event.preventDefault();
IPython.notebook.command_mode()
IPython.notebook.command_mode();
IPython.notebook.select_prev();
IPython.notebook.edit_mode();
return false;
};
}
}
},
'down' : {
@ -179,11 +179,11 @@ var IPython = (function (IPython) {
var cell = IPython.notebook.get_selected_cell();
if (cell && cell.at_bottom()) {
event.preventDefault();
IPython.notebook.command_mode()
IPython.notebook.command_mode();
IPython.notebook.select_next();
IPython.notebook.edit_mode();
return false;
};
}
}
},
'alt+-' : {
@ -210,7 +210,7 @@ var IPython = (function (IPython) {
help : 'tooltip',
help_index : 'ed',
},
}
};
if (platform === 'MacOS') {
default_edit_shortcuts['cmd+/'] =
@ -264,9 +264,8 @@ var IPython = (function (IPython) {
var index = IPython.notebook.get_selected_index();
if (index !== 0 && index !== null) {
IPython.notebook.select_prev();
var cell = IPython.notebook.get_selected_cell();
cell.focus_cell();
};
IPython.notebook.focus_cell();
}
return false;
}
},
@ -277,9 +276,8 @@ var IPython = (function (IPython) {
var index = IPython.notebook.get_selected_index();
if (index !== (IPython.notebook.ncells()-1) && index !== null) {
IPython.notebook.select_next();
var cell = IPython.notebook.get_selected_cell();
cell.focus_cell();
};
IPython.notebook.focus_cell();
}
return false;
}
},
@ -290,9 +288,8 @@ var IPython = (function (IPython) {
var index = IPython.notebook.get_selected_index();
if (index !== 0 && index !== null) {
IPython.notebook.select_prev();
var cell = IPython.notebook.get_selected_cell();
cell.focus_cell();
};
IPython.notebook.focus_cell();
}
return false;
}
},
@ -303,9 +300,8 @@ var IPython = (function (IPython) {
var index = IPython.notebook.get_selected_index();
if (index !== (IPython.notebook.ncells()-1) && index !== null) {
IPython.notebook.select_next();
var cell = IPython.notebook.get_selected_cell();
cell.focus_cell();
};
IPython.notebook.focus_cell();
}
return false;
}
},
@ -540,23 +536,23 @@ var IPython = (function (IPython) {
return false;
}
},
}
};
// Shortcut manager class
var ShortcutManager = function (delay) {
this._shortcuts = {}
this._counts = {}
this._timers = {}
this._shortcuts = {};
this._counts = {};
this._timers = {};
this.delay = delay || 800; // delay in milliseconds
}
};
ShortcutManager.prototype.help = function () {
var help = [];
for (var shortcut in this._shortcuts) {
var help_string = this._shortcuts[shortcut]['help'];
var help_index = this._shortcuts[shortcut]['help_index'];
var help_string = this._shortcuts[shortcut].help;
var help_index = this._shortcuts[shortcut].help_index;
if (help_string) {
if (platform === 'MacOS') {
shortcut = shortcut.replace('meta', 'cmd');
@ -576,45 +572,45 @@ var IPython = (function (IPython) {
return 0;
});
return help;
}
};
ShortcutManager.prototype.normalize_key = function (key) {
return inv_keycodes[keycodes[key]];
}
};
ShortcutManager.prototype.normalize_shortcut = function (shortcut) {
// Sort a sequence of + separated modifiers into the order alt+ctrl+meta+shift
shortcut = shortcut.replace('cmd', 'meta').toLowerCase();
var values = shortcut.split("+");
if (values.length === 1) {
return this.normalize_key(values[0])
return this.normalize_key(values[0]);
} else {
var modifiers = values.slice(0,-1);
var key = this.normalize_key(values[values.length-1]);
modifiers.sort();
return modifiers.join('+') + '+' + key;
}
}
};
ShortcutManager.prototype.event_to_shortcut = function (event) {
// Convert a jQuery keyboard event to a strong based keyboard shortcut
var shortcut = '';
var key = inv_keycodes[event.which]
var key = inv_keycodes[event.which];
if (event.altKey && key !== 'alt') {shortcut += 'alt+';}
if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl+';}
if (event.metaKey && key !== 'meta') {shortcut += 'meta+';}
if (event.shiftKey && key !== 'shift') {shortcut += 'shift+';}
shortcut += key;
return shortcut
}
return shortcut;
};
ShortcutManager.prototype.clear_shortcuts = function () {
this._shortcuts = {};
}
};
ShortcutManager.prototype.add_shortcut = function (shortcut, data) {
if (typeof(data) === 'function') {
data = {help: '', help_index: '', handler: data}
data = {help: '', help_index: '', handler: data};
}
data.help_index = data.help_index || '';
data.help = data.help || '';
@ -625,19 +621,19 @@ var IPython = (function (IPython) {
shortcut = this.normalize_shortcut(shortcut);
this._counts[shortcut] = 0;
this._shortcuts[shortcut] = data;
}
};
ShortcutManager.prototype.add_shortcuts = function (data) {
for (var shortcut in data) {
this.add_shortcut(shortcut, data[shortcut]);
}
}
};
ShortcutManager.prototype.remove_shortcut = function (shortcut) {
shortcut = this.normalize_shortcut(shortcut);
delete this._counts[shortcut];
delete this._shortcuts[shortcut];
}
};
ShortcutManager.prototype.count_handler = function (shortcut, event, data) {
var that = this;
@ -646,7 +642,7 @@ var IPython = (function (IPython) {
var timer = null;
if (c[shortcut] === data.count-1) {
c[shortcut] = 0;
var timer = t[shortcut];
timer = t[shortcut];
if (timer) {clearTimeout(timer); delete t[shortcut];}
return data.handler(event);
} else {
@ -657,13 +653,13 @@ var IPython = (function (IPython) {
t[shortcut] = timer;
}
return false;
}
};
ShortcutManager.prototype.call_handler = function (event) {
var shortcut = this.event_to_shortcut(event);
var data = this._shortcuts[shortcut];
if (data) {
var handler = data['handler'];
var handler = data.handler;
if (handler) {
if (data.count === 1) {
return handler(event);
@ -673,12 +669,11 @@ var IPython = (function (IPython) {
}
}
return true;
}
};
// Main keyboard manager for the notebook
var KeyboardManager = function () {
this.mode = 'command';
this.enabled = true;
@ -701,14 +696,14 @@ var IPython = (function (IPython) {
KeyboardManager.prototype.handle_keydown = function (event) {
var notebook = IPython.notebook;
if (event.which === keycodes['esc']) {
if (event.which === keycodes.esc) {
// Intercept escape at highest level to avoid closing
// websocket connection with firefox
event.preventDefault();
}
if (!this.enabled) {
if (event.which === keycodes['esc']) {
if (event.which === keycodes.esc) {
// ESC
notebook.command_mode();
return false;
@ -722,43 +717,60 @@ var IPython = (function (IPython) {
return this.command_shortcuts.call_handler(event);
}
return true;
}
};
KeyboardManager.prototype.edit_mode = function () {
this.last_mode = this.mode;
this.mode = 'edit';
}
};
KeyboardManager.prototype.command_mode = function () {
this.last_mode = this.mode;
this.mode = 'command';
}
};
KeyboardManager.prototype.enable = function () {
this.enabled = true;
}
};
KeyboardManager.prototype.disable = function () {
this.enabled = false;
}
};
KeyboardManager.prototype.register_events = function (e) {
var that = this;
e.on('focusin', function () {
var handle_focus = function () {
that.disable();
});
e.on('focusout', function () {
};
var handle_blur = function () {
that.enable();
});
};
e.on('focusin', handle_focus);
e.on('focusout', handle_blur);
// TODO: Very strange. The focusout event does not seem fire for the
// bootstrap textboxes on FF25&26... This works around that by
// registering focus and blur events recursively on all inputs within
// registered element.
e.find('input').blur(handle_blur);
e.on('DOMNodeInserted', function (event) {
var target = $(event.target);
if (target.is('input')) {
target.blur(handle_blur);
} else {
target.find('input').blur(handle_blur);
}
});
// There are times (raw_input) where we remove the element from the DOM before
// focusout is called. In this case we bind to the remove event of jQueryUI,
// which gets triggered upon removal, iff it is focused at the time.
// is_focused must be used to check for the case where an element within
// the element being removed is focused.
e.on('remove', function () {
if (document.activeElement === e[0]) {
if (IPython.utils.is_focused(e[0])) {
that.enable();
}
});
}
};
IPython.keycodes = keycodes;

@ -116,9 +116,7 @@ var IPython = (function (IPython) {
});
$([IPython.events]).on('edit_mode.Cell', function (event, data) {
var index = that.find_cell_index(data.cell);
that.select(index);
that.edit_mode();
that.handle_edit_mode(that.find_cell_index(data.cell));
});
$([IPython.events]).on('command_mode.Cell', function (event, data) {
@ -459,7 +457,6 @@ var IPython = (function (IPython) {
if (this.is_valid_cell_index(index)) {
var sindex = this.get_selected_index();
if (sindex !== null && index !== sindex) {
this.command_mode();
this.get_cell(sindex).unselect();
}
var cell = this.get_cell(index);
@ -504,6 +501,13 @@ var IPython = (function (IPython) {
// Edit/Command mode
/**
* Gets the index of the cell that is in edit mode.
*
* @method get_edit_index
*
* @return index {int}
**/
Notebook.prototype.get_edit_index = function () {
var result = null;
this.get_cell_elements().filter(function (index) {
@ -514,32 +518,74 @@ var IPython = (function (IPython) {
return result;
};
/**
* Make the notebook enter command mode.
*
* @method command_mode
**/
Notebook.prototype.command_mode = function () {
// Make sure there isn't an edit mode cell lingering around.
var cell = this.get_cell(this.get_edit_index());
if (cell) {
cell.command_mode();
}
// Notify the keyboard manager if this is a change of mode for the
// notebook as a whole.
if (this.mode !== 'command') {
$([IPython.events]).trigger('command_mode.Notebook');
var index = this.get_edit_index();
var cell = this.get_cell(index);
if (cell) {
cell.command_mode();
}
this.mode = 'command';
$([IPython.events]).trigger('command_mode.Notebook');
IPython.keyboard_manager.command_mode();
}
};
Notebook.prototype.edit_mode = function () {
/**
* Handle when a cell fires it's edit_mode event.
*
* @method handle_edit_mode
* @param [index] {int} Cell index to select. If no index is provided,
* the current selected cell is used.
**/
Notebook.prototype.handle_edit_mode = function (index) {
// Make sure the cell exists.
var cell = this.get_cell(index);
if (cell === null) { return; }
// Set the cell to edit mode and notify the keyboard manager if this
// is a change of mode for the notebook as a whole.
if (this.mode !== 'edit') {
$([IPython.events]).trigger('edit_mode.Notebook');
var cell = this.get_selected_cell();
if (cell === null) {return;} // No cell is selected
// We need to set the mode to edit to prevent reentering this method
// when cell.edit_mode() is called below.
cell.edit_mode();
this.mode = 'edit';
$([IPython.events]).trigger('edit_mode.Notebook');
IPython.keyboard_manager.edit_mode();
cell.edit_mode();
}
};
/**
* Make a cell enter edit mode.
*
* @method edit_mode
* @param [index] {int} Cell index to select. If no index is provided,
* the current selected cell is used.
**/
Notebook.prototype.edit_mode = function (index) {
if (index===undefined) {
index = this.get_selected_index();
}
// Make sure the cell exists.
var cell = this.get_cell(index);
if (cell === null) { return; }
if (cell.mode != 'edit') {
cell.unrender();
cell.focus_editor();
}
};
/**
* Focus the currently selected cell.
*
* @method focus_cell
**/
Notebook.prototype.focus_cell = function () {
var cell = this.get_selected_cell();
if (cell === null) {return;} // No cell is selected
@ -1403,8 +1449,8 @@ var IPython = (function (IPython) {
var cell_index = this.find_cell_index(cell);
cell.execute();
this.command_mode();
cell.focus_cell();
this.command_mode();
this.set_dirty(true);
};
@ -1422,16 +1468,14 @@ var IPython = (function (IPython) {
// If we are at the end always insert a new cell and return
if (cell_index === (this.ncells()-1)) {
this.insert_cell_below('code');
this.select(cell_index+1);
this.edit_mode();
this.edit_mode(cell_index+1);
this.scroll_to_bottom();
this.set_dirty(true);
return;
}
this.insert_cell_below('code');
this.select(cell_index+1);
this.edit_mode();
this.edit_mode(cell_index+1);
this.set_dirty(true);
};
@ -1450,8 +1494,7 @@ var IPython = (function (IPython) {
// If we are at the end always insert a new cell and return
if (cell_index === (this.ncells()-1)) {
this.insert_cell_below('code');
this.select(cell_index+1);
this.edit_mode();
this.edit_mode(cell_index+1);
this.scroll_to_bottom();
this.set_dirty(true);
return;
@ -1459,6 +1502,7 @@ var IPython = (function (IPython) {
this.select(cell_index+1);
this.get_cell(cell_index+1).focus_cell();
this.command_mode();
this.set_dirty(true);
};
@ -1925,8 +1969,7 @@ var IPython = (function (IPython) {
this.fromJSON(data);
if (this.ncells() === 0) {
this.insert_cell_below('code');
this.select(0);
this.edit_mode();
this.edit_mode(0);
} else {
this.select(0);
this.command_mode();
@ -2286,3 +2329,4 @@ var IPython = (function (IPython) {
return IPython;
}(IPython));

@ -81,7 +81,7 @@ var IPython = (function (IPython) {
this.celltoolbar = new IPython.CellToolbar(this);
inner_cell.append(this.celltoolbar.element);
var input_area = $('<div/>').addClass('text_cell_input border-box-sizing');
this.code_mirror = CodeMirror(input_area.get(0), this.cm_config);
this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config);
// The tabindex=-1 makes this div focusable.
var render_area = $('<div/>').addClass('text_cell_render border-box-sizing').
addClass('rendered_html').attr('tabindex','-1');
@ -104,8 +104,11 @@ var IPython = (function (IPython) {
this.element.dblclick(function () {
if (that.selected === false) {
$([IPython.events]).trigger('select.Cell', {'cell':that});
};
$([IPython.events]).trigger('edit_mode.Cell', {cell: that});
}
var cont = that.unrender();
if (cont) {
that.focus_editor();
}
});
};
@ -145,7 +148,7 @@ var IPython = (function (IPython) {
return false;
} else {
return true;
};
}
} else if (event.which === key.DOWNARROW && event.type === 'keydown') {
// If we are not at the bottom, let CM handle the down arrow and
// prevent the global keydown handler from handling it.
@ -154,7 +157,7 @@ var IPython = (function (IPython) {
return false;
} else {
return true;
};
}
} else if (event.which === key.ESC && event.type === 'keydown') {
if (that.code_mirror.options.keyMap === "vim-insert") {
// vim keyMap is active and in insert mode. In this case we leave vim
@ -179,7 +182,7 @@ var IPython = (function (IPython) {
if (this.mode === 'edit') {
this.code_mirror.refresh();
}
};
}
return cont;
};
@ -193,10 +196,9 @@ var IPython = (function (IPython) {
text_cell.find('div.text_cell_input').show();
if (this.get_text() === this.placeholder) {
this.set_text('');
this.refresh();
}
};
this.refresh();
}
return cont;
};
@ -204,15 +206,6 @@ var IPython = (function (IPython) {
this.render();
};
TextCell.prototype.edit_mode = function () {
var cont = IPython.Cell.prototype.edit_mode.apply(this);
if (cont) {
this.unrender();
this.focus_editor();
};
return cont;
}
/**
* setter: {{#crossLink "TextCell/set_text"}}{{/crossLink}}
* @method get_text
@ -261,8 +254,8 @@ var IPython = (function (IPython) {
return true;
} else {
return false;
};
};
}
}
};
/**
@ -278,8 +271,8 @@ var IPython = (function (IPython) {
return true;
} else {
return false;
};
};
}
}
};
/**
@ -332,7 +325,7 @@ var IPython = (function (IPython) {
mode: 'gfm'
},
placeholder: "Type *Markdown* and LaTeX: $\\alpha^2$"
}
};
MarkdownCell.prototype = new TextCell();
@ -363,8 +356,8 @@ var IPython = (function (IPython) {
}
this.element.find('div.text_cell_input').hide();
this.element.find("div.text_cell_render").show();
this.typeset()
};
this.typeset();
}
return cont;
};
@ -378,7 +371,7 @@ var IPython = (function (IPython) {
*/
var RawCell = function (options) {
options = this.mergeopt(RawCell,options)
options = this.mergeopt(RawCell,options);
TextCell.apply(this, [options]);
this.cell_type = 'raw';
// RawCell should always hide its rendered div
@ -396,7 +389,7 @@ var IPython = (function (IPython) {
/** @method bind_events **/
RawCell.prototype.bind_events = function () {
TextCell.prototype.bind_events.apply(this);
var that = this
var that = this;
this.element.focusout(function() {
that.auto_highlight();
});
@ -452,7 +445,7 @@ var IPython = (function (IPython) {
/** @method fromJSON */
HeadingCell.prototype.fromJSON = function (data) {
if (data.level != undefined){
if (data.level !== undefined){
this.level = data.level;
}
TextCell.prototype.fromJSON.apply(this, arguments);
@ -492,7 +485,7 @@ var IPython = (function (IPython) {
if (this.rendered) {
this.rendered = false;
this.render();
};
}
};
/** The depth of header cell, based on html (h1 to h6)
@ -544,7 +537,7 @@ var IPython = (function (IPython) {
this.element.find('div.text_cell_input').hide();
this.element.find("div.text_cell_render").show();
};
}
return cont;
};

@ -52,7 +52,7 @@ var IPython = (function (IPython) {
// expand the tooltip to see more
var expandlink = $('<a/>').attr('href', "#").addClass("ui-corner-all") //rounded corner
.attr('role', "button").attr('id', 'expanbutton').attr('title', 'Grow the tooltip vertically (press tab 2 times)').click(function () {
that.expand()
that.expand();
}).append(
$('<span/>').text('Expand').addClass('ui-icon').addClass('ui-icon-plus'));
@ -121,9 +121,13 @@ var IPython = (function (IPython) {
this._old_cell = (cell) ? cell : null;
this._old_request = (text) ? text : null;
this._consecutive_counter = 0;
}
};
};
Tooltip.prototype.is_visible = function () {
return !this._hidden;
};
Tooltip.prototype.showInPager = function (cell) {
// reexecute last call in pager by appending ? to show back in pager
var that = this;
@ -139,27 +143,27 @@ var IPython = (function (IPython) {
'store_history': true
});
this.remove_and_cancel_tooltip();
}
};
// grow the tooltip verticaly
Tooltip.prototype.expand = function () {
this.text.removeClass('smalltooltip');
this.text.addClass('bigtooltip');
$('#expanbutton').hide('slow');
}
};
// deal with all the logic of hiding the tooltip
// and reset it's status
Tooltip.prototype._hide = function () {
this._hidden = true;
this.tooltip.fadeOut('fast');
$('#expanbutton').show('slow');
this.text.removeClass('bigtooltip');
this.text.addClass('smalltooltip');
// keep scroll top to be sure to always see the first line
this.text.scrollTop(0);
this._hidden = true;
this.code_mirror = null;
}
};
// return true on successfully removing a visible tooltip; otherwise return
// false.
@ -178,23 +182,23 @@ var IPython = (function (IPython) {
} else {
return false;
}
}
};
// cancel autocall done after '(' for example.
Tooltip.prototype.cancel_pending = function () {
if (this._tooltip_timeout != null) {
if (this._tooltip_timeout !== null) {
clearTimeout(this._tooltip_timeout);
this._tooltip_timeout = null;
}
}
};
// will trigger tooltip after timeout
Tooltip.prototype.pending = function (cell, hide_if_no_docstring) {
var that = this;
this._tooltip_timeout = setTimeout(function () {
that.request(cell, hide_if_no_docstring)
that.request(cell, hide_if_no_docstring);
}, that.time_before_tooltip);
}
};
// easy access for julia monkey patching.
Tooltip.last_token_re = /[a-z_][0-9a-z._]*$/gi;
@ -219,7 +223,7 @@ var IPython = (function (IPython) {
line = line.replace(endBracket, "");
// reset the regex object
Tooltip.last_token_re.lastIndex = 0;
return Tooltip.last_token_re.exec(line)
return Tooltip.last_token_re.exec(line);
};
Tooltip.prototype._request_tooltip = function (cell, line) {
@ -252,7 +256,7 @@ var IPython = (function (IPython) {
// now we treat the different number of keypress
// first if same cell, same text, increment counter by 1
if (this._old_cell == cell && this._old_request == text && this._hidden == false) {
if (this._old_cell == cell && this._old_request == text && this._hidden === false) {
this._consecutive_counter++;
} else {
// else reset
@ -273,7 +277,7 @@ var IPython = (function (IPython) {
}
return;
}
};
// cancel the option of having the tooltip to stick
Tooltip.prototype.cancel_stick = function () {
@ -281,14 +285,14 @@ var IPython = (function (IPython) {
this._stick_timeout = null;
this._clocklink.hide('slow');
this._sticky = false;
}
};
// put the tooltip in a sicky state for 10 seconds
// it won't be removed by remove_and_cancell() unless you called with
// the first parameter set to true.
// remove_and_cancell_tooltip(true)
Tooltip.prototype.stick = function (time) {
time = (time != undefined) ? time : 10;
time = (time !== undefined) ? time : 10;
var that = this;
this._sticky = true;
this._clocklink.show('slow');
@ -296,7 +300,7 @@ var IPython = (function (IPython) {
that._sticky = false;
that._clocklink.hide('slow');
}, time * 1000);
}
};
// should be called with the kernel reply to actually show the tooltip
Tooltip.prototype._show = function (reply) {
@ -322,7 +326,7 @@ var IPython = (function (IPython) {
var xinter = o.left + (xinit - o.left) / w * (w - 450);
var posarrowleft = xinit - xinter;
if (this._hidden == false) {
if (this._hidden === false) {
this.tooltip.animate({
'left': xinter - 30 + 'px',
'top': (head.bottom + 10) + 'px'
@ -365,8 +369,8 @@ var IPython = (function (IPython) {
}
}
this.tooltip.fadeIn('fast');
this._hidden = false;
this.tooltip.fadeIn('fast');
this.text.children().remove();
var pre = $('<pre/>').html(utils.fixConsole(docstring));
@ -377,8 +381,7 @@ var IPython = (function (IPython) {
this.text.append(pre);
// keep scroll top to be sure to always see the first line
this.text.scrollTop(0);
}
};
IPython.Tooltip = Tooltip;

Loading…
Cancel
Save