Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dual mode bug fixes. #5146

Merged
merged 25 commits into from
Feb 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dd3841a
jshint
jdfreder Feb 18, 2014
c34bd56
DEBUG
jdfreder Feb 18, 2014
9ad744d
Fixed lots of bugs
jdfreder Feb 24, 2014
d8d7f5e
Use is_focused for element kbman removal event
jdfreder Feb 25, 2014
588bdf1
Added cell unfocus event canceller API
jdfreder Feb 25, 2014
96d3ec2
Fixed rebase problems
jdfreder Feb 26, 2014
63e3096
Post in person review
jdfreder Feb 26, 2014
a5dd988
s/unfocus/blur
jdfreder Feb 26, 2014
613dbf8
Removed change that is no longer needed
jdfreder Feb 26, 2014
5f9cdbf
Standardized comments and removed last logs
jdfreder Feb 26, 2014
826236c
Moved edit_mode canceling logic back into cell.
jdfreder Feb 27, 2014
bbf444a
Always refresh the CM editor upon TextCell unrender.
ellisonbg Feb 27, 2014
d54db33
Remove fixes that are implemented correct in new CM
jdfreder Feb 27, 2014
4318928
Reorg index and focus_editor params on edit_mode func
jdfreder Feb 27, 2014
37f8846
Final touches?
jdfreder Feb 28, 2014
2e6bff8
Updated components to point to head
jdfreder Feb 28, 2014
7018374
Re-added widget textbox blur fix FF
jdfreder Feb 28, 2014
86a628e
implemented whiteboard logic
jdfreder Feb 28, 2014
2e7589d
Merge pull request #18 from jdfreder/modal-rewrite
jdfreder Feb 28, 2014
c2015f9
Couple of whiteboard logic implementation misses
jdfreder Feb 28, 2014
24510be
Remove notebook load log succes
jdfreder Feb 28, 2014
4ed449c
Move should cancel blur into codecell
jdfreder Feb 28, 2014
676cf36
Added comments to kbm and shrunk focus_cell lines
jdfreder Feb 28, 2014
3683400
Re-added removed refresh
jdfreder Feb 28, 2014
8b012de
s/trigger_edit_mode/edit_mode
jdfreder Feb 28, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion IPython/html/static/components
89 changes: 41 additions & 48 deletions IPython/html/static/notebook/js/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -76,20 +75,16 @@ 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;
}

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.
Expand Down Expand Up @@ -118,8 +113,7 @@ var IPython = (function (IPython) {
} else {
this.element.addClass('command_mode');
}
}

};

/**
* Subclasses can implement override bind_events.
Expand All @@ -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) {
Expand All @@ -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()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert this back to edit_mode.Cell.

$([IPython.events]).trigger('command_mode.Cell', {cell: that});
}
});
}
Expand Down Expand Up @@ -273,32 +259,38 @@ 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 () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good here.

return false;
};

/**
* Focus the cell in the DOM sense
* @method focus_cell
*/
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
Expand Down Expand Up @@ -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;
}
};


/**
Expand All @@ -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;
Expand Down Expand Up @@ -430,32 +422,33 @@ 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;
}
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){
Expand All @@ -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);
};
Expand Down
21 changes: 14 additions & 7 deletions IPython/html/static/notebook/js/codecell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tooltip testing that is in the notebook.js version of this should be moved here. Cell already depends on Tooltip so this is fine. This keeps this logic out of notebook.js entirely.


CodeCell.prototype.select_all = function () {
var start = {line: 0, ch: 0};
Expand Down
7 changes: 7 additions & 0 deletions IPython/html/static/notebook/js/completer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -282,6 +288,7 @@ var IPython = (function (IPython) {
};

Completer.prototype.close = function () {
this._visible = false;
if (this.done) return;
this.done = true;
$('.completions').remove();
Expand Down