Merge pull request #1327 from ellisonbg/updatecm2

Updating CodeMirror to the latest dev master. 

We had found a bug in CodeMirror that was forcing us to call refresh/focus/refresh on Firefox. This bug was fixed upstream. This PR pull in the latest CM with the bug fix and removes the extra refresh calls. All known CM bugs should be fixed, yeh!
This commit is contained in:
Fernando Perez 2012-01-25 22:16:13 -08:00
commit ef1cc56996
3 changed files with 30 additions and 26 deletions

View File

@ -18,28 +18,35 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
'for', 'from', 'global', 'if', 'import',
'lambda', 'pass', 'raise', 'return',
'try', 'while', 'with', 'yield'];
var commontypes = ['bool', 'classmethod', 'complex', 'dict', 'enumerate',
'float', 'frozenset', 'int', 'list', 'object',
'property', 'reversed', 'set', 'slice', 'staticmethod',
'str', 'super', 'tuple', 'type'];
var py2 = {'types': ['basestring', 'buffer', 'file', 'long', 'unicode',
'xrange'],
var commonBuiltins = ['abs', 'all', 'any', 'bin', 'bool', 'bytearray', 'callable', 'chr',
'classmethod', 'compile', 'complex', 'delattr', 'dict', 'dir', 'divmod',
'enumerate', 'eval', 'filter', 'float', 'format', 'frozenset',
'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id',
'input', 'int', 'isinstance', 'issubclass', 'iter', 'len',
'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next',
'object', 'oct', 'open', 'ord', 'pow', 'property', 'range',
'repr', 'reversed', 'round', 'set', 'setattr', 'slice',
'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple',
'type', 'vars', 'zip', '__import__', 'NotImplemented',
'Ellipsis', '__debug__'];
var py2 = {'builtins': ['apply', 'basestring', 'buffer', 'cmp', 'coerce', 'execfile',
'file', 'intern', 'long', 'raw_input', 'reduce', 'reload',
'unichr', 'unicode', 'xrange', 'False', 'True', 'None'],
'keywords': ['exec', 'print']};
var py3 = {'types': ['bytearray', 'bytes', 'filter', 'map', 'memoryview',
'open', 'range', 'zip'],
'keywords': ['nonlocal']};
var py3 = {'builtins': ['ascii', 'bytes', 'exec', 'print'],
'keywords': ['nonlocal', 'False', 'True', 'None']};
if (!!parserConf.version && parseInt(parserConf.version, 10) === 3) {
commonkeywords = commonkeywords.concat(py3.keywords);
commontypes = commontypes.concat(py3.types);
commonBuiltins = commonBuiltins.concat(py3.builtins);
var stringPrefixes = new RegExp("^(([rb]|(br))?('{3}|\"{3}|['\"]))", "i");
} else {
commonkeywords = commonkeywords.concat(py2.keywords);
commontypes = commontypes.concat(py2.types);
commonBuiltins = commonBuiltins.concat(py2.builtins);
var stringPrefixes = new RegExp("^(([rub]|(ur)|(br))?('{3}|\"{3}|['\"]))", "i");
}
var keywords = wordRegexp(commonkeywords);
var types = wordRegexp(commontypes);
var builtins = wordRegexp(commonBuiltins);
var indentInfo = null;
@ -129,14 +136,14 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
return null;
}
if (stream.match(types)) {
return 'builtin';
}
if (stream.match(keywords)) {
return 'keyword';
}
if (stream.match(builtins)) {
return 'builtin';
}
if (stream.match(identifiers)) {
return 'variable';
}
@ -244,7 +251,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
if (current === '.') {
style = state.tokenize(stream, state);
current = stream.current();
if (style === 'variable') {
if (style === 'variable' || style === 'builtin') {
return 'variable';
} else {
return ERRORCLASS;

View File

@ -530,11 +530,11 @@ var IPython = (function (IPython) {
CodeCell.prototype.select = function () {
IPython.Cell.prototype.select.apply(this);
// In some cases (inserting a new cell) we need a refresh before and
// after the focus. Not sure why this is the case.
this.code_mirror.refresh();
this.code_mirror.focus();
this.code_mirror.refresh();
// We used to need an additional refresh() after the focus, but
// it appears that this has been fixed in CM. This bug would show
// up on FF when a newly loaded markdown cell was edited.
};

View File

@ -96,14 +96,11 @@ var IPython = (function (IPython) {
var output = text_cell.find("div.text_cell_render");
output.hide();
text_cell.find('div.text_cell_input').show();
// I don't know why I need to do this, but if I don't do
// refresh/focus/refresh, the to_markdown method won't work.
this.code_mirror.refresh();
this.code_mirror.focus();
// This final refresh is needed on Firefox to trigger the editor
// to be auto-sized. This glitch only happens on cell that are
// loaded initially and haven't had their editor focused before.
this.code_mirror.refresh();
// We used to need an additional refresh() after the focus, but
// it appears that this has been fixed in CM. This bug would show
// up on FF when a newly loaded markdown cell was edited.
this.rendered = false;
if (this.get_text() === this.placeholder) {
this.set_text('');