mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-12 11:45:38 +08:00
Merge pull request #2190 from Carreau/update_code_mirror
Update code mirror 2.22 to 2.32 Update codemirror to the latest stable. And upadte our code here and there to smooth the changes. Just the fact that there is a new tab system that was inserting tabs instead of 4 space, we just have to pass a new line when creating e new CM instance. Should also fix #1464. See Readme-IPython to see what patch to apply when updating next.
This commit is contained in:
commit
4529b2b05c
35
IPython/frontend/html/notebook/static/codemirror/mode/python/python.js
vendored
Executable file → Normal file
35
IPython/frontend/html/notebook/static/codemirror/mode/python/python.js
vendored
Executable file → Normal file
@ -4,8 +4,11 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
|
||||
function wordRegexp(words) {
|
||||
return new RegExp("^((" + words.join(")|(") + "))\\b");
|
||||
}
|
||||
|
||||
|
||||
// IPython-specific changes: add '?' as recognized character.
|
||||
var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\\?]");
|
||||
// End IPython changes.
|
||||
|
||||
var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
|
||||
var doubleOperators = new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))");
|
||||
var doubleDelimiters = new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");
|
||||
@ -249,32 +252,30 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
|
||||
|
||||
// Handle '.' connected identifiers
|
||||
if (current === '.') {
|
||||
style = state.tokenize(stream, state);
|
||||
current = stream.current();
|
||||
if (style === 'variable' || style === 'builtin') {
|
||||
return 'variable';
|
||||
} else {
|
||||
return ERRORCLASS;
|
||||
style = stream.match(identifiers, false) ? null : ERRORCLASS;
|
||||
if (style === null && state.lastToken === 'meta') {
|
||||
// Apply 'meta' style to '.' connected identifiers when
|
||||
// appropriate.
|
||||
style = 'meta';
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
// Handle decorators
|
||||
if (current === '@') {
|
||||
style = state.tokenize(stream, state);
|
||||
current = stream.current();
|
||||
if (style === 'variable'
|
||||
|| current === '@staticmethod'
|
||||
|| current === '@classmethod') {
|
||||
return 'meta';
|
||||
} else {
|
||||
return ERRORCLASS;
|
||||
}
|
||||
return stream.match(identifiers, false) ? 'meta' : ERRORCLASS;
|
||||
}
|
||||
|
||||
if ((style === 'variable' || style === 'builtin')
|
||||
&& state.lastToken === 'meta') {
|
||||
style = 'meta';
|
||||
}
|
||||
|
||||
// Handle scope changes.
|
||||
if (current === 'pass' || current === 'return') {
|
||||
state.dedent += 1;
|
||||
}
|
||||
if (current === 'lambda') state.lambda = true;
|
||||
if ((current === ':' && !state.lambda && state.scopes[0].type == 'py')
|
||||
|| indentInfo === 'indent') {
|
||||
indent(stream, state);
|
||||
@ -316,7 +317,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
|
||||
token: function(stream, state) {
|
||||
var style = tokenLexer(stream, state);
|
||||
|
||||
state.lastToken = {style:style, content: stream.current()};
|
||||
state.lastToken = style;
|
||||
|
||||
if (stream.eol() && stream.lambda) {
|
||||
state.lambda = false;
|
||||
|
@ -41,6 +41,7 @@ var IPython = (function (IPython) {
|
||||
mode: 'python',
|
||||
theme: 'ipython',
|
||||
readOnly: this.read_only,
|
||||
extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess",'Backspace':"delSpaceToPrevTabStop"},
|
||||
onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
|
||||
});
|
||||
input.append(input_area);
|
||||
@ -124,20 +125,6 @@ var IPython = (function (IPython) {
|
||||
this.completer.startCompletion();
|
||||
return true;
|
||||
};
|
||||
} else if (event.keyCode === key.BACKSPACE && event.type == 'keydown') {
|
||||
// If backspace and the line ends with 4 spaces, remove them.
|
||||
var line = editor.getLine(cur.line);
|
||||
var ending = line.slice(-4);
|
||||
if (ending === ' ') {
|
||||
editor.replaceRange('',
|
||||
{line: cur.line, ch: cur.ch-4},
|
||||
{line: cur.line, ch: cur.ch}
|
||||
);
|
||||
event.stop();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
} else {
|
||||
// keypress/keyup also trigger on TAB press, and we don't want to
|
||||
// use those to disable tab completion.
|
||||
|
@ -35,6 +35,7 @@ var IPython = (function (IPython) {
|
||||
value: this.placeholder,
|
||||
readOnly: this.read_only,
|
||||
lineWrapping : true,
|
||||
extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess"},
|
||||
onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this)
|
||||
});
|
||||
// The tabindex=-1 makes this div focusable.
|
||||
|
Loading…
Reference in New Issue
Block a user