-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhuhp
committed
Jan 19, 2021
1 parent
30b4cc2
commit a39a533
Showing
15 changed files
with
2,060 additions
and
457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
flink-streaming-web/src/main/resources/static/codemirror/hint/anyword-hint.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// CodeMirror, copyright (c) by Marijn Haverbeke and others | ||
// Distributed under an MIT license: https://codemirror.net/LICENSE | ||
|
||
(function(mod) { | ||
if (typeof exports == "object" && typeof module == "object") // CommonJS | ||
mod(require("../../lib/codemirror")); | ||
else if (typeof define == "function" && define.amd) // AMD | ||
define(["../../lib/codemirror"], mod); | ||
else // Plain browser env | ||
mod(CodeMirror); | ||
})(function(CodeMirror) { | ||
"use strict"; | ||
|
||
var WORD = /[\w$]+/, RANGE = 500; | ||
|
||
CodeMirror.registerHelper("hint", "anyword", function(editor, options) { | ||
var word = options && options.word || WORD; | ||
var range = options && options.range || RANGE; | ||
var cur = editor.getCursor(), curLine = editor.getLine(cur.line); | ||
var end = cur.ch, start = end; | ||
while (start && word.test(curLine.charAt(start - 1))) --start; | ||
var curWord = start != end && curLine.slice(start, end); | ||
|
||
var list = options && options.list || [], seen = {}; | ||
var re = new RegExp(word.source, "g"); | ||
for (var dir = -1; dir <= 1; dir += 2) { | ||
var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir; | ||
for (; line != endLine; line += dir) { | ||
var text = editor.getLine(line), m; | ||
while (m = re.exec(text)) { | ||
if (line == cur.line && m[0] === curWord) continue; | ||
if ((!curWord || m[0].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[0])) { | ||
seen[m[0]] = true; | ||
list.push(m[0]); | ||
} | ||
} | ||
} | ||
} | ||
return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)}; | ||
}); | ||
}); |
66 changes: 66 additions & 0 deletions
66
flink-streaming-web/src/main/resources/static/codemirror/hint/css-hint.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// CodeMirror, copyright (c) by Marijn Haverbeke and others | ||
// Distributed under an MIT license: https://codemirror.net/LICENSE | ||
|
||
(function(mod) { | ||
if (typeof exports == "object" && typeof module == "object") // CommonJS | ||
mod(require("../../lib/codemirror"), require("../../mode/css/css")); | ||
else if (typeof define == "function" && define.amd) // AMD | ||
define(["../../lib/codemirror", "../../mode/css/css"], mod); | ||
else // Plain browser env | ||
mod(CodeMirror); | ||
})(function(CodeMirror) { | ||
"use strict"; | ||
|
||
var pseudoClasses = {"active":1, "after":1, "before":1, "checked":1, "default":1, | ||
"disabled":1, "empty":1, "enabled":1, "first-child":1, "first-letter":1, | ||
"first-line":1, "first-of-type":1, "focus":1, "hover":1, "in-range":1, | ||
"indeterminate":1, "invalid":1, "lang":1, "last-child":1, "last-of-type":1, | ||
"link":1, "not":1, "nth-child":1, "nth-last-child":1, "nth-last-of-type":1, | ||
"nth-of-type":1, "only-of-type":1, "only-child":1, "optional":1, "out-of-range":1, | ||
"placeholder":1, "read-only":1, "read-write":1, "required":1, "root":1, | ||
"selection":1, "target":1, "valid":1, "visited":1 | ||
}; | ||
|
||
CodeMirror.registerHelper("hint", "css", function(cm) { | ||
var cur = cm.getCursor(), token = cm.getTokenAt(cur); | ||
var inner = CodeMirror.innerMode(cm.getMode(), token.state); | ||
if (inner.mode.name != "css") return; | ||
|
||
if (token.type == "keyword" && "!important".indexOf(token.string) == 0) | ||
return {list: ["!important"], from: CodeMirror.Pos(cur.line, token.start), | ||
to: CodeMirror.Pos(cur.line, token.end)}; | ||
|
||
var start = token.start, end = cur.ch, word = token.string.slice(0, end - start); | ||
if (/[^\w$_-]/.test(word)) { | ||
word = ""; start = end = cur.ch; | ||
} | ||
|
||
var spec = CodeMirror.resolveMode("text/css"); | ||
|
||
var result = []; | ||
function add(keywords) { | ||
for (var name in keywords) | ||
if (!word || name.lastIndexOf(word, 0) == 0) | ||
result.push(name); | ||
} | ||
|
||
var st = inner.state.state; | ||
if (st == "pseudo" || token.type == "variable-3") { | ||
add(pseudoClasses); | ||
} else if (st == "block" || st == "maybeprop") { | ||
add(spec.propertyKeywords); | ||
} else if (st == "prop" || st == "parens" || st == "at" || st == "params") { | ||
add(spec.valueKeywords); | ||
add(spec.colorKeywords); | ||
} else if (st == "media" || st == "media_parens") { | ||
add(spec.mediaTypes); | ||
add(spec.mediaFeatures); | ||
} | ||
|
||
if (result.length) return { | ||
list: result, | ||
from: CodeMirror.Pos(cur.line, start), | ||
to: CodeMirror.Pos(cur.line, end) | ||
}; | ||
}); | ||
}); |
108 changes: 108 additions & 0 deletions
108
flink-streaming-web/src/main/resources/static/codemirror/hint/formatting.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
(function() { | ||
|
||
CodeMirror.extendMode("css", { | ||
commentStart: "/*", | ||
commentEnd: "*/", | ||
newlineAfterToken: function(type, content) { | ||
return /^[;{}]$/.test(content); | ||
} | ||
}); | ||
|
||
CodeMirror.extendMode("javascript", { | ||
commentStart: "/*", | ||
commentEnd: "*/", | ||
// FIXME semicolons inside of for | ||
newlineAfterToken: function(type, content, textAfter, state) { | ||
if (this.jsonMode) { | ||
return /^[\[,{]$/.test(content) || /^}/.test(textAfter); | ||
} else { | ||
if (content == ";" && state.lexical && state.lexical.type == ")") return false; | ||
return /^[;{}]$/.test(content) && !/^;/.test(textAfter); | ||
} | ||
} | ||
}); | ||
|
||
CodeMirror.extendMode("xml", { | ||
commentStart: "<!--", | ||
commentEnd: "-->", | ||
newlineAfterToken: function(type, content, textAfter) { | ||
return type == "tag" && />$/.test(content) || /^</.test(textAfter); | ||
} | ||
}); | ||
|
||
// Comment/uncomment the specified range | ||
CodeMirror.defineExtension("commentRange", function (isComment, from, to) { | ||
var cm = this, curMode = CodeMirror.innerMode(cm.getMode(), cm.getTokenAt(from).state).mode; | ||
cm.operation(function() { | ||
if (isComment) { // Comment range | ||
cm.replaceRange(curMode.commentEnd, to); | ||
cm.replaceRange(curMode.commentStart, from); | ||
if (from.line == to.line && from.ch == to.ch) // An empty comment inserted - put cursor inside | ||
cm.setCursor(from.line, from.ch + curMode.commentStart.length); | ||
} else { // Uncomment range | ||
var selText = cm.getRange(from, to); | ||
var startIndex = selText.indexOf(curMode.commentStart); | ||
var endIndex = selText.lastIndexOf(curMode.commentEnd); | ||
if (startIndex > -1 && endIndex > -1 && endIndex > startIndex) { | ||
// Take string till comment start | ||
selText = selText.substr(0, startIndex) | ||
// From comment start till comment end | ||
+ selText.substring(startIndex + curMode.commentStart.length, endIndex) | ||
// From comment end till string end | ||
+ selText.substr(endIndex + curMode.commentEnd.length); | ||
} | ||
cm.replaceRange(selText, from, to); | ||
} | ||
}); | ||
}); | ||
|
||
// Applies automatic mode-aware indentation to the specified range | ||
CodeMirror.defineExtension("autoIndentRange", function (from, to) { | ||
var cmInstance = this; | ||
this.operation(function () { | ||
for (var i = from.line; i <= to.line; i++) { | ||
cmInstance.indentLine(i, "smart"); | ||
} | ||
}); | ||
}); | ||
|
||
// Applies automatic formatting to the specified range | ||
CodeMirror.defineExtension("autoFormatRange", function (from, to) { | ||
var cm = this; | ||
var outer = cm.getMode(), text = cm.getRange(from, to).split("\n"); | ||
var state = CodeMirror.copyState(outer, cm.getTokenAt(from).state); | ||
var tabSize = cm.getOption("tabSize"); | ||
|
||
var out = "", lines = 0, atSol = from.ch == 0; | ||
function newline() { | ||
out += "\n"; | ||
atSol = true; | ||
++lines; | ||
} | ||
|
||
for (var i = 0; i < text.length; ++i) { | ||
var stream = new CodeMirror.StringStream(text[i], tabSize); | ||
while (!stream.eol()) { | ||
var inner = CodeMirror.innerMode(outer, state); | ||
var style = outer.token(stream, state), cur = stream.current(); | ||
stream.start = stream.pos; | ||
if (!atSol || /\S/.test(cur)) { | ||
out += cur; | ||
atSol = false; | ||
} | ||
if (!atSol && inner.mode.newlineAfterToken && | ||
inner.mode.newlineAfterToken(style, cur, stream.string.slice(stream.pos) || text[i+1] || "", inner.state)) | ||
newline(); | ||
} | ||
if (!stream.pos && outer.blankLine) outer.blankLine(state); | ||
if (!atSol) newline(); | ||
} | ||
|
||
cm.operation(function () { | ||
cm.replaceRange(out, from, to); | ||
for (var cur = from.line + 1, end = from.line + lines; cur <= end; ++cur) | ||
cm.indentLine(cur, "smart"); | ||
cm.setSelection(from, cm.getCursor(false)); | ||
}); | ||
}); | ||
})(); |
Oops, something went wrong.