Skip to content

Commit

Permalink
Upgrade CodeMirror
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Bonomi committed Jan 8, 2022
1 parent 7fbf952 commit d970fb8
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 49 deletions.
2 changes: 1 addition & 1 deletion airflow_code_editor/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.3
5.1.4
58 changes: 30 additions & 28 deletions airflow_code_editor/static/addon/fold/brace-fold.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

CodeMirror.registerHelper("fold", "brace", function(cm, start) {
var line = start.line, lineText = cm.getLine(line);
var tokenType;

function findOpening(openCh) {
var tokenType;
for (var at = start.ch, pass = 0;;) {
var found = at <= 0 ? -1 : lineText.lastIndexOf(openCh, at - 1);
if (found == -1) {
Expand All @@ -26,40 +26,42 @@ CodeMirror.registerHelper("fold", "brace", function(cm, start) {
}
if (pass == 1 && found < start.ch) break;
tokenType = cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1));
if (!/^(comment|string)/.test(tokenType)) return found + 1;
if (!/^(comment|string)/.test(tokenType)) return {ch: found + 1, tokenType: tokenType};
at = found - 1;
}
}

var startBrace = findOpening("{"), startBracket = findOpening("[")
var startToken, endToken, startCh
if (startBrace != null && (startBracket == null || startBracket > startBrace)) {
startCh = startBrace; startToken = "{"; endToken = "}"
} else if (startBracket != null) {
startCh = startBracket; startToken = "["; endToken = "]"
} else {
return
}

var count = 1, lastLine = cm.lastLine(), end, endCh;
outer: for (var i = line; i <= lastLine; ++i) {
var text = cm.getLine(i), pos = i == line ? startCh : 0;
for (;;) {
var nextOpen = text.indexOf(startToken, pos), nextClose = text.indexOf(endToken, pos);
if (nextOpen < 0) nextOpen = text.length;
if (nextClose < 0) nextClose = text.length;
pos = Math.min(nextOpen, nextClose);
if (pos == text.length) break;
if (cm.getTokenTypeAt(CodeMirror.Pos(i, pos + 1)) == tokenType) {
if (pos == nextOpen) ++count;
else if (!--count) { end = i; endCh = pos; break outer; }
function findRange(startToken, endToken, found) {
var count = 1, lastLine = cm.lastLine(), end, startCh = found.ch, endCh
outer: for (var i = line; i <= lastLine; ++i) {
var text = cm.getLine(i), pos = i == line ? startCh : 0;
for (;;) {
var nextOpen = text.indexOf(startToken, pos), nextClose = text.indexOf(endToken, pos);
if (nextOpen < 0) nextOpen = text.length;
if (nextClose < 0) nextClose = text.length;
pos = Math.min(nextOpen, nextClose);
if (pos == text.length) break;
if (cm.getTokenTypeAt(CodeMirror.Pos(i, pos + 1)) == found.tokenType) {
if (pos == nextOpen) ++count;
else if (!--count) { end = i; endCh = pos; break outer; }
}
++pos;
}
++pos;
}

if (end == null || line == end) return null
return {from: CodeMirror.Pos(line, startCh),
to: CodeMirror.Pos(end, endCh)};
}

var startBrace = findOpening("{"), startBracket = findOpening("[")
if (startBrace && (!startBracket || startBracket.ch > startBrace.ch)) {
return findRange("{", "}", startBrace) || (startBracket && findRange("[", "]", startBracket))
} else if (startBracket) {
return findRange("[", "]", startBracket) || (startBrace && findRange("{", "}", startBrace))
} else {
return null
}
if (end == null || line == end) return;
return {from: CodeMirror.Pos(line, startCh),
to: CodeMirror.Pos(end, endCh)};
});

CodeMirror.registerHelper("fold", "import", function(cm, start) {
Expand Down
2 changes: 1 addition & 1 deletion airflow_code_editor/static/airflow_code_editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion airflow_code_editor/static/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -9840,7 +9840,7 @@

addLegacyProps(CodeMirror);

CodeMirror.version = "5.64.0";
CodeMirror.version = "5.65.0";

return CodeMirror;

Expand Down
2 changes: 1 addition & 1 deletion airflow_code_editor/static/mode/factor/factor.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
// specific to simple modes.
meta: {
dontIndentStates: ["start", "vocabulary", "string", "string3", "stack"],
lineComment: [ "!", "#!" ]
lineComment: "!"
}
});

Expand Down
6 changes: 3 additions & 3 deletions airflow_code_editor/static/mode/nsis/nsis.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ CodeMirror.defineSimpleMode("nsis",{
{regex: /[-+\/*=<>!]+/, token: "operator"},

// Variable
{regex: /\$\w+/, token: "variable"},
{regex: /\$\w[\w\.]*/, token: "variable"},

// Constant
{regex: /\${[\w\.:-]+}/, token: "variable-2"},
{regex: /\${[\!\w\.:-]+}/, token: "variable-2"},

// Language String
{regex: /\$\([\w\.:-]+\)/, token: "variable-3"}
{regex: /\$\([\!\w\.:-]+\)/, token: "variable-3"}
],
comment: [
{regex: /.*?\*\//, token: "comment", next: "start"},
Expand Down
38 changes: 28 additions & 10 deletions airflow_code_editor/static/mode/scheme/scheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

/**
* Author: Koh Zi Han, based on implementation by Koh Zi Chun
* Improved by: Jakub T. Jankiewicz
*/

(function(mod) {
Expand All @@ -17,7 +18,7 @@

CodeMirror.defineMode("scheme", function () {
var BUILTIN = "builtin", COMMENT = "comment", STRING = "string",
ATOM = "atom", NUMBER = "number", BRACKET = "bracket";
SYMBOL = "symbol", ATOM = "atom", NUMBER = "number", BRACKET = "bracket";
var INDENT_WORD_SKIP = 2;

function makeKeywords(str) {
Expand Down Expand Up @@ -67,6 +68,18 @@ CodeMirror.defineMode("scheme", function () {
return stream.match(hexMatcher);
}

function processEscapedSequence(stream, options) {
var next, escaped = false;
while ((next = stream.next()) != null) {
if (next == options.token && !escaped) {

options.state.mode = false;
break;
}
escaped = !escaped && next == "\\";
}
}

return {
startState: function () {
return {
Expand All @@ -92,17 +105,19 @@ CodeMirror.defineMode("scheme", function () {

switch(state.mode){
case "string": // multi-line string parsing mode
var next, escaped = false;
while ((next = stream.next()) != null) {
if (next == "\"" && !escaped) {

state.mode = false;
break;
}
escaped = !escaped && next == "\\";
}
processEscapedSequence(stream, {
token: "\"",
state: state
});
returnType = STRING; // continue on in scheme-string mode
break;
case "symbol": // escape symbol
processEscapedSequence(stream, {
token: "|",
state: state
});
returnType = SYMBOL; // continue on in scheme-symbol mode
break;
case "comment": // comment parsing mode
var next, maybeEnd = false;
while ((next = stream.next()) != null) {
Expand Down Expand Up @@ -143,6 +158,9 @@ CodeMirror.defineMode("scheme", function () {
stream.eatWhile(/[\w_\-!$%&*+\.\/:<=>?@\^~]/);
returnType = ATOM;
}
} else if (ch == '|') {
state.mode = "symbol";
returnType = SYMBOL;
} else if (ch == '#') {
if (stream.eat("|")) { // Multi-line comment
state.mode = "comment"; // toggle to comment mode
Expand Down
16 changes: 16 additions & 0 deletions airflow_code_editor/static/vim.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
{ keys: '<Right>', type: 'keyToKey', toKeys: 'l' },
{ keys: '<Up>', type: 'keyToKey', toKeys: 'k' },
{ keys: '<Down>', type: 'keyToKey', toKeys: 'j' },
{ keys: 'g<Up>', type: 'keyToKey', toKeys: 'gk' },
{ keys: 'g<Down>', type: 'keyToKey', toKeys: 'gj' },
{ keys: '<Space>', type: 'keyToKey', toKeys: 'l' },
{ keys: '<BS>', type: 'keyToKey', toKeys: 'h', context: 'normal'},
{ keys: '<Del>', type: 'keyToKey', toKeys: 'x', context: 'normal'},
Expand All @@ -94,6 +96,7 @@
{ keys: '<PageUp>', type: 'keyToKey', toKeys: '<C-b>' },
{ keys: '<PageDown>', type: 'keyToKey', toKeys: '<C-f>' },
{ keys: '<CR>', type: 'keyToKey', toKeys: 'j^', context: 'normal' },
{ keys: '<Ins>', type: 'keyToKey', toKeys: 'i', context: 'normal'},
{ keys: '<Ins>', type: 'action', action: 'toggleOverwrite', context: 'insert' },
// Motions
{ keys: 'H', type: 'motion', motion: 'moveToTopLine', motionArgs: { linewise: true, toJumplist: true }},
Expand Down Expand Up @@ -123,6 +126,9 @@
{ keys: '<C-u>', type: 'motion', motion: 'moveByScroll', motionArgs: { forward: false, explicitRepeat: true }},
{ keys: 'gg', type: 'motion', motion: 'moveToLineOrEdgeOfDocument', motionArgs: { forward: false, explicitRepeat: true, linewise: true, toJumplist: true }},
{ keys: 'G', type: 'motion', motion: 'moveToLineOrEdgeOfDocument', motionArgs: { forward: true, explicitRepeat: true, linewise: true, toJumplist: true }},
{keys: "g$", type: "motion", motion: "moveToEndOfDisplayLine"},
{keys: "g^", type: "motion", motion: "moveToStartOfDisplayLine"},
{keys: "g0", type: "motion", motion: "moveToStartOfDisplayLine"},
{ keys: '0', type: 'motion', motion: 'moveToStartOfLine' },
{ keys: '^', type: 'motion', motion: 'moveToFirstNonWhiteSpaceCharacter' },
{ keys: '+', type: 'motion', motion: 'moveByLines', motionArgs: { forward: true, toFirstChar:true }},
Expand Down Expand Up @@ -2086,6 +2092,16 @@
return new Pos(lineNum,
findFirstNonWhiteSpaceCharacter(cm.getLine(lineNum)));
},
moveToStartOfDisplayLine: function(cm) {
cm.execCommand("goLineLeft");
return cm.getCursor();
},
moveToEndOfDisplayLine: function(cm) {
cm.execCommand("goLineRight");
var head = cm.getCursor();
if (head.sticky == "before") head.ch--;
return head;
},
textObjectManipulation: function(cm, head, motionArgs, vim) {
// TODO: lots of possible exceptions that can be thrown here. Try da(
// outside of a () block.
Expand Down
13 changes: 10 additions & 3 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,14 @@

## 5.1.1

2020-10-17
2021-10-17

### Changed
- CodeMirror upgrade

## 5.1.2

2020-10-23
2021-10-23

### Changed

Expand All @@ -299,7 +299,7 @@

## 5.1.3

2020-12-04
2021-12-04

### Changed

Expand All @@ -308,3 +308,10 @@
### Fix

- Fix empty files list

## 5.1.4

2022-01-08

### Changed
- CodeMirror upgrade
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "airflow-code-editor",
"version": "5.1.3",
"version": "5.1.4",
"description": "A plugin for [Apache Airflow](https://github.com/apache/airflow) that allows you to edit DAGs in browser. It provides a file managing interface within specified directories and it can be used to edit and download your files. If git support is enabled, the DAGs are stored in a Git repository. You may use it to view Git history, review local changes and commit.",
"private": true,
"directories": {
Expand Down

0 comments on commit d970fb8

Please sign in to comment.