-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Dual mode bug fixes. #5146
Changes from all commits
dd3841a
c34bd56
9ad744d
d8d7f5e
588bdf1
96d3ec2
63e3096
a5dd988
613dbf8
5f9cdbf
826236c
bbf444a
d54db33
4318928
37f8846
2e6bff8
7018374
86a628e
2e7589d
c2015f9
24510be
4ed449c
676cf36
3683400
8b012de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,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. | ||
|
@@ -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,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 () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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,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){ | ||
|
@@ -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); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tooltip testing that is in the |
||
|
||
CodeCell.prototype.select_all = function () { | ||
var start = {line: 0, ch: 0}; | ||
|
There was a problem hiding this comment.
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
.