arkpar
10 years ago
18 changed files with 9520 additions and 69 deletions
@ -0,0 +1,150 @@ |
|||
import QtQuick 2.2 |
|||
import QtQuick.Controls 1.1 |
|||
import QtQuick.Layouts 1.0 |
|||
import QtQuick.Controls.Styles 1.1 |
|||
import CodeEditorExtensionManager 1.0 |
|||
import QtWebEngine 1.0 |
|||
import QtWebEngine.experimental 1.0 |
|||
import QtWebChannel 1.0 |
|||
|
|||
Rectangle { |
|||
|
|||
property alias textEditor: editorBrowser; |
|||
|
|||
anchors.top: parent.top |
|||
id: codeEditorView |
|||
width: parent.width |
|||
height: parent.height * 0.7 |
|||
|
|||
|
|||
QtObject { |
|||
id: textModel |
|||
|
|||
// the identifier under which this object |
|||
// will be known on the JavaScript side |
|||
WebChannel.id: "foo" |
|||
|
|||
// signals, methods and properties are |
|||
// accessible to JavaScript code |
|||
signal someSignal(string message); |
|||
|
|||
function someMethod(message) { |
|||
console.log(message); |
|||
someSignal(message); |
|||
return "foobar"; |
|||
} |
|||
|
|||
property string hello: "world" |
|||
} |
|||
|
|||
Rectangle { |
|||
anchors.fill: parent |
|||
|
|||
|
|||
WebEngineView { |
|||
|
|||
|
|||
id: editorBrowser |
|||
url: "qrc:///qml/html/codeeditor.html" |
|||
//experimental.webChannel.registeredObjects: [myObject] |
|||
experimental.inspectable: true |
|||
|
|||
anchors.fill: parent |
|||
onJavaScriptConsoleMessage: { |
|||
|
|||
console.log(sourceID + ":" + lineNumber + ":" + message); |
|||
} |
|||
|
|||
|
|||
onLoadingChanged: |
|||
{ |
|||
console.log("onLoadingChanged"); |
|||
if (!loading) { |
|||
console.log("onLoadingChangedDone"); |
|||
runJavaScript("getTextChanged()", function(result) { |
|||
console.log(result); |
|||
}); |
|||
pollTimer.running = true; |
|||
} |
|||
} |
|||
|
|||
Timer |
|||
{ |
|||
id: pollTimer |
|||
interval: 30 |
|||
running: false |
|||
repeat: true |
|||
onTriggered: { |
|||
editorBrowser.runJavaScript("getTextChanged()", function(result) { |
|||
if (result === true) { |
|||
var textValue = editorBrowser.runJavaScript("getText()" , function(textValue) { |
|||
codeModel.registerCodeChange(textValue); |
|||
}); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
|||
/* |
|||
Item { |
|||
anchors.fill: parent |
|||
visible: false |
|||
Rectangle { |
|||
id: lineColumn |
|||
property int rowHeight: codeEditor.font.pixelSize + 3 |
|||
color: "#202020" |
|||
width: 50 |
|||
height: parent.height |
|||
Column { |
|||
y: -codeEditor.flickableItem.contentY + 4 |
|||
width: parent.width |
|||
Repeater { |
|||
model: Math.max(codeEditor.lineCount + 2, (lineColumn.height/lineColumn.rowHeight)) |
|||
delegate: Text { |
|||
id: text |
|||
color: codeEditor.textColor |
|||
font: codeEditor.font |
|||
width: lineColumn.width - 4 |
|||
horizontalAlignment: Text.AlignRight |
|||
verticalAlignment: Text.AlignVCenter |
|||
height: lineColumn.rowHeight |
|||
renderType: Text.NativeRendering |
|||
text: index + 1 |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
TextArea { |
|||
id: codeEditor |
|||
textColor: "#EEE8D5" |
|||
style: TextAreaStyle { |
|||
backgroundColor: "#002B36" |
|||
} |
|||
|
|||
anchors.left: lineColumn.right |
|||
anchors.right: parent.right |
|||
anchors.top: parent.top |
|||
anchors.bottom: parent.bottom |
|||
wrapMode: TextEdit.NoWrap |
|||
frameVisible: false |
|||
|
|||
height: parent.height |
|||
font.family: "Monospace" |
|||
font.pointSize: 12 |
|||
width: parent.width |
|||
//anchors.centerIn: parent |
|||
tabChangesFocus: false |
|||
Keys.onPressed: { |
|||
if (event.key === Qt.Key_Tab) { |
|||
codeEditor.insert(codeEditor.cursorPosition, "\t"); |
|||
event.accepted = true; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
*/ |
|||
} |
@ -0,0 +1,71 @@ |
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|||
|
|||
// Because sometimes you need to style the cursor's line.
|
|||
//
|
|||
// Adds an option 'styleActiveLine' which, when enabled, gives the
|
|||
// active line's wrapping <div> the CSS class "CodeMirror-activeline",
|
|||
// and gives its background <div> the class "CodeMirror-activeline-background".
|
|||
|
|||
(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 WRAP_CLASS = "CodeMirror-activeline"; |
|||
var BACK_CLASS = "CodeMirror-activeline-background"; |
|||
|
|||
CodeMirror.defineOption("styleActiveLine", false, function(cm, val, old) { |
|||
var prev = old && old != CodeMirror.Init; |
|||
if (val && !prev) { |
|||
cm.state.activeLines = []; |
|||
updateActiveLines(cm, cm.listSelections()); |
|||
cm.on("beforeSelectionChange", selectionChange); |
|||
} else if (!val && prev) { |
|||
cm.off("beforeSelectionChange", selectionChange); |
|||
clearActiveLines(cm); |
|||
delete cm.state.activeLines; |
|||
} |
|||
}); |
|||
|
|||
function clearActiveLines(cm) { |
|||
for (var i = 0; i < cm.state.activeLines.length; i++) { |
|||
cm.removeLineClass(cm.state.activeLines[i], "wrap", WRAP_CLASS); |
|||
cm.removeLineClass(cm.state.activeLines[i], "background", BACK_CLASS); |
|||
} |
|||
} |
|||
|
|||
function sameArray(a, b) { |
|||
if (a.length != b.length) return false; |
|||
for (var i = 0; i < a.length; i++) |
|||
if (a[i] != b[i]) return false; |
|||
return true; |
|||
} |
|||
|
|||
function updateActiveLines(cm, ranges) { |
|||
var active = []; |
|||
for (var i = 0; i < ranges.length; i++) { |
|||
var range = ranges[i]; |
|||
if (!range.empty()) continue; |
|||
var line = cm.getLineHandleVisualStart(range.head.line); |
|||
if (active[active.length - 1] != line) active.push(line); |
|||
} |
|||
if (sameArray(cm.state.activeLines, active)) return; |
|||
cm.operation(function() { |
|||
clearActiveLines(cm); |
|||
for (var i = 0; i < active.length; i++) { |
|||
cm.addLineClass(active[i], "wrap", WRAP_CLASS); |
|||
cm.addLineClass(active[i], "background", BACK_CLASS); |
|||
} |
|||
cm.state.activeLines = active; |
|||
}); |
|||
} |
|||
|
|||
function selectionChange(cm, sel) { |
|||
updateActiveLines(cm, sel.ranges); |
|||
} |
|||
}); |
@ -0,0 +1,15 @@ |
|||
<!doctype html> |
|||
<meta charset="utf-8"/> |
|||
<link rel="stylesheet" href="codemirror.css"> |
|||
<link rel="stylesheet" href="codetheme.css"> |
|||
<link rel="stylesheet" href="fullscreen.css"> |
|||
<script src="codemirror.js"></script> |
|||
|
|||
<script src="javascript.js"></script> |
|||
<script src="fullscreen.js"></script> |
|||
<script src="active-line.js"></script> |
|||
<script src="matchbrackets.js"></script> |
|||
|
|||
<script src="qrc:///qtwebchannel/qwebchannel.js"></script> |
|||
<body/> |
|||
<script src="codeeditor.js"></script> |
@ -0,0 +1,32 @@ |
|||
|
|||
var editor = CodeMirror(document.body, { |
|||
lineNumbers: true, |
|||
styleActiveLine: true, |
|||
matchBrackets: true, |
|||
autofocus: true, |
|||
|
|||
}); |
|||
editor.setOption("theme", "blackboard"); |
|||
editor.setOption("fullScreen", true); |
|||
|
|||
editor.changeRegistered = false; |
|||
|
|||
editor.on("change", function(eMirror, object) { |
|||
editor.changeRegistered = true; |
|||
|
|||
}); |
|||
|
|||
getTextChanged = function() { |
|||
return editor.changeRegistered; |
|||
}; |
|||
|
|||
|
|||
getText = function() { |
|||
editor.changeRegistered = false; |
|||
return editor.getValue(); |
|||
}; |
|||
|
|||
|
|||
setText = function(text) { |
|||
editor.setValue(text); |
|||
}; |
@ -0,0 +1,311 @@ |
|||
/* BASICS */ |
|||
|
|||
.CodeMirror { |
|||
/* Set height, width, borders, and global font properties here */ |
|||
font-family: monospace; |
|||
border: 1px solid black; |
|||
height: 100%; |
|||
font-size:16px |
|||
} |
|||
|
|||
/* PADDING */ |
|||
|
|||
.CodeMirror-lines { |
|||
padding: 4px 0; /* Vertical padding around content */ |
|||
} |
|||
.CodeMirror pre { |
|||
padding: 0 4px; /* Horizontal padding of content */ |
|||
} |
|||
|
|||
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { |
|||
background-color: white; /* The little square between H and V scrollbars */ |
|||
} |
|||
|
|||
/* GUTTER */ |
|||
|
|||
.CodeMirror-gutters { |
|||
border-right: 1px solid #ddd; |
|||
background-color: #f7f7f7; |
|||
white-space: nowrap; |
|||
} |
|||
.CodeMirror-linenumbers {} |
|||
.CodeMirror-linenumber { |
|||
padding: 0 3px 0 5px; |
|||
min-width: 20px; |
|||
text-align: right; |
|||
color: #999; |
|||
-moz-box-sizing: content-box; |
|||
box-sizing: content-box; |
|||
} |
|||
|
|||
.CodeMirror-guttermarker { color: black; } |
|||
.CodeMirror-guttermarker-subtle { color: #999; } |
|||
|
|||
/* CURSOR */ |
|||
|
|||
.CodeMirror div.CodeMirror-cursor { |
|||
border-left: 1px solid black; |
|||
} |
|||
/* Shown when moving in bi-directional text */ |
|||
.CodeMirror div.CodeMirror-secondarycursor { |
|||
border-left: 1px solid silver; |
|||
} |
|||
.CodeMirror.cm-fat-cursor div.CodeMirror-cursor { |
|||
width: auto; |
|||
border: 0; |
|||
background: #7e7; |
|||
} |
|||
.CodeMirror.cm-fat-cursor div.CodeMirror-cursors { |
|||
z-index: 1; |
|||
} |
|||
|
|||
.cm-animate-fat-cursor { |
|||
width: auto; |
|||
border: 0; |
|||
-webkit-animation: blink 1.06s steps(1) infinite; |
|||
-moz-animation: blink 1.06s steps(1) infinite; |
|||
animation: blink 1.06s steps(1) infinite; |
|||
} |
|||
@-moz-keyframes blink { |
|||
0% { background: #7e7; } |
|||
50% { background: none; } |
|||
100% { background: #7e7; } |
|||
} |
|||
@-webkit-keyframes blink { |
|||
0% { background: #7e7; } |
|||
50% { background: none; } |
|||
100% { background: #7e7; } |
|||
} |
|||
@keyframes blink { |
|||
0% { background: #7e7; } |
|||
50% { background: none; } |
|||
100% { background: #7e7; } |
|||
} |
|||
|
|||
/* Can style cursor different in overwrite (non-insert) mode */ |
|||
div.CodeMirror-overwrite div.CodeMirror-cursor {} |
|||
|
|||
.cm-tab { display: inline-block; text-decoration: inherit; } |
|||
|
|||
.CodeMirror-ruler { |
|||
border-left: 1px solid #ccc; |
|||
position: absolute; |
|||
} |
|||
|
|||
/* DEFAULT THEME */ |
|||
|
|||
.cm-s-default .cm-keyword {color: #708;} |
|||
.cm-s-default .cm-atom {color: #219;} |
|||
.cm-s-default .cm-number {color: #164;} |
|||
.cm-s-default .cm-def {color: #00f;} |
|||
.cm-s-default .cm-variable, |
|||
.cm-s-default .cm-punctuation, |
|||
.cm-s-default .cm-property, |
|||
.cm-s-default .cm-operator {} |
|||
.cm-s-default .cm-variable-2 {color: #05a;} |
|||
.cm-s-default .cm-variable-3 {color: #085;} |
|||
.cm-s-default .cm-comment {color: #a50;} |
|||
.cm-s-default .cm-string {color: #a11;} |
|||
.cm-s-default .cm-string-2 {color: #f50;} |
|||
.cm-s-default .cm-meta {color: #555;} |
|||
.cm-s-default .cm-qualifier {color: #555;} |
|||
.cm-s-default .cm-builtin {color: #30a;} |
|||
.cm-s-default .cm-bracket {color: #997;} |
|||
.cm-s-default .cm-tag {color: #170;} |
|||
.cm-s-default .cm-attribute {color: #00c;} |
|||
.cm-s-default .cm-header {color: blue;} |
|||
.cm-s-default .cm-quote {color: #090;} |
|||
.cm-s-default .cm-hr {color: #999;} |
|||
.cm-s-default .cm-link {color: #00c;} |
|||
|
|||
.cm-negative {color: #d44;} |
|||
.cm-positive {color: #292;} |
|||
.cm-header, .cm-strong {font-weight: bold;} |
|||
.cm-em {font-style: italic;} |
|||
.cm-link {text-decoration: underline;} |
|||
.cm-strikethrough {text-decoration: line-through;} |
|||
|
|||
.cm-s-default .cm-error {color: #f00;} |
|||
.cm-invalidchar {color: #f00;} |
|||
|
|||
/* Default styles for common addons */ |
|||
|
|||
div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;} |
|||
div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;} |
|||
.CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); } |
|||
.CodeMirror-activeline-background {background: #e8f2ff;} |
|||
|
|||
/* STOP */ |
|||
|
|||
/* The rest of this file contains styles related to the mechanics of |
|||
the editor. You probably shouldn't touch them. */ |
|||
|
|||
.CodeMirror { |
|||
line-height: 1; |
|||
position: relative; |
|||
overflow: hidden; |
|||
background: white; |
|||
color: black; |
|||
} |
|||
|
|||
.CodeMirror-scroll { |
|||
overflow: scroll !important; /* Things will break if this is overridden */ |
|||
/* 30px is the magic margin used to hide the element's real scrollbars */ |
|||
/* See overflow: hidden in .CodeMirror */ |
|||
margin-bottom: -30px; margin-right: -30px; |
|||
padding-bottom: 30px; |
|||
height: 100%; |
|||
outline: none; /* Prevent dragging from highlighting the element */ |
|||
position: relative; |
|||
-moz-box-sizing: content-box; |
|||
box-sizing: content-box; |
|||
} |
|||
.CodeMirror-sizer { |
|||
position: relative; |
|||
border-right: 30px solid transparent; |
|||
-moz-box-sizing: content-box; |
|||
box-sizing: content-box; |
|||
} |
|||
|
|||
/* The fake, visible scrollbars. Used to force redraw during scrolling |
|||
before actuall scrolling happens, thus preventing shaking and |
|||
flickering artifacts. */ |
|||
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { |
|||
position: absolute; |
|||
z-index: 6; |
|||
display: none; |
|||
} |
|||
.CodeMirror-vscrollbar { |
|||
right: 0; top: 0; |
|||
overflow-x: hidden; |
|||
overflow-y: scroll; |
|||
} |
|||
.CodeMirror-hscrollbar { |
|||
bottom: 0; left: 0; |
|||
overflow-y: hidden; |
|||
overflow-x: scroll; |
|||
} |
|||
.CodeMirror-scrollbar-filler { |
|||
right: 0; bottom: 0; |
|||
} |
|||
.CodeMirror-gutter-filler { |
|||
left: 0; bottom: 0; |
|||
} |
|||
|
|||
.CodeMirror-gutters { |
|||
position: absolute; left: 0; top: 0; |
|||
z-index: 3; |
|||
} |
|||
.CodeMirror-gutter { |
|||
white-space: normal; |
|||
height: 100%; |
|||
-moz-box-sizing: content-box; |
|||
box-sizing: content-box; |
|||
display: inline-block; |
|||
margin-bottom: -30px; |
|||
/* Hack to make IE7 behave */ |
|||
*zoom:1; |
|||
*display:inline; |
|||
} |
|||
.CodeMirror-gutter-wrapper { |
|||
position: absolute; |
|||
z-index: 4; |
|||
height: 100%; |
|||
} |
|||
.CodeMirror-gutter-elt { |
|||
position: absolute; |
|||
cursor: default; |
|||
z-index: 4; |
|||
} |
|||
|
|||
.CodeMirror-lines { |
|||
cursor: text; |
|||
min-height: 1px; /* prevents collapsing before first draw */ |
|||
} |
|||
.CodeMirror pre { |
|||
/* Reset some styles that the rest of the page might have set */ |
|||
-moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0; |
|||
border-width: 0; |
|||
background: transparent; |
|||
font-family: inherit; |
|||
font-size: inherit; |
|||
margin: 0; |
|||
white-space: pre; |
|||
word-wrap: normal; |
|||
line-height: inherit; |
|||
color: inherit; |
|||
z-index: 2; |
|||
position: relative; |
|||
overflow: visible; |
|||
} |
|||
.CodeMirror-wrap pre { |
|||
word-wrap: break-word; |
|||
white-space: pre-wrap; |
|||
word-break: normal; |
|||
} |
|||
|
|||
.CodeMirror-linebackground { |
|||
position: absolute; |
|||
left: 0; right: 0; top: 0; bottom: 0; |
|||
z-index: 0; |
|||
} |
|||
|
|||
.CodeMirror-linewidget { |
|||
position: relative; |
|||
z-index: 2; |
|||
overflow: auto; |
|||
} |
|||
|
|||
.CodeMirror-widget {} |
|||
|
|||
.CodeMirror-measure { |
|||
position: absolute; |
|||
width: 100%; |
|||
height: 0; |
|||
overflow: hidden; |
|||
visibility: hidden; |
|||
} |
|||
.CodeMirror-measure pre { position: static; } |
|||
|
|||
.CodeMirror div.CodeMirror-cursor { |
|||
position: absolute; |
|||
border-right: none; |
|||
width: 0; |
|||
} |
|||
|
|||
div.CodeMirror-cursors { |
|||
visibility: hidden; |
|||
position: relative; |
|||
z-index: 3; |
|||
} |
|||
.CodeMirror-focused div.CodeMirror-cursors { |
|||
visibility: visible; |
|||
} |
|||
|
|||
.CodeMirror-selected { background: #d9d9d9; } |
|||
.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; } |
|||
.CodeMirror-crosshair { cursor: crosshair; } |
|||
|
|||
.cm-searching { |
|||
background: #ffa; |
|||
background: rgba(255, 255, 0, .4); |
|||
} |
|||
|
|||
/* IE7 hack to prevent it from returning funny offsetTops on the spans */ |
|||
.CodeMirror span { *vertical-align: text-bottom; } |
|||
|
|||
/* Used to force a border model for a node */ |
|||
.cm-force-border { padding-right: .1px; } |
|||
|
|||
@media print { |
|||
/* Hide the cursor when printing */ |
|||
.CodeMirror div.CodeMirror-cursors { |
|||
visibility: hidden; |
|||
} |
|||
} |
|||
|
|||
/* See issue #2901 */ |
|||
.cm-tab-wrap-hack:after { content: ''; } |
|||
|
|||
/* Help users use markselection to safely style text background */ |
|||
span.CodeMirror-selectedtext { background: none; } |
File diff suppressed because it is too large
@ -0,0 +1,30 @@ |
|||
/* Port of TextMate's Blackboard theme */ |
|||
|
|||
.cm-s-blackboard.CodeMirror { background: #0C1021; color: #F8F8F8; } |
|||
.cm-s-blackboard .CodeMirror-selected { background: #253B76 !important; } |
|||
.cm-s-blackboard .CodeMirror-gutters { background: #0C1021; border-right: 0; } |
|||
.cm-s-blackboard .CodeMirror-guttermarker { color: #FBDE2D; } |
|||
.cm-s-blackboard .CodeMirror-guttermarker-subtle { color: #888; } |
|||
.cm-s-blackboard .CodeMirror-linenumber { color: #888; } |
|||
.cm-s-blackboard .CodeMirror-cursor { border-left: 1px solid #A7A7A7 !important; } |
|||
|
|||
.cm-s-blackboard .cm-keyword { color: #FBDE2D; } |
|||
.cm-s-blackboard .cm-atom { color: #D8FA3C; } |
|||
.cm-s-blackboard .cm-number { color: #D8FA3C; } |
|||
.cm-s-blackboard .cm-def { color: #8DA6CE; } |
|||
.cm-s-blackboard .cm-variable { color: #FF6400; } |
|||
.cm-s-blackboard .cm-operator { color: #FBDE2D;} |
|||
.cm-s-blackboard .cm-comment { color: #AEAEAE; } |
|||
.cm-s-blackboard .cm-string { color: #61CE3C; } |
|||
.cm-s-blackboard .cm-string-2 { color: #61CE3C; } |
|||
.cm-s-blackboard .cm-meta { color: #D8FA3C; } |
|||
.cm-s-blackboard .cm-builtin { color: #8DA6CE; } |
|||
.cm-s-blackboard .cm-tag { color: #8DA6CE; } |
|||
.cm-s-blackboard .cm-attribute { color: #8DA6CE; } |
|||
.cm-s-blackboard .cm-header { color: #FF6400; } |
|||
.cm-s-blackboard .cm-hr { color: #AEAEAE; } |
|||
.cm-s-blackboard .cm-link { color: #8DA6CE; } |
|||
.cm-s-blackboard .cm-error { background: #9D1E15; color: #F8F8F8; } |
|||
|
|||
.cm-s-blackboard .CodeMirror-activeline-background {background: #3C3636 !important;} |
|||
.cm-s-blackboard .CodeMirror-matchingbracket {outline:1px solid grey;color:white !important} |
@ -0,0 +1,6 @@ |
|||
.CodeMirror-fullscreen { |
|||
position: fixed; |
|||
top: 0; left: 0; right: 0; bottom: 0; |
|||
height: auto; |
|||
z-index: 9; |
|||
} |
@ -0,0 +1,41 @@ |
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|||
// Distributed under an MIT license: http://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"; |
|||
|
|||
CodeMirror.defineOption("fullScreen", false, function(cm, val, old) { |
|||
if (old == CodeMirror.Init) old = false; |
|||
if (!old == !val) return; |
|||
if (val) setFullscreen(cm); |
|||
else setNormal(cm); |
|||
}); |
|||
|
|||
function setFullscreen(cm) { |
|||
var wrap = cm.getWrapperElement(); |
|||
cm.state.fullScreenRestore = {scrollTop: window.pageYOffset, scrollLeft: window.pageXOffset, |
|||
width: wrap.style.width, height: wrap.style.height}; |
|||
wrap.style.width = ""; |
|||
wrap.style.height = "auto"; |
|||
wrap.className += " CodeMirror-fullscreen"; |
|||
document.documentElement.style.overflow = "hidden"; |
|||
cm.refresh(); |
|||
} |
|||
|
|||
function setNormal(cm) { |
|||
var wrap = cm.getWrapperElement(); |
|||
wrap.className = wrap.className.replace(/\s*CodeMirror-fullscreen\b/, ""); |
|||
document.documentElement.style.overflow = ""; |
|||
var info = cm.state.fullScreenRestore; |
|||
wrap.style.width = info.width; wrap.style.height = info.height; |
|||
window.scrollTo(info.scrollLeft, info.scrollTop); |
|||
cm.refresh(); |
|||
} |
|||
}); |
@ -0,0 +1,686 @@ |
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|||
|
|||
// TODO actually recognize syntax of TypeScript constructs
|
|||
|
|||
(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"; |
|||
|
|||
CodeMirror.defineMode("javascript", function(config, parserConfig) { |
|||
var indentUnit = config.indentUnit; |
|||
var statementIndent = parserConfig.statementIndent; |
|||
var jsonldMode = parserConfig.jsonld; |
|||
var jsonMode = parserConfig.json || jsonldMode; |
|||
var isTS = parserConfig.typescript; |
|||
var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/; |
|||
|
|||
// Tokenizer
|
|||
|
|||
var keywords = function(){ |
|||
function kw(type) {return {type: type, style: "keyword"};} |
|||
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c"); |
|||
var operator = kw("operator"), atom = {type: "atom", style: "atom"}; |
|||
|
|||
var jsKeywords = { |
|||
"if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B, |
|||
"return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C, "debugger": C, |
|||
"var": kw("var"), "const": kw("var"), "let": kw("var"), |
|||
"function": kw("function"), "catch": kw("catch"), |
|||
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"), |
|||
"in": operator, "typeof": operator, "instanceof": operator, |
|||
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom, |
|||
"this": kw("this"), "module": kw("module"), "class": kw("class"), "super": kw("atom"), |
|||
"yield": C, "export": kw("export"), "import": kw("import"), "extends": C |
|||
}; |
|||
|
|||
// Extend the 'normal' keywords with the TypeScript language extensions
|
|||
if (isTS) { |
|||
var type = {type: "variable", style: "variable-3"}; |
|||
var tsKeywords = { |
|||
// object-like things
|
|||
"interface": kw("interface"), |
|||
"extends": kw("extends"), |
|||
"constructor": kw("constructor"), |
|||
|
|||
// scope modifiers
|
|||
"public": kw("public"), |
|||
"private": kw("private"), |
|||
"protected": kw("protected"), |
|||
"static": kw("static"), |
|||
|
|||
// types
|
|||
"string": type, "number": type, "bool": type, "any": type |
|||
}; |
|||
|
|||
for (var attr in tsKeywords) { |
|||
jsKeywords[attr] = tsKeywords[attr]; |
|||
} |
|||
} |
|||
|
|||
return jsKeywords; |
|||
}(); |
|||
|
|||
var isOperatorChar = /[+\-*&%=<>!?|~^]/; |
|||
var isJsonldKeyword = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/; |
|||
|
|||
function readRegexp(stream) { |
|||
var escaped = false, next, inSet = false; |
|||
while ((next = stream.next()) != null) { |
|||
if (!escaped) { |
|||
if (next == "/" && !inSet) return; |
|||
if (next == "[") inSet = true; |
|||
else if (inSet && next == "]") inSet = false; |
|||
} |
|||
escaped = !escaped && next == "\\"; |
|||
} |
|||
} |
|||
|
|||
// Used as scratch variables to communicate multiple values without
|
|||
// consing up tons of objects.
|
|||
var type, content; |
|||
function ret(tp, style, cont) { |
|||
type = tp; content = cont; |
|||
return style; |
|||
} |
|||
function tokenBase(stream, state) { |
|||
var ch = stream.next(); |
|||
if (ch == '"' || ch == "'") { |
|||
state.tokenize = tokenString(ch); |
|||
return state.tokenize(stream, state); |
|||
} else if (ch == "." && stream.match(/^\d+(?:[eE][+\-]?\d+)?/)) { |
|||
return ret("number", "number"); |
|||
} else if (ch == "." && stream.match("..")) { |
|||
return ret("spread", "meta"); |
|||
} else if (/[\[\]{}\(\),;\:\.]/.test(ch)) { |
|||
return ret(ch); |
|||
} else if (ch == "=" && stream.eat(">")) { |
|||
return ret("=>", "operator"); |
|||
} else if (ch == "0" && stream.eat(/x/i)) { |
|||
stream.eatWhile(/[\da-f]/i); |
|||
return ret("number", "number"); |
|||
} else if (/\d/.test(ch)) { |
|||
stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/); |
|||
return ret("number", "number"); |
|||
} else if (ch == "/") { |
|||
if (stream.eat("*")) { |
|||
state.tokenize = tokenComment; |
|||
return tokenComment(stream, state); |
|||
} else if (stream.eat("/")) { |
|||
stream.skipToEnd(); |
|||
return ret("comment", "comment"); |
|||
} else if (state.lastType == "operator" || state.lastType == "keyword c" || |
|||
state.lastType == "sof" || /^[\[{}\(,;:]$/.test(state.lastType)) { |
|||
readRegexp(stream); |
|||
stream.eatWhile(/[gimy]/); // 'y' is "sticky" option in Mozilla
|
|||
return ret("regexp", "string-2"); |
|||
} else { |
|||
stream.eatWhile(isOperatorChar); |
|||
return ret("operator", "operator", stream.current()); |
|||
} |
|||
} else if (ch == "`") { |
|||
state.tokenize = tokenQuasi; |
|||
return tokenQuasi(stream, state); |
|||
} else if (ch == "#") { |
|||
stream.skipToEnd(); |
|||
return ret("error", "error"); |
|||
} else if (isOperatorChar.test(ch)) { |
|||
stream.eatWhile(isOperatorChar); |
|||
return ret("operator", "operator", stream.current()); |
|||
} else if (wordRE.test(ch)) { |
|||
stream.eatWhile(wordRE); |
|||
var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word]; |
|||
return (known && state.lastType != ".") ? ret(known.type, known.style, word) : |
|||
ret("variable", "variable", word); |
|||
} |
|||
} |
|||
|
|||
function tokenString(quote) { |
|||
return function(stream, state) { |
|||
var escaped = false, next; |
|||
if (jsonldMode && stream.peek() == "@" && stream.match(isJsonldKeyword)){ |
|||
state.tokenize = tokenBase; |
|||
return ret("jsonld-keyword", "meta"); |
|||
} |
|||
while ((next = stream.next()) != null) { |
|||
if (next == quote && !escaped) break; |
|||
escaped = !escaped && next == "\\"; |
|||
} |
|||
if (!escaped) state.tokenize = tokenBase; |
|||
return ret("string", "string"); |
|||
}; |
|||
} |
|||
|
|||
function tokenComment(stream, state) { |
|||
var maybeEnd = false, ch; |
|||
while (ch = stream.next()) { |
|||
if (ch == "/" && maybeEnd) { |
|||
state.tokenize = tokenBase; |
|||
break; |
|||
} |
|||
maybeEnd = (ch == "*"); |
|||
} |
|||
return ret("comment", "comment"); |
|||
} |
|||
|
|||
function tokenQuasi(stream, state) { |
|||
var escaped = false, next; |
|||
while ((next = stream.next()) != null) { |
|||
if (!escaped && (next == "`" || next == "$" && stream.eat("{"))) { |
|||
state.tokenize = tokenBase; |
|||
break; |
|||
} |
|||
escaped = !escaped && next == "\\"; |
|||
} |
|||
return ret("quasi", "string-2", stream.current()); |
|||
} |
|||
|
|||
var brackets = "([{}])"; |
|||
// This is a crude lookahead trick to try and notice that we're
|
|||
// parsing the argument patterns for a fat-arrow function before we
|
|||
// actually hit the arrow token. It only works if the arrow is on
|
|||
// the same line as the arguments and there's no strange noise
|
|||
// (comments) in between. Fallback is to only notice when we hit the
|
|||
// arrow, and not declare the arguments as locals for the arrow
|
|||
// body.
|
|||
function findFatArrow(stream, state) { |
|||
if (state.fatArrowAt) state.fatArrowAt = null; |
|||
var arrow = stream.string.indexOf("=>", stream.start); |
|||
if (arrow < 0) return; |
|||
|
|||
var depth = 0, sawSomething = false; |
|||
for (var pos = arrow - 1; pos >= 0; --pos) { |
|||
var ch = stream.string.charAt(pos); |
|||
var bracket = brackets.indexOf(ch); |
|||
if (bracket >= 0 && bracket < 3) { |
|||
if (!depth) { ++pos; break; } |
|||
if (--depth == 0) break; |
|||
} else if (bracket >= 3 && bracket < 6) { |
|||
++depth; |
|||
} else if (wordRE.test(ch)) { |
|||
sawSomething = true; |
|||
} else if (/["'\/]/.test(ch)) { |
|||
return; |
|||
} else if (sawSomething && !depth) { |
|||
++pos; |
|||
break; |
|||
} |
|||
} |
|||
if (sawSomething && !depth) state.fatArrowAt = pos; |
|||
} |
|||
|
|||
// Parser
|
|||
|
|||
var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true, "this": true, "jsonld-keyword": true}; |
|||
|
|||
function JSLexical(indented, column, type, align, prev, info) { |
|||
this.indented = indented; |
|||
this.column = column; |
|||
this.type = type; |
|||
this.prev = prev; |
|||
this.info = info; |
|||
if (align != null) this.align = align; |
|||
} |
|||
|
|||
function inScope(state, varname) { |
|||
for (var v = state.localVars; v; v = v.next) |
|||
if (v.name == varname) return true; |
|||
for (var cx = state.context; cx; cx = cx.prev) { |
|||
for (var v = cx.vars; v; v = v.next) |
|||
if (v.name == varname) return true; |
|||
} |
|||
} |
|||
|
|||
function parseJS(state, style, type, content, stream) { |
|||
var cc = state.cc; |
|||
// Communicate our context to the combinators.
|
|||
// (Less wasteful than consing up a hundred closures on every call.)
|
|||
cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; cx.style = style; |
|||
|
|||
if (!state.lexical.hasOwnProperty("align")) |
|||
state.lexical.align = true; |
|||
|
|||
while(true) { |
|||
var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement; |
|||
if (combinator(type, content)) { |
|||
while(cc.length && cc[cc.length - 1].lex) |
|||
cc.pop()(); |
|||
if (cx.marked) return cx.marked; |
|||
if (type == "variable" && inScope(state, content)) return "variable-2"; |
|||
return style; |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Combinator utils
|
|||
|
|||
var cx = {state: null, column: null, marked: null, cc: null}; |
|||
function pass() { |
|||
for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]); |
|||
} |
|||
function cont() { |
|||
pass.apply(null, arguments); |
|||
return true; |
|||
} |
|||
function register(varname) { |
|||
function inList(list) { |
|||
for (var v = list; v; v = v.next) |
|||
if (v.name == varname) return true; |
|||
return false; |
|||
} |
|||
var state = cx.state; |
|||
if (state.context) { |
|||
cx.marked = "def"; |
|||
if (inList(state.localVars)) return; |
|||
state.localVars = {name: varname, next: state.localVars}; |
|||
} else { |
|||
if (inList(state.globalVars)) return; |
|||
if (parserConfig.globalVars) |
|||
state.globalVars = {name: varname, next: state.globalVars}; |
|||
} |
|||
} |
|||
|
|||
// Combinators
|
|||
|
|||
var defaultVars = {name: "this", next: {name: "arguments"}}; |
|||
function pushcontext() { |
|||
cx.state.context = {prev: cx.state.context, vars: cx.state.localVars}; |
|||
cx.state.localVars = defaultVars; |
|||
} |
|||
function popcontext() { |
|||
cx.state.localVars = cx.state.context.vars; |
|||
cx.state.context = cx.state.context.prev; |
|||
} |
|||
function pushlex(type, info) { |
|||
var result = function() { |
|||
var state = cx.state, indent = state.indented; |
|||
if (state.lexical.type == "stat") indent = state.lexical.indented; |
|||
else for (var outer = state.lexical; outer && outer.type == ")" && outer.align; outer = outer.prev) |
|||
indent = outer.indented; |
|||
state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info); |
|||
}; |
|||
result.lex = true; |
|||
return result; |
|||
} |
|||
function poplex() { |
|||
var state = cx.state; |
|||
if (state.lexical.prev) { |
|||
if (state.lexical.type == ")") |
|||
state.indented = state.lexical.indented; |
|||
state.lexical = state.lexical.prev; |
|||
} |
|||
} |
|||
poplex.lex = true; |
|||
|
|||
function expect(wanted) { |
|||
function exp(type) { |
|||
if (type == wanted) return cont(); |
|||
else if (wanted == ";") return pass(); |
|||
else return cont(exp); |
|||
}; |
|||
return exp; |
|||
} |
|||
|
|||
function statement(type, value) { |
|||
if (type == "var") return cont(pushlex("vardef", value.length), vardef, expect(";"), poplex); |
|||
if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex); |
|||
if (type == "keyword b") return cont(pushlex("form"), statement, poplex); |
|||
if (type == "{") return cont(pushlex("}"), block, poplex); |
|||
if (type == ";") return cont(); |
|||
if (type == "if") { |
|||
if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex) |
|||
cx.state.cc.pop()(); |
|||
return cont(pushlex("form"), expression, statement, poplex, maybeelse); |
|||
} |
|||
if (type == "function") return cont(functiondef); |
|||
if (type == "for") return cont(pushlex("form"), forspec, statement, poplex); |
|||
if (type == "variable") return cont(pushlex("stat"), maybelabel); |
|||
if (type == "switch") return cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"), |
|||
block, poplex, poplex); |
|||
if (type == "case") return cont(expression, expect(":")); |
|||
if (type == "default") return cont(expect(":")); |
|||
if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"), |
|||
statement, poplex, popcontext); |
|||
if (type == "module") return cont(pushlex("form"), pushcontext, afterModule, popcontext, poplex); |
|||
if (type == "class") return cont(pushlex("form"), className, poplex); |
|||
if (type == "export") return cont(pushlex("form"), afterExport, poplex); |
|||
if (type == "import") return cont(pushlex("form"), afterImport, poplex); |
|||
return pass(pushlex("stat"), expression, expect(";"), poplex); |
|||
} |
|||
function expression(type) { |
|||
return expressionInner(type, false); |
|||
} |
|||
function expressionNoComma(type) { |
|||
return expressionInner(type, true); |
|||
} |
|||
function expressionInner(type, noComma) { |
|||
if (cx.state.fatArrowAt == cx.stream.start) { |
|||
var body = noComma ? arrowBodyNoComma : arrowBody; |
|||
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(pattern, ")"), poplex, expect("=>"), body, popcontext); |
|||
else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext); |
|||
} |
|||
|
|||
var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma; |
|||
if (atomicTypes.hasOwnProperty(type)) return cont(maybeop); |
|||
if (type == "function") return cont(functiondef, maybeop); |
|||
if (type == "keyword c") return cont(noComma ? maybeexpressionNoComma : maybeexpression); |
|||
if (type == "(") return cont(pushlex(")"), maybeexpression, comprehension, expect(")"), poplex, maybeop); |
|||
if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression); |
|||
if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop); |
|||
if (type == "{") return contCommasep(objprop, "}", null, maybeop); |
|||
if (type == "quasi") { return pass(quasi, maybeop); } |
|||
return cont(); |
|||
} |
|||
function maybeexpression(type) { |
|||
if (type.match(/[;\}\)\],]/)) return pass(); |
|||
return pass(expression); |
|||
} |
|||
function maybeexpressionNoComma(type) { |
|||
if (type.match(/[;\}\)\],]/)) return pass(); |
|||
return pass(expressionNoComma); |
|||
} |
|||
|
|||
function maybeoperatorComma(type, value) { |
|||
if (type == ",") return cont(expression); |
|||
return maybeoperatorNoComma(type, value, false); |
|||
} |
|||
function maybeoperatorNoComma(type, value, noComma) { |
|||
var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma; |
|||
var expr = noComma == false ? expression : expressionNoComma; |
|||
if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext); |
|||
if (type == "operator") { |
|||
if (/\+\+|--/.test(value)) return cont(me); |
|||
if (value == "?") return cont(expression, expect(":"), expr); |
|||
return cont(expr); |
|||
} |
|||
if (type == "quasi") { return pass(quasi, me); } |
|||
if (type == ";") return; |
|||
if (type == "(") return contCommasep(expressionNoComma, ")", "call", me); |
|||
if (type == ".") return cont(property, me); |
|||
if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me); |
|||
} |
|||
function quasi(type, value) { |
|||
if (type != "quasi") return pass(); |
|||
if (value.slice(value.length - 2) != "${") return cont(quasi); |
|||
return cont(expression, continueQuasi); |
|||
} |
|||
function continueQuasi(type) { |
|||
if (type == "}") { |
|||
cx.marked = "string-2"; |
|||
cx.state.tokenize = tokenQuasi; |
|||
return cont(quasi); |
|||
} |
|||
} |
|||
function arrowBody(type) { |
|||
findFatArrow(cx.stream, cx.state); |
|||
return pass(type == "{" ? statement : expression); |
|||
} |
|||
function arrowBodyNoComma(type) { |
|||
findFatArrow(cx.stream, cx.state); |
|||
return pass(type == "{" ? statement : expressionNoComma); |
|||
} |
|||
function maybelabel(type) { |
|||
if (type == ":") return cont(poplex, statement); |
|||
return pass(maybeoperatorComma, expect(";"), poplex); |
|||
} |
|||
function property(type) { |
|||
if (type == "variable") {cx.marked = "property"; return cont();} |
|||
} |
|||
function objprop(type, value) { |
|||
if (type == "variable" || cx.style == "keyword") { |
|||
cx.marked = "property"; |
|||
if (value == "get" || value == "set") return cont(getterSetter); |
|||
return cont(afterprop); |
|||
} else if (type == "number" || type == "string") { |
|||
cx.marked = jsonldMode ? "property" : (cx.style + " property"); |
|||
return cont(afterprop); |
|||
} else if (type == "jsonld-keyword") { |
|||
return cont(afterprop); |
|||
} else if (type == "[") { |
|||
return cont(expression, expect("]"), afterprop); |
|||
} |
|||
} |
|||
function getterSetter(type) { |
|||
if (type != "variable") return pass(afterprop); |
|||
cx.marked = "property"; |
|||
return cont(functiondef); |
|||
} |
|||
function afterprop(type) { |
|||
if (type == ":") return cont(expressionNoComma); |
|||
if (type == "(") return pass(functiondef); |
|||
} |
|||
function commasep(what, end) { |
|||
function proceed(type) { |
|||
if (type == ",") { |
|||
var lex = cx.state.lexical; |
|||
if (lex.info == "call") lex.pos = (lex.pos || 0) + 1; |
|||
return cont(what, proceed); |
|||
} |
|||
if (type == end) return cont(); |
|||
return cont(expect(end)); |
|||
} |
|||
return function(type) { |
|||
if (type == end) return cont(); |
|||
return pass(what, proceed); |
|||
}; |
|||
} |
|||
function contCommasep(what, end, info) { |
|||
for (var i = 3; i < arguments.length; i++) |
|||
cx.cc.push(arguments[i]); |
|||
return cont(pushlex(end, info), commasep(what, end), poplex); |
|||
} |
|||
function block(type) { |
|||
if (type == "}") return cont(); |
|||
return pass(statement, block); |
|||
} |
|||
function maybetype(type) { |
|||
if (isTS && type == ":") return cont(typedef); |
|||
} |
|||
function typedef(type) { |
|||
if (type == "variable"){cx.marked = "variable-3"; return cont();} |
|||
} |
|||
function vardef() { |
|||
return pass(pattern, maybetype, maybeAssign, vardefCont); |
|||
} |
|||
function pattern(type, value) { |
|||
if (type == "variable") { register(value); return cont(); } |
|||
if (type == "[") return contCommasep(pattern, "]"); |
|||
if (type == "{") return contCommasep(proppattern, "}"); |
|||
} |
|||
function proppattern(type, value) { |
|||
if (type == "variable" && !cx.stream.match(/^\s*:/, false)) { |
|||
register(value); |
|||
return cont(maybeAssign); |
|||
} |
|||
if (type == "variable") cx.marked = "property"; |
|||
return cont(expect(":"), pattern, maybeAssign); |
|||
} |
|||
function maybeAssign(_type, value) { |
|||
if (value == "=") return cont(expressionNoComma); |
|||
} |
|||
function vardefCont(type) { |
|||
if (type == ",") return cont(vardef); |
|||
} |
|||
function maybeelse(type, value) { |
|||
if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex); |
|||
} |
|||
function forspec(type) { |
|||
if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex); |
|||
} |
|||
function forspec1(type) { |
|||
if (type == "var") return cont(vardef, expect(";"), forspec2); |
|||
if (type == ";") return cont(forspec2); |
|||
if (type == "variable") return cont(formaybeinof); |
|||
return pass(expression, expect(";"), forspec2); |
|||
} |
|||
function formaybeinof(_type, value) { |
|||
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); } |
|||
return cont(maybeoperatorComma, forspec2); |
|||
} |
|||
function forspec2(type, value) { |
|||
if (type == ";") return cont(forspec3); |
|||
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); } |
|||
return pass(expression, expect(";"), forspec3); |
|||
} |
|||
function forspec3(type) { |
|||
if (type != ")") cont(expression); |
|||
} |
|||
function functiondef(type, value) { |
|||
if (value == "*") {cx.marked = "keyword"; return cont(functiondef);} |
|||
if (type == "variable") {register(value); return cont(functiondef);} |
|||
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, statement, popcontext); |
|||
} |
|||
function funarg(type) { |
|||
if (type == "spread") return cont(funarg); |
|||
return pass(pattern, maybetype); |
|||
} |
|||
function className(type, value) { |
|||
if (type == "variable") {register(value); return cont(classNameAfter);} |
|||
} |
|||
function classNameAfter(type, value) { |
|||
if (value == "extends") return cont(expression, classNameAfter); |
|||
if (type == "{") return cont(pushlex("}"), classBody, poplex); |
|||
} |
|||
function classBody(type, value) { |
|||
if (type == "variable" || cx.style == "keyword") { |
|||
cx.marked = "property"; |
|||
if (value == "get" || value == "set") return cont(classGetterSetter, functiondef, classBody); |
|||
return cont(functiondef, classBody); |
|||
} |
|||
if (value == "*") { |
|||
cx.marked = "keyword"; |
|||
return cont(classBody); |
|||
} |
|||
if (type == ";") return cont(classBody); |
|||
if (type == "}") return cont(); |
|||
} |
|||
function classGetterSetter(type) { |
|||
if (type != "variable") return pass(); |
|||
cx.marked = "property"; |
|||
return cont(); |
|||
} |
|||
function afterModule(type, value) { |
|||
if (type == "string") return cont(statement); |
|||
if (type == "variable") { register(value); return cont(maybeFrom); } |
|||
} |
|||
function afterExport(_type, value) { |
|||
if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); } |
|||
if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); } |
|||
return pass(statement); |
|||
} |
|||
function afterImport(type) { |
|||
if (type == "string") return cont(); |
|||
return pass(importSpec, maybeFrom); |
|||
} |
|||
function importSpec(type, value) { |
|||
if (type == "{") return contCommasep(importSpec, "}"); |
|||
if (type == "variable") register(value); |
|||
return cont(); |
|||
} |
|||
function maybeFrom(_type, value) { |
|||
if (value == "from") { cx.marked = "keyword"; return cont(expression); } |
|||
} |
|||
function arrayLiteral(type) { |
|||
if (type == "]") return cont(); |
|||
return pass(expressionNoComma, maybeArrayComprehension); |
|||
} |
|||
function maybeArrayComprehension(type) { |
|||
if (type == "for") return pass(comprehension, expect("]")); |
|||
if (type == ",") return cont(commasep(maybeexpressionNoComma, "]")); |
|||
return pass(commasep(expressionNoComma, "]")); |
|||
} |
|||
function comprehension(type) { |
|||
if (type == "for") return cont(forspec, comprehension); |
|||
if (type == "if") return cont(expression, comprehension); |
|||
} |
|||
|
|||
// Interface
|
|||
|
|||
return { |
|||
startState: function(basecolumn) { |
|||
var state = { |
|||
tokenize: tokenBase, |
|||
lastType: "sof", |
|||
cc: [], |
|||
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false), |
|||
localVars: parserConfig.localVars, |
|||
context: parserConfig.localVars && {vars: parserConfig.localVars}, |
|||
indented: 0 |
|||
}; |
|||
if (parserConfig.globalVars && typeof parserConfig.globalVars == "object") |
|||
state.globalVars = parserConfig.globalVars; |
|||
return state; |
|||
}, |
|||
|
|||
token: function(stream, state) { |
|||
if (stream.sol()) { |
|||
if (!state.lexical.hasOwnProperty("align")) |
|||
state.lexical.align = false; |
|||
state.indented = stream.indentation(); |
|||
findFatArrow(stream, state); |
|||
} |
|||
if (state.tokenize != tokenComment && stream.eatSpace()) return null; |
|||
var style = state.tokenize(stream, state); |
|||
if (type == "comment") return style; |
|||
state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type; |
|||
return parseJS(state, style, type, content, stream); |
|||
}, |
|||
|
|||
indent: function(state, textAfter) { |
|||
if (state.tokenize == tokenComment) return CodeMirror.Pass; |
|||
if (state.tokenize != tokenBase) return 0; |
|||
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical; |
|||
// Kludge to prevent 'maybelse' from blocking lexical scope pops
|
|||
if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) { |
|||
var c = state.cc[i]; |
|||
if (c == poplex) lexical = lexical.prev; |
|||
else if (c != maybeelse) break; |
|||
} |
|||
if (lexical.type == "stat" && firstChar == "}") lexical = lexical.prev; |
|||
if (statementIndent && lexical.type == ")" && lexical.prev.type == "stat") |
|||
lexical = lexical.prev; |
|||
var type = lexical.type, closing = firstChar == type; |
|||
|
|||
if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info + 1 : 0); |
|||
else if (type == "form" && firstChar == "{") return lexical.indented; |
|||
else if (type == "form") return lexical.indented + indentUnit; |
|||
else if (type == "stat") |
|||
return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? statementIndent || indentUnit : 0); |
|||
else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false) |
|||
return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit); |
|||
else if (lexical.align) return lexical.column + (closing ? 0 : 1); |
|||
else return lexical.indented + (closing ? 0 : indentUnit); |
|||
}, |
|||
|
|||
electricInput: /^\s*(?:case .*?:|default:|\{|\})$/, |
|||
blockCommentStart: jsonMode ? null : "/*", |
|||
blockCommentEnd: jsonMode ? null : "*/", |
|||
lineComment: jsonMode ? null : "//", |
|||
fold: "brace", |
|||
|
|||
helperType: jsonMode ? "json" : "javascript", |
|||
jsonldMode: jsonldMode, |
|||
jsonMode: jsonMode |
|||
}; |
|||
}); |
|||
|
|||
CodeMirror.registerHelper("wordChars", "javascript", /[\w$]/); |
|||
|
|||
CodeMirror.defineMIME("text/javascript", "javascript"); |
|||
CodeMirror.defineMIME("text/ecmascript", "javascript"); |
|||
CodeMirror.defineMIME("application/javascript", "javascript"); |
|||
CodeMirror.defineMIME("application/x-javascript", "javascript"); |
|||
CodeMirror.defineMIME("application/ecmascript", "javascript"); |
|||
CodeMirror.defineMIME("application/json", {name: "javascript", json: true}); |
|||
CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true}); |
|||
CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true}); |
|||
CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true }); |
|||
CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true }); |
|||
|
|||
}); |
@ -0,0 +1,120 @@ |
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|||
// Distributed under an MIT license: http://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) { |
|||
var ie_lt8 = /MSIE \d/.test(navigator.userAgent) && |
|||
(document.documentMode == null || document.documentMode < 8); |
|||
|
|||
var Pos = CodeMirror.Pos; |
|||
|
|||
var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"}; |
|||
|
|||
function findMatchingBracket(cm, where, strict, config) { |
|||
var line = cm.getLineHandle(where.line), pos = where.ch - 1; |
|||
var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)]; |
|||
if (!match) return null; |
|||
var dir = match.charAt(1) == ">" ? 1 : -1; |
|||
if (strict && (dir > 0) != (pos == where.ch)) return null; |
|||
var style = cm.getTokenTypeAt(Pos(where.line, pos + 1)); |
|||
|
|||
var found = scanForBracket(cm, Pos(where.line, pos + (dir > 0 ? 1 : 0)), dir, style || null, config); |
|||
if (found == null) return null; |
|||
return {from: Pos(where.line, pos), to: found && found.pos, |
|||
match: found && found.ch == match.charAt(0), forward: dir > 0}; |
|||
} |
|||
|
|||
// bracketRegex is used to specify which type of bracket to scan
|
|||
// should be a regexp, e.g. /[[\]]/
|
|||
//
|
|||
// Note: If "where" is on an open bracket, then this bracket is ignored.
|
|||
//
|
|||
// Returns false when no bracket was found, null when it reached
|
|||
// maxScanLines and gave up
|
|||
function scanForBracket(cm, where, dir, style, config) { |
|||
var maxScanLen = (config && config.maxScanLineLength) || 10000; |
|||
var maxScanLines = (config && config.maxScanLines) || 1000; |
|||
|
|||
var stack = []; |
|||
var re = config && config.bracketRegex ? config.bracketRegex : /[(){}[\]]/; |
|||
var lineEnd = dir > 0 ? Math.min(where.line + maxScanLines, cm.lastLine() + 1) |
|||
: Math.max(cm.firstLine() - 1, where.line - maxScanLines); |
|||
for (var lineNo = where.line; lineNo != lineEnd; lineNo += dir) { |
|||
var line = cm.getLine(lineNo); |
|||
if (!line) continue; |
|||
var pos = dir > 0 ? 0 : line.length - 1, end = dir > 0 ? line.length : -1; |
|||
if (line.length > maxScanLen) continue; |
|||
if (lineNo == where.line) pos = where.ch - (dir < 0 ? 1 : 0); |
|||
for (; pos != end; pos += dir) { |
|||
var ch = line.charAt(pos); |
|||
if (re.test(ch) && (style === undefined || cm.getTokenTypeAt(Pos(lineNo, pos + 1)) == style)) { |
|||
var match = matching[ch]; |
|||
if ((match.charAt(1) == ">") == (dir > 0)) stack.push(ch); |
|||
else if (!stack.length) return {pos: Pos(lineNo, pos), ch: ch}; |
|||
else stack.pop(); |
|||
} |
|||
} |
|||
} |
|||
return lineNo - dir == (dir > 0 ? cm.lastLine() : cm.firstLine()) ? false : null; |
|||
} |
|||
|
|||
function matchBrackets(cm, autoclear, config) { |
|||
// Disable brace matching in long lines, since it'll cause hugely slow updates
|
|||
var maxHighlightLen = cm.state.matchBrackets.maxHighlightLineLength || 1000; |
|||
var marks = [], ranges = cm.listSelections(); |
|||
for (var i = 0; i < ranges.length; i++) { |
|||
var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, false, config); |
|||
if (match && cm.getLine(match.from.line).length <= maxHighlightLen) { |
|||
var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket"; |
|||
marks.push(cm.markText(match.from, Pos(match.from.line, match.from.ch + 1), {className: style})); |
|||
if (match.to && cm.getLine(match.to.line).length <= maxHighlightLen) |
|||
marks.push(cm.markText(match.to, Pos(match.to.line, match.to.ch + 1), {className: style})); |
|||
} |
|||
} |
|||
|
|||
if (marks.length) { |
|||
// Kludge to work around the IE bug from issue #1193, where text
|
|||
// input stops going to the textare whever this fires.
|
|||
if (ie_lt8 && cm.state.focused) cm.display.input.focus(); |
|||
|
|||
var clear = function() { |
|||
cm.operation(function() { |
|||
for (var i = 0; i < marks.length; i++) marks[i].clear(); |
|||
}); |
|||
}; |
|||
if (autoclear) setTimeout(clear, 800); |
|||
else return clear; |
|||
} |
|||
} |
|||
|
|||
var currentlyHighlighted = null; |
|||
function doMatchBrackets(cm) { |
|||
cm.operation(function() { |
|||
if (currentlyHighlighted) {currentlyHighlighted(); currentlyHighlighted = null;} |
|||
currentlyHighlighted = matchBrackets(cm, false, cm.state.matchBrackets); |
|||
}); |
|||
} |
|||
|
|||
CodeMirror.defineOption("matchBrackets", false, function(cm, val, old) { |
|||
if (old && old != CodeMirror.Init) |
|||
cm.off("cursorActivity", doMatchBrackets); |
|||
if (val) { |
|||
cm.state.matchBrackets = typeof val == "object" ? val : {}; |
|||
cm.on("cursorActivity", doMatchBrackets); |
|||
} |
|||
}); |
|||
|
|||
CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);}); |
|||
CodeMirror.defineExtension("findMatchingBracket", function(pos, strict, config){ |
|||
return findMatchingBracket(this, pos, strict, config); |
|||
}); |
|||
CodeMirror.defineExtension("scanForBracket", function(pos, dir, style, config){ |
|||
return scanForBracket(this, pos, dir, style, config); |
|||
}); |
|||
}); |
Loading…
Reference in new issue