forked from icecoder/ICEcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathon-editor-load.php
More file actions
198 lines (181 loc) · 7.85 KB
/
on-editor-load.php
File metadata and controls
198 lines (181 loc) · 7.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
if (!isset($_SESSION['loggedIn'])) {
die('Sorry, not logged in.');
}
?>
<!--
Purpose: This file is run when ICEcoder editor has loaded
Langs: Anything - PHP, JS etc
//-->
<script>
CodeMirror.commands.autocomplete = function(cm) {
var langType = top.ICEcoder.caretLocType;
if (["JavaScript","CoffeeScript","TypeScript","SQL","CSS","HTML","XML","Content"].indexOf(langType)>-1) {
if (langType=="XML"||langType=="Content") {langType="HTML"};
CodeMirror.showHint(cm,CodeMirror.hint[langType.toLowerCase()]);
}
}
// Switch the CodeMirror mode on demand
top.ICEcoder.switchMode = function(mode) {
var cM, cMdiff, fileName, fileExt;
cM = top.ICEcoder.getcMInstance();
cMdiff = top.ICEcoder.getcMdiffInstance();
fileName = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1];
if (cM && mode) {
if (mode != cM.getOption("mode")) {
cM.setOption("mode",mode);
cMdiff.setOption("mode",mode);
}
} else if (cM && fileName) {
<?php include(dirname(__FILE__)."/../lib/language-modes-partial.js");?>
if (mode != cM.getOption("mode")) {
cM.setOption("mode",mode);
cM.setOption("lint",(fileExt == "js" || fileExt == "json") && top.ICEcoder.codeAssist ? true : false);
cMdiff.setOption("mode",mode);
cMdiff.setOption("lint",(fileExt == "js" || fileExt == "json") && top.ICEcoder.codeAssist ? true : false);
}
}
}
// Comment/uncomment line or selected range on keypress
top.ICEcoder.lineCommentToggleSub = function(cM, cursorPos, linePos, lineContent, lCLen) {
var comments, startLine, endLine, commentCH, commentBS, commentBE;
// Language specific commenting
if (["JavaScript","CoffeeScript","TypeScript","PHP","Python","Ruby","CSS","SQL","Erlang","Julia","Java","YAML","C","C++","C#","Go","Lua","Perl","Sass"].indexOf(top.ICEcoder.caretLocType)>-1) {
comments = {
"JavaScript" : ["// ", "/* ", " */"],
"CoffeeScript" : ["# ", "### ", " ###"],
"TypeScript" : ["// ", "/* ", " */"],
"PHP" : ["// ", "/* ", " */"],
"Python" : ["# ", "/* ", " */"],
"Ruby" : ["# ", "/* ", " */"],
"CSS" : ["// ", "/* ", " */"],
"SQL" : ["// ", "/* ", " */"],
"Erlang" : ["% ", "/* ", " */"],
"Julia" : ["# ", "/* ", " */"],
"Java" : ["// ", "/* ", " */"],
"YAML" : ["# ", "/* ", " */"],
"C" : ["// ", "/* ", " */"],
"C++" : ["// ", "/* ", " */"],
"C#" : ["// ", "/* ", " */"],
"Go" : ["// ", "/* ", " */"],
"Lua" : ["-- ", "--[[ ", " ]]"],
"Perl" : ["# ", "/* ", " */"],
"Sass" : ["// ", "/* ", " */"]
}
// Identify the single line, block start and block end comment chars
commentCH = comments[top.ICEcoder.caretLocType][0];
commentBS = comments[top.ICEcoder.caretLocType][1];
commentBE = comments[top.ICEcoder.caretLocType][2];
// Block commenting
if (cM.somethingSelected()) {
// Language has no block commenting, so repeating singles are needed
if (["Ruby","Python","Erlang","Julia","YAML","Perl"].indexOf(top.ICEcoder.caretLocType)>-1) {
startLine = cM.getCursor(true).line;
endLine = cM.getCursor().line;
for (var i=startLine; i<=endLine; i++) {
cM.replaceRange(cM.getLine(i).slice(0,commentCH.length)!=commentCH
? commentCH + cM.getLine(i)
: cM.getLine(i).slice(commentCH.length,cM.getLine(i).length), {line:i, ch:0}, {line:i, ch:1000000});
}
// Language has block commenting
} else {
cM.replaceSelection(cM.getSelection().slice(0,commentBS.length)!=commentBS
? commentBS + cM.getSelection() + commentBE
: cM.getSelection().slice(commentBS.length,cM.getSelection().length-commentBE.length),"around");
}
// Single line commenting
} else {
if (["CSS","SQL"].indexOf(top.ICEcoder.caretLocType)>-1) {
cM.replaceRange(lineContent.slice(0,commentBS.length)!=commentBS
? commentBS + lineContent + commentBE
: lineContent.slice(commentBS.length,lCLen-commentBE.length), {line: linePos, ch: 0}, {line: linePos, ch: 1000000});
adjustCursor = commentBS.length;
if (lineContent.slice(0,commentBS.length)==commentBS) {adjustCursor = -adjustCursor};
} else {
cM.replaceRange(lineContent.slice(0,commentCH.length)!=commentCH
? commentCH + lineContent
: lineContent.slice(commentCH.length,lCLen), {line: linePos, ch: 0}, {line: linePos, ch: 1000000});
adjustCursor = commentCH.length;
if (lineContent.slice(0,commentCH.length)==commentCH) {adjustCursor = -adjustCursor};
}
}
// HTML style commenting
} else {
if (cM.somethingSelected()) {
cM.replaceSelection(cM.getSelection().slice(0,4)!="<\!--"
? "<\!--" + cM.getSelection() + "//-->"
: cM.getSelection().slice(4,cM.getSelection().length-5),"around");
} else {
cM.replaceRange(lineContent.slice(0,4)!="<\!--"
? "<\!--" + lineContent + "//-->"
: lineContent.slice(4,lCLen-5), {line: linePos, ch: 0}, {line: linePos, ch: 1000000});
adjustCursor = lineContent.slice(0,4)=="<\!--" ? -4 : 4;
}
}
if (!cM.somethingSelected()) {cM.setCursor(linePos, cursorPos+adjustCursor)};
}
// Indicate if the nesting structure of the code is OK
top.ICEcoder.updateNestingIndicator = function() {
var cM, cMdiff, thisCM, testToken, nestOK, fileName, fileExt;
cM = top.ICEcoder.getcMInstance();
cMdiff = top.ICEcoder.getcMdiffInstance();
thisCM = top.ICEcoder.editorFocusInstance.indexOf('diff') > -1 ? cMdiff : cM;
nestOK = true;
fileName = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1];
if (fileName) {
fileExt = fileName.split(".");
fileExt = fileExt[fileExt.length-1];
}
if (thisCM && fileName && ["js","coffee","ts","css","less","sql","erl","yaml","java","jl","c","cpp","ino","cs","go","lua","pl","scss"].indexOf(fileExt)==-1) {
testToken = thisCM.getTokenAt({line:thisCM.lineCount(),ch:thisCM.lineInfo(thisCM.lineCount()-1).text.length});
nestOK = testToken.type && testToken.type.indexOf("error") == -1 ? true : false;
}
top.ICEcoder.nestValid.style.background = nestOK ? "#0b0" : "#f00";
top.ICEcoder.nestValid.title = nestOK ? "Nesting OK" : "Nesting Broken";
}
// Determine which area of the document we're in
top.ICEcoder.caretLocationType = function() {
var cM, cMdiff, thisCM, caretLocType, caretChunk, fileName, fileExt;
cM = top.ICEcoder.getcMInstance();
cMdiff = top.ICEcoder.getcMdiffInstance();
thisCM = top.ICEcoder.editorFocusInstance.indexOf('diff') > -1 ? cMdiff : cM;
caretLocType = "Unknown";
caretChunk = thisCM.getValue().substr(0,top.ICEcoder.caretPos+1);
if(caretChunk.lastIndexOf("<script")>caretChunk.lastIndexOf("/script>")&&caretLocType=="Unknown") {caretLocType = "JavaScript";}
else if (caretChunk.lastIndexOf("<\?")>caretChunk.lastIndexOf("?\>")&&caretLocType=="Unknown") {caretLocType = "PHP";}
else if (caretChunk.lastIndexOf("<\%")>caretChunk.lastIndexOf("%\>")&&caretLocType=="Unknown") {caretLocType = "Ruby";}
else if (caretChunk.lastIndexOf("<style")>caretChunk.lastIndexOf("/style>")&&caretLocType=="Unknown") {caretLocType = "CSS";}
else if (caretChunk.lastIndexOf("<")>caretChunk.lastIndexOf(">")&&caretLocType=="Unknown") {caretLocType = "HTML";}
else if (caretLocType=="Unknown") {caretLocType = "Content";};
fileName = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1];
if (caretLocType == "Content" && fileName) {
fileExt = fileName.split(".");
fileExt = fileExt[fileExt.length-1];
caretLocType =
fileExt == "js" ? "JavaScript"
: fileExt == "coffee" ? "CoffeeScript"
: fileExt == "ts" ? "TypeScript"
: fileExt == "py" ? "Python"
: fileExt == "rb" ? "Ruby"
: fileExt == "css" ? "CSS"
: fileExt == "less" ? "LESS"
: fileExt == "md" ? "Markdown"
: fileExt == "xml" ? "XML"
: fileExt == "sql" ? "SQL"
: fileExt == "yaml" ? "YAML"
: fileExt == "java" ? "Java"
: fileExt == "erl" ? "Erlang"
: fileExt == "jl" ? "Julia"
: fileExt == "c" ? "C"
: fileExt == "cpp" ? "C++"
: fileExt == "ino" ? "C++"
: fileExt == "cs" ? "C#"
: fileExt == "go" ? "Go"
: fileExt == "lua" ? "Lua"
: fileExt == "pl" ? "Perl"
: fileExt == "scss" ? "Sass"
: "Content";
}
top.ICEcoder.caretLocType = caretLocType;
}
</script>