Skip to content

Commit 12ced2c

Browse files
committed
Commenting on Erlang, Julia, Java and YAML
Using commentChar now to handle char used on commenting (# or % for Erlang) Erlang, Julia, Java and YAML commenting covered Include Python also as forgotten adjustCursor to be set to 1 on single chars, overriding 2 Cursor adjusting done here now, not in parent function anymore as adjustCursor value not available from that scope
1 parent 43ddc3d commit 12ced2c

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

processes/on-editor-load.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@
3939

4040
// Comment/uncomment line or selected range on keypress
4141
top.ICEcoder.lineCommentToggleSub = function(cM, cursorPos, linePos, lineContent, lCLen, adjustCursor) {
42-
var startLine, endLine;
42+
var startLine, endLine, commentChar;
4343

44-
if (["JavaScript","CoffeeScript","PHP","Python","Ruby","CSS","SQL"].indexOf(top.ICEcoder.caretLocType)>-1) {
44+
if (["JavaScript","CoffeeScript","PHP","Python","Ruby","CSS","SQL","Erlang","Julia","Java","YAML"].indexOf(top.ICEcoder.caretLocType)>-1) {
4545
if (cM.somethingSelected()) {
46-
if (top.ICEcoder.caretLocType=="Ruby"||top.ICEcoder.caretLocType=="Python") {
46+
if (["Ruby","Python","Erlang","Julia","YAML"].indexOf(top.ICEcoder.caretLocType)>-1) {
47+
commentChar = top.ICEcoder.caretLocType == "Erlang" ? "%" : "#";
4748
startLine = cM.getCursor(true).line;
4849
endLine = cM.getCursor().line;
4950
for (var i=startLine; i<=endLine; i++) {
50-
cM.setLine(i, cM.getLine(i).slice(0,1)!="#"
51-
? "#" + cM.getLine(i)
51+
cM.setLine(i, cM.getLine(i).slice(0,1)!=commentChar
52+
? commentChar + cM.getLine(i)
5253
: cM.getLine(i).slice(1,cM.getLine(i).length));
5354
}
5455
} else {
@@ -62,11 +63,13 @@
6263
? "/*" + lineContent + "*/"
6364
: lineContent.slice(2,lCLen).slice(0,lCLen-4));
6465
if (lineContent.slice(0,2)=="/*") {adjustCursor = -adjustCursor};
65-
} else if (top.ICEcoder.caretLocType=="Ruby") {
66-
cM.setLine(linePos, lineContent.slice(0,1)!="#"
67-
? "#" + lineContent
66+
} else if (["Ruby","Python","Erlang","Julia","YAML"].indexOf(top.ICEcoder.caretLocType)>-1) {
67+
commentChar = top.ICEcoder.caretLocType == "Erlang" ? "%" : "#";
68+
cM.setLine(linePos, lineContent.slice(0,1)!=commentChar
69+
? commentChar + lineContent
6870
: lineContent.slice(1,lCLen));
69-
if (lineContent.slice(0,1)=="#") {adjustCursor = -adjustCursor};
71+
adjustCursor = 1;
72+
if (lineContent.slice(0,1)==commentChar) {adjustCursor = -adjustCursor};
7073
} else {
7174
cM.setLine(linePos, lineContent.slice(0,2)!="//"
7275
? "//" + lineContent
@@ -86,6 +89,8 @@
8689
adjustCursor = lineContent.slice(0,4)=="<\!--" ? -4 : 4;
8790
}
8891
}
92+
93+
if (!cM.somethingSelected()) {cM.setCursor(linePos, cursorPos+adjustCursor)};
8994
}
9095

9196
// Work out the nesting depth location on demand and update our display if required

0 commit comments

Comments
 (0)