diff --git a/airflow_code_editor/static/addon/lint/lint.js b/airflow_code_editor/static/addon/lint/lint.js index 7b40e10..21631b9 100644 --- a/airflow_code_editor/static/addon/lint/lint.js +++ b/airflow_code_editor/static/addon/lint/lint.js @@ -24,8 +24,10 @@ function position(e) { if (!tt.parentNode) return CodeMirror.off(document, "mousemove", position); - tt.style.top = Math.max(0, e.clientY - tt.offsetHeight - 5) + "px"; - tt.style.left = (e.clientX + 5) + "px"; + var top = Math.max(0, e.clientY - tt.offsetHeight - 5); + var left = Math.max(0, Math.min(e.clientX + 5, tt.ownerDocument.defaultView.innerWidth - tt.offsetWidth)); + tt.style.top = top + "px" + tt.style.left = left + "px"; } CodeMirror.on(document, "mousemove", position); position(e); @@ -199,10 +201,6 @@ var anns = annotations[line]; if (!anns) continue; - // filter out duplicate messages - var message = []; - anns = anns.filter(function(item) { return message.indexOf(item.message) > -1 ? false : message.push(item.message) }); - var maxSeverity = null; var tipLabel = state.hasGutter && document.createDocumentFragment(); @@ -220,9 +218,8 @@ __annotation: ann })); } - // use original annotations[line] to show multiple messages if (state.hasGutter) - cm.setGutterMarker(line, GUTTER_ID, makeMarker(cm, tipLabel, maxSeverity, annotations[line].length > 1, + cm.setGutterMarker(line, GUTTER_ID, makeMarker(cm, tipLabel, maxSeverity, anns.length > 1, options.tooltips)); if (options.highlightLines) diff --git a/airflow_code_editor/static/codemirror.js b/airflow_code_editor/static/codemirror.js index 979586f..7687cd0 100644 --- a/airflow_code_editor/static/codemirror.js +++ b/airflow_code_editor/static/codemirror.js @@ -112,13 +112,14 @@ } while (child = child.parentNode) } - function activeElt(doc) { + function activeElt(rootNode) { // IE and Edge may throw an "Unspecified Error" when accessing document.activeElement. // IE < 10 will throw when accessed while the page is loading or in an iframe. // IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable. + var doc = rootNode.ownerDocument || rootNode; var activeElement; try { - activeElement = doc.activeElement; + activeElement = rootNode.activeElement; } catch(e) { activeElement = doc.body || null; } @@ -146,6 +147,15 @@ function doc(cm) { return cm.display.wrapper.ownerDocument } + function root(cm) { + return rootNode(cm.display.wrapper) + } + + function rootNode(element) { + // Detect modern browsers (2017+). + return element.getRootNode ? element.getRootNode() : element.ownerDocument + } + function win(cm) { return doc(cm).defaultView } function bind(f) { @@ -3900,7 +3910,7 @@ cm.display.maxLineChanged = false; } - var takeFocus = op.focus && op.focus == activeElt(doc(cm)); + var takeFocus = op.focus && op.focus == activeElt(root(cm)); if (op.preparedSelection) { cm.display.input.showSelection(op.preparedSelection, takeFocus); } if (op.updatedDisplay || op.startHeight != cm.doc.height) @@ -4077,7 +4087,7 @@ function selectionSnapshot(cm) { if (cm.hasFocus()) { return null } - var active = activeElt(doc(cm)); + var active = activeElt(root(cm)); if (!active || !contains(cm.display.lineDiv, active)) { return null } var result = {activeElt: active}; if (window.getSelection) { @@ -4093,7 +4103,7 @@ } function restoreSelection(snapshot) { - if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt(snapshot.activeElt.ownerDocument)) { return } + if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt(rootNode(snapshot.activeElt))) { return } snapshot.activeElt.focus(); if (!/^(INPUT|TEXTAREA)$/.test(snapshot.activeElt.nodeName) && snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) { @@ -7264,7 +7274,7 @@ function onKeyDown(e) { var cm = this; if (e.target && e.target != cm.display.input.getField()) { return } - cm.curOp.focus = activeElt(doc(cm)); + cm.curOp.focus = activeElt(root(cm)); if (signalDOMEvent(cm, e)) { return } // IE does strange things with escape. if (ie && ie_version < 11 && e.keyCode == 27) { e.returnValue = false; } @@ -7426,7 +7436,7 @@ function leftButtonDown(cm, pos, repeat, event) { if (ie) { setTimeout(bind(ensureFocus, cm), 0); } - else { cm.curOp.focus = activeElt(doc(cm)); } + else { cm.curOp.focus = activeElt(root(cm)); } var behavior = configureMouse(cm, repeat, event); @@ -7496,19 +7506,19 @@ // Normal selection, as opposed to text dragging. function leftButtonSelect(cm, event, start, behavior) { if (ie) { delayBlurEvent(cm); } - var display = cm.display, doc$1 = cm.doc; + var display = cm.display, doc = cm.doc; e_preventDefault(event); - var ourRange, ourIndex, startSel = doc$1.sel, ranges = startSel.ranges; + var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges; if (behavior.addNew && !behavior.extend) { - ourIndex = doc$1.sel.contains(start); + ourIndex = doc.sel.contains(start); if (ourIndex > -1) { ourRange = ranges[ourIndex]; } else { ourRange = new Range(start, start); } } else { - ourRange = doc$1.sel.primary(); - ourIndex = doc$1.sel.primIndex; + ourRange = doc.sel.primary(); + ourIndex = doc.sel.primIndex; } if (behavior.unit == "rectangle") { @@ -7525,18 +7535,18 @@ if (!behavior.addNew) { ourIndex = 0; - setSelection(doc$1, new Selection([ourRange], 0), sel_mouse); - startSel = doc$1.sel; + setSelection(doc, new Selection([ourRange], 0), sel_mouse); + startSel = doc.sel; } else if (ourIndex == -1) { ourIndex = ranges.length; - setSelection(doc$1, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex), + setSelection(doc, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex), {scroll: false, origin: "*mouse"}); } else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) { - setSelection(doc$1, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0), + setSelection(doc, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0), {scroll: false, origin: "*mouse"}); - startSel = doc$1.sel; + startSel = doc.sel; } else { - replaceOneSelection(doc$1, ourIndex, ourRange, sel_mouse); + replaceOneSelection(doc, ourIndex, ourRange, sel_mouse); } var lastPos = start; @@ -7546,19 +7556,19 @@ if (behavior.unit == "rectangle") { var ranges = [], tabSize = cm.options.tabSize; - var startCol = countColumn(getLine(doc$1, start.line).text, start.ch, tabSize); - var posCol = countColumn(getLine(doc$1, pos.line).text, pos.ch, tabSize); + var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize); + var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize); var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol); for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line)); line <= end; line++) { - var text = getLine(doc$1, line).text, leftPos = findColumn(text, left, tabSize); + var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize); if (left == right) { ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))); } else if (text.length > leftPos) { ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))); } } if (!ranges.length) { ranges.push(new Range(start, start)); } - setSelection(doc$1, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex), + setSelection(doc, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex), {origin: "*mouse", scroll: false}); cm.scrollIntoView(pos); } else { @@ -7573,8 +7583,8 @@ anchor = maxPos(oldRange.to(), range.head); } var ranges$1 = startSel.ranges.slice(0); - ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc$1, anchor), head)); - setSelection(doc$1, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse); + ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc, anchor), head)); + setSelection(doc, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse); } } @@ -7590,9 +7600,9 @@ var cur = posFromMouse(cm, e, true, behavior.unit == "rectangle"); if (!cur) { return } if (cmp(cur, lastPos) != 0) { - cm.curOp.focus = activeElt(doc(cm)); + cm.curOp.focus = activeElt(root(cm)); extendTo(cur); - var visible = visibleLines(display, doc$1); + var visible = visibleLines(display, doc); if (cur.line >= visible.to || cur.line < visible.from) { setTimeout(operation(cm, function () {if (counter == curCount) { extend(e); }}), 150); } } else { @@ -7617,7 +7627,7 @@ } off(display.wrapper.ownerDocument, "mousemove", move); off(display.wrapper.ownerDocument, "mouseup", up); - doc$1.history.lastSelOrigin = null; + doc.history.lastSelOrigin = null; } var move = operation(cm, function (e) { @@ -8617,7 +8627,7 @@ signal(this, "overwriteToggle", this, this.state.overwrite); }, - hasFocus: function() { return this.display.input.getField() == activeElt(doc(this)) }, + hasFocus: function() { return this.display.input.getField() == activeElt(root(this)) }, isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) }, scrollTo: methodOp(function (x, y) { scrollToCoords(this, x, y); }), @@ -8899,7 +8909,7 @@ disableBrowserMagic(te); cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild); te.value = lastCopied.text.join("\n"); - var hadFocus = activeElt(div.ownerDocument); + var hadFocus = activeElt(rootNode(div)); selectInput(te); setTimeout(function () { cm.display.lineSpace.removeChild(kludge); @@ -8922,7 +8932,7 @@ ContentEditableInput.prototype.prepareSelection = function () { var result = prepareSelection(this.cm, false); - result.focus = activeElt(this.div.ownerDocument) == this.div; + result.focus = activeElt(rootNode(this.div)) == this.div; return result }; @@ -9018,7 +9028,7 @@ ContentEditableInput.prototype.focus = function () { if (this.cm.options.readOnly != "nocursor") { - if (!this.selectionInEditor() || activeElt(this.div.ownerDocument) != this.div) + if (!this.selectionInEditor() || activeElt(rootNode(this.div)) != this.div) { this.showSelection(this.prepareSelection(), true); } this.div.focus(); } @@ -9526,7 +9536,7 @@ TextareaInput.prototype.supportsTouch = function () { return false }; TextareaInput.prototype.focus = function () { - if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt(this.textarea.ownerDocument) != this.textarea)) { + if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt(rootNode(this.textarea)) != this.textarea)) { try { this.textarea.focus(); } catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM } @@ -9733,7 +9743,7 @@ // Set autofocus to true if this textarea is focused, or if it has // autofocus and no other element is focused. if (options.autofocus == null) { - var hasFocus = activeElt(textarea.ownerDocument); + var hasFocus = activeElt(rootNode(textarea)); options.autofocus = hasFocus == textarea || textarea.getAttribute("autofocus") != null && hasFocus == document.body; } @@ -9867,7 +9877,7 @@ addLegacyProps(CodeMirror); - CodeMirror.version = "5.65.13"; + CodeMirror.version = "5.65.16"; return CodeMirror; diff --git a/airflow_code_editor/static/mode/clike/clike.js b/airflow_code_editor/static/mode/clike/clike.js index fcfc7c4..e9f441f 100644 --- a/airflow_code_editor/static/mode/clike/clike.js +++ b/airflow_code_editor/static/mode/clike/clike.js @@ -218,7 +218,8 @@ CodeMirror.defineMode("clike", function(config, parserConfig) { }, indent: function(state, textAfter) { - if (state.tokenize != tokenBase && state.tokenize != null || state.typeAtEndOfLine) return CodeMirror.Pass; + if (state.tokenize != tokenBase && state.tokenize != null || state.typeAtEndOfLine && isTopScope(state.context)) + return CodeMirror.Pass; var ctx = state.context, firstChar = textAfter && textAfter.charAt(0); var closing = firstChar == ctx.type; if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev; diff --git a/airflow_code_editor/static/mode/clike/test.js b/airflow_code_editor/static/mode/clike/test.js index 80d8ea4..2933a00 100644 --- a/airflow_code_editor/static/mode/clike/test.js +++ b/airflow_code_editor/static/mode/clike/test.js @@ -162,4 +162,9 @@ "[type StringBuffer];", "[type StringBuilder];", "[type Void];"); + + MTJAVA("indent", + "[keyword public] [keyword class] [def A] [keyword extends] [variable B]", + "{", + " [variable c]()") })(); diff --git a/airflow_code_editor/static/mode/dart/dart.js b/airflow_code_editor/static/mode/dart/dart.js index f81e4f9..ba9ff3d 100644 --- a/airflow_code_editor/static/mode/dart/dart.js +++ b/airflow_code_editor/static/mode/dart/dart.js @@ -15,7 +15,7 @@ "implements mixin get native set typedef with enum throw rethrow assert break case " + "continue default in return new deferred async await covariant try catch finally " + "do else for if switch while import library export part of show hide is as extension " + - "on yield late required sealed base interface when inline").split(" "); + "on yield late required sealed base interface when").split(" "); var blockKeywords = "try catch finally do else for if switch while".split(" "); var atoms = "true false null".split(" "); var builtins = "void bool num int double dynamic var String Null Never".split(" "); diff --git a/airflow_code_editor/static/mode/dart/index.html b/airflow_code_editor/static/mode/dart/index.html index 88b8936..ee6128c 100644 --- a/airflow_code_editor/static/mode/dart/index.html +++ b/airflow_code_editor/static/mode/dart/index.html @@ -29,33 +29,33 @@

Dart mode

import 'dart:math' show Random; void main() { - print(new Die(n: 12).roll()); + print(Die(n: 12).roll()); } // Define a class. class Die { // Define a class variable. - static Random shaker = new Random(); + static final Random shaker = Random(); // Define instance variables. - int sides, value; - - // Define a method using shorthand syntax. - String toString() => '$value'; + final int sides; + int? lastRoll; // Define a constructor. - Die({int n: 6}) { - if (4 <= n && n <= 20) { - sides = n; - } else { + Die({int n = 6}) : sides = n { + if (4 > n || n > 20) { // Support for errors and exceptions. - throw new ArgumentError(/* */); + throw ArgumentError(/* */); } } + // Define a method using shorthand syntax. + @override + String toString() => '$lastRoll'; + // Define an instance method. int roll() { - return value = shaker.nextInt(sides) + 1; + return lastRoll = shaker.nextInt(sides) + 1; } } diff --git a/airflow_code_editor/static/mode/go/go.js b/airflow_code_editor/static/mode/go/go.js index 8dbdc65..bd54f1a 100644 --- a/airflow_code_editor/static/mode/go/go.js +++ b/airflow_code_editor/static/mode/go/go.js @@ -46,11 +46,11 @@ CodeMirror.defineMode("go", function(config) { } if (/[\d\.]/.test(ch)) { if (ch == ".") { - stream.match(/^[0-9]+([eE][\-+]?[0-9]+)?/); + stream.match(/^[0-9_]+([eE][\-+]?[0-9_]+)?/); } else if (ch == "0") { - stream.match(/^[xX][0-9a-fA-F]+/) || stream.match(/^0[0-7]+/); + stream.match(/^[xX][0-9a-fA-F_]+/) || stream.match(/^[0-7_]+/); } else { - stream.match(/^[0-9]*\.?[0-9]*([eE][\-+]?[0-9]+)?/); + stream.match(/^[0-9_]*\.?[0-9_]*([eE][\-+]?[0-9_]+)?/); } return "number"; } diff --git a/airflow_code_editor/static/mode/jsx/jsx.js b/airflow_code_editor/static/mode/jsx/jsx.js index 1406ef1..35ac608 100644 --- a/airflow_code_editor/static/mode/jsx/jsx.js +++ b/airflow_code_editor/static/mode/jsx/jsx.js @@ -103,7 +103,8 @@ } function jsToken(stream, state, cx) { - if (stream.peek() == "<" && jsMode.expressionAllowed(stream, cx.state)) { + if (stream.peek() == "<" && !stream.match(/^<([^<>]|<[^>]*>)+,\s*>/, false) && + jsMode.expressionAllowed(stream, cx.state)) { state.context = new Context(CodeMirror.startState(xmlMode, jsMode.indent(cx.state, "", "")), xmlMode, 0, state.context) jsMode.skipExpression(cx.state) diff --git a/airflow_code_editor/static/mode/jsx/test.js b/airflow_code_editor/static/mode/jsx/test.js index 08a0d47..6065573 100644 --- a/airflow_code_editor/static/mode/jsx/test.js +++ b/airflow_code_editor/static/mode/jsx/test.js @@ -95,4 +95,6 @@ "[bracket&tag <][tag MyComponent] [attribute foo]=[string \"bar\"] [bracket&tag />]; [comment //ok]", "[bracket&tag <][tag MyComponent] [attribute foo]={[number 0]} [bracket&tag />]; [comment //error]") + TS("tsx_react_generics", + "[variable x] [operator =] [operator <] [variable T],[operator >] ([def v]: [type T]) [operator =>] [variable-2 v];") })() diff --git a/airflow_code_editor/static/mode/nsis/nsis.js b/airflow_code_editor/static/mode/nsis/nsis.js index 2173916..de18871 100644 --- a/airflow_code_editor/static/mode/nsis/nsis.js +++ b/airflow_code_editor/static/mode/nsis/nsis.js @@ -24,7 +24,7 @@ CodeMirror.defineSimpleMode("nsis",{ { regex: /`(?:[^\\`]|\\.)*`?/, token: "string" }, // Compile Time Commands - {regex: /^\s*(?:\!(addincludedir|addplugindir|appendfile|cd|define|delfile|echo|error|execute|finalize|getdllversion|gettlbversion|include|insertmacro|macro|macroend|makensis|packhdr|pragma|searchparse|searchreplace|system|tempfile|undef|uninstfinalize|verbose|warning))\b/i, token: "keyword"}, + {regex: /^\s*(?:\!(addincludedir|addplugindir|appendfile|assert|cd|define|delfile|echo|error|execute|finalize|getdllversion|gettlbversion|include|insertmacro|macro|macroend|makensis|packhdr|pragma|searchparse|searchreplace|system|tempfile|undef|uninstfinalize|verbose|warning))\b/i, token: "keyword"}, // Conditional Compilation {regex: /^\s*(?:\!(if(?:n?def)?|ifmacron?def|macro))\b/i, token: "keyword", indent: true}, diff --git a/airflow_code_editor/static/mode/yaml/yaml.js b/airflow_code_editor/static/mode/yaml/yaml.js index 298db55..895d133 100644 --- a/airflow_code_editor/static/mode/yaml/yaml.js +++ b/airflow_code_editor/static/mode/yaml/yaml.js @@ -85,7 +85,7 @@ CodeMirror.defineMode("yaml", function() { } /* pairs (associative arrays) -> key */ - if (!state.pair && stream.match(/^\s*(?:[,\[\]{}&*!|>'"%@`][^\s'":]|[^,\[\]{}#&*!|>'"%@`])[^#]*?(?=\s*:($|\s))/)) { + if (!state.pair && stream.match(/^\s*(?:[,\[\]{}&*!|>'"%@`][^\s'":]|[^\s,\[\]{}#&*!|>'"%@`])[^#:]*(?=:($|\s))/)) { state.pair = true; state.keyCol = stream.indentation(); return "atom";