forked from icecoder/ICEcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathice-coder.js
More file actions
4533 lines (3979 loc) · 179 KB
/
ice-coder.js
File metadata and controls
4533 lines (3979 loc) · 179 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Get any elem by ID
var get = function(elem) {
return top.document.getElementById(elem);
};
// Main ICEcoder object
var ICEcoder = {
// ==============
// INIT
// ==============
// Define settings
filesW: 250, // Width of files pane
minFilesW: 14, // Min width of files pane
maxFilesW: 250, // Max width of files pane
selectedTab: 0, // The tab that's currently selected
savedPoints: [], // Ints array to indicate save points for docs
savedContents: [], // Array of last known saved contents
canSwitchTabs: true, // Stops switching of tabs when trying to close
openFiles: [], // Array of open file URLs
openFileMDTs: [], // Array of open file modification datetimes
openFileVersions: [], // Array of open file version counts
cMInstances: [], // List of CodeMirror instance no's
nextcMInstance: 1, // Next available CodeMirror instance no
selectedFiles: [], // Array of selected files
findMode: false, // States if we're in find/replace mode
scrollbarVisible: false, // Indicates if the main pane has a scrollbar
mouseDown: false, // If the mouse is down
mouseDownInCM: false, // If the mouse is down within CodeMirror instance (can be false, 'editor' or 'gutter')
mouseDownMinimap: false, // If the mouse is down on Minimap nav box
draggingFilesW: false, // If we're dragging the file manager width
draggingTab: false, // If we're dragging a tab
draggingWithKey: false, // The key that's down while dragging, false if no key
tabLeftPos: [], // Array of left positions of tabs inside content area
tabBGcurrent: '#1d1d1b', // BG of current tab
tabBGselected: '#49d', // BG of selected tab
tabBGopen: '#c3c3c3', // BG of open tab
tabBGnormal: 'transparent', // BG of normal tab
tabFGcurrent: '#fff', // FG of selected tab
tabFGselected: '#fff', // FG of selected tab
tabFGopenFile: '#000', // FG of open file
tabFGnormalFile: '#eee', // FG of normal file
tabFGnormalTab: '#888', // FG of normal tab
serverQueueItems: [], // Array of URLs to call in order
miniMapBoxTop: 0, // Top of the minimap box highlighter
miniMapBoxHeight: 0, // Height of the minimap box highlighter
previewWindow: false, // Target variable for the preview window
previewWindowLoading: false, // Loading state of preview window
pluginIntervalRefs: [], // Array of plugin interval refs
overPopup: false, // Indicates if we're over a popup or not
cmdKey: false, // Tracking apple Command key up/down state
oppTagReplaceData: [], // Will contain data for automatic opposite tag replacement to sync them
fmReady: false, // Indicates if the file manager is ready for action
bugReportStatus: "off", // Values of: off, error, ok, bugs
bugReportPath: "", // Bug report file path
bugFilesSizesSeen: [], // Array of last seen sizes of bug files
bugFilesSizesActual: [], // Array of actual sizes of bug files
githubDiff: false, // Toggle for viewing GitHub/FM diff view
githubAuthTokenSet: false, // Has the user set their GitHub token yet
splitPane: false, // Single or split pane editing
splitPaneLeftPerc: 100, // Width of left pane as a percentage
renderLineStyle: [], // Array of styles to apply on renderLine event
renderPaneShiftAmount: 0, // Shift comparison main (negative) vs diff pane (positive)
debounce: "", // Contains debounce timeout object
editorFocusInstance: "", // Name of editor instance that has focus
openSeconds: 0, // Number of seconds ICEcoder has been open for
ready: false, // Indicates if ICEcoder is ready for action
// Set our aliases
initAliases: function() {
var aliasArray = ["header","files", "fileOptions", "optionsFile", "optionsEdit", "optionsSource", "optionsHelp", "filesFrame", "editor", "tabsBar", "findBar", "content", "terminal", "footer", "nestValid", "versionsDisplay", "splitPaneControls", "splitPaneNamesMain", "splitPaneNamesDiff", "charDisplay", "byteDisplay", "docExplorer", "miniMap", "miniMapContainer", "miniMapContent", "functionClassList"];
// Create our ID aliases
for (var i=0;i<aliasArray.length;i++) {
ICEcoder[aliasArray[i]] = top.get(aliasArray[i]);
}
},
// On load, set the layout and check any nesting is valid
init: function() {
var screenIcon, sISrc;
// Contract the file manager if the user has set to have it hidden
if (!top.ICEcoder.lockedNav) {
top.ICEcoder.filesW = ICEcoder.minFilesW;
}
// Set layout
ICEcoder.setLayout();
top.ICEcoder.overFileFolder('folder', '|');
top.ICEcoder.selectFileFolder('init');
top.ICEcoder.filesFrame.contentWindow.focus();
// Hide the loading screen & auto open last files?
top.ICEcoder.showHide('hide',top.get('loadingMask'));
top.ICEcoder.autoOpenInt = setInterval(function() {
if (top.ICEcoder.fmReady) {
// Delay auto open process by 200ms to give trial bar time to begin animation
if (top.ICEcoder.openLastFiles) {setTimeout(function() {top.ICEcoder.autoOpenFiles()},200);};
clearInterval(top.ICEcoder.autoOpenInt);
}
}, 4);
// Update the nesting indicator every 30ms
setInterval(ICEcoder.updateNestingIndicator,30);
// Start bug checking
top.ICEcoder.startBugChecking();
// Set the time since last user interaction
top.ICEcoder.autoLogoutTimer = 0;
// Start our interval timer, runs every second
top.ICEcoder.oneSecondInt = setInterval(function() {
top.ICEcoder.autoLogoutTimer++;
var unsavedFiles = false;
// Check if we have any unsaved files
for(var i=1;i<=ICEcoder.savedPoints.length;i++) {
if (ICEcoder.savedPoints[i-1]!=top.ICEcoder.getcMInstance(i).changeGeneration()) {
unsavedFiles = true;
}
}
// Show an auto-logout warning 60 secs before a logout
if(!unsavedFiles && top.ICEcoder.autoLogoutMins > 1 && top.ICEcoder.autoLogoutTimer == (top.ICEcoder.autoLogoutMins*60)-60) {
top.ICEcoder.autoLogoutWarningScreen();
}
if (get('autoLogoutIFrame') && get('autoLogoutIFrame').contentWindow.document.getElementById('timeRemaning')) {
get('autoLogoutIFrame').contentWindow.document.getElementById('timeRemaning').innerHTML =
top.ICEcoder.autoLogoutTimer > 0
? (top.ICEcoder.autoLogoutMins*60) - top.ICEcoder.autoLogoutTimer
: 0;
}
// If there aren't any unsaved files, we have a timeout period > 0 and the time is up, we can logout
if(!unsavedFiles && ICEcoder.autoLogoutMins > 0 && top.ICEcoder.autoLogoutTimer >= top.ICEcoder.autoLogoutMins*60) {
top.ICEcoder.logout('autoLogout');
}
// Finally, increase number of seconds ICEcoder has been open for by 1
top.ICEcoder.openSeconds++;
// Every 5 mins, ping our file to keep the session alive
if (top.ICEcoder.openSeconds % 300 == 0) {
top.ICEcoder.filesFrame.contentWindow.frames['pingActive'].location.href = "lib/session-active-ping.php";
}
},1000);
// ICEcoder is ready to start using
top.ICEcoder.ready = true;
},
// ==============
// LAYOUT
// ==============
// Set our layout according to the browser size
setLayout: function(dontSetEditor) {
var winW, winH, headerH, fileNavH, tabsBarH, findBarH;
// Determin width & height available
winW = window.innerWidth;
winH = window.innerHeight;
// Apply sizes to various elements of the page
headerH = 25, fileNavH = 35, tabsBarH = 21, findBarH = 28;
this.header.style.width = this.tabsBar.style.width = this.findBar.style.width = winW + "px";
this.files.style.width = this.editor.style.left = this.filesW + "px";
this.optionsFile.style.width = this.optionsEdit.style.width = this.optionsSource.style.width = this.optionsHelp.style.width = (this.filesW-60) + "px";
this.filesFrame.style.height = (winH-headerH-fileNavH) + "px";
this.nestValid.style.left = (this.filesW+10) + "px";
this.versionsDisplay.style.left = (this.filesW+25) + "px";
this.splitPaneControls.style.left = (parseInt((winW-this.filesW)/2,10)-25-4+this.filesW) - 100 + "px";
this.splitPaneNamesMain.style.left = (parseInt((winW-this.filesW)*0.25,10)-50+this.filesW) - 60 + "px";
this.splitPaneNamesDiff.style.left = (parseInt((winW-this.filesW)*0.75,10)-50+this.filesW) - 135 + "px";
top.ICEcoder.setTabWidths();
// If we need to set the editor sizes
if (!dontSetEditor) {
this.editor.style.width = ICEcoder.content.style.width = (winW-this.filesW) - 200 + "px";
ICEcoder.terminal.style.width = (winW-this.filesW) + "px";
ICEcoder.content.style.height = (winH-headerH-tabsBarH-findBarH-26) + "px";
ICEcoder.terminal.style.height = winH + "px";
// Resize the CodeMirror instances to match the window size
setTimeout(function(){
for (var i=0;i<top.ICEcoder.openFiles.length;i++) {
// Done the long way here as we need to call them in specific order to stop showing background and so avoiding a flicker effect
if (!top.ICEcoder.splitPane) {
top.ICEcoder.content.contentWindow['cM'+ICEcoder.cMInstances[i]].setSize(top.ICEcoder.splitPaneLeftPerc+"%",top.ICEcoder.content.style.height);
}
top.ICEcoder.content.contentWindow['cM'+ICEcoder.cMInstances[i]+'diff'].setSize((100-top.ICEcoder.splitPaneLeftPerc)+"%",top.ICEcoder.content.style.height);
top.ICEcoder.content.contentWindow['cM'+ICEcoder.cMInstances[i]+'diff'].getWrapperElement().style.left = top.ICEcoder.splitPaneLeftPerc+"%";
if (top.ICEcoder.splitPane) {
top.ICEcoder.content.contentWindow['cM'+ICEcoder.cMInstances[i]].setSize(top.ICEcoder.splitPaneLeftPerc+"%",top.ICEcoder.content.style.height);
}
}
// Set height of docExplorer
this.docExplorer.style.height = top.ICEcoder.content.style.height;
// Place resultsBar to edge of pane or it's scrollbar
if (!top.ICEcoder.splitPane) {
top.ICEcoder.content.contentWindow.document.getElementById('resultsBar').style.right = !top.ICEcoder.scrollBarVisible ? "0" : "17px";
} else {
top.ICEcoder.content.contentWindow.document.getElementById('resultsBar').style.right = !top.ICEcoder.scrollBarVisible ? parseInt(parseInt(ICEcoder.content.style.width,10)/2,10)+"px" : (parseInt(parseInt(ICEcoder.content.style.width,10)/2,10)+17)+"px";
}
},4);
}
},
// Set the layout as split pane or not
setSplitPane: function(onOff) {
var cM, cMdiff;
top.ICEcoder.splitPane = onOff == "on" ? true : false;
top.get('splitPaneControlsOff').style.opacity = top.ICEcoder.splitPane ? 0.5 : 1;
top.get('splitPaneControlsOn').style.opacity = top.ICEcoder.splitPane ? 1 : 0.5;
top.get('splitPaneNamesMain').style.opacity = top.get('splitPaneNamesDiff').style.opacity = top.ICEcoder.splitPane ? 1 : 0;
top.ICEcoder.setLayout();
// Also clear marks (if going to a single pane) or redo the marks (if split pane)
if (top.ICEcoder.splitPane) {
top.ICEcoder.updateDiffs();
// Also set the scroll position to match
cM = top.ICEcoder.getcMInstance();
top.ICEcoder.cMonScroll(cM,'cM'+ICEcoder.cMInstances[ICEcoder.selectedTab-1]);
} else {
cM = top.ICEcoder.getcMInstance();
cMdiff = top.ICEcoder.getcMdiffInstance();
if (cM) {
// Clear all main pane marks
cMmarks = cM.getAllMarks();
for (var i=0; i<cMmarks.length; i++) {
cMmarks[i].clear();
}
// Clear all diff pane marks
cMdiffMarks = cMdiff.getAllMarks();
for (var i=0; i<cMdiffMarks.length; i++) {
cMdiffMarks[i].clear();
}
}
}
// Animate in/out the split pane
// First, clear any existing split pane interval anim
if ("undefined" != typeof top.ICEcoder.animSplitPaneInt) {
clearInterval(top.ICEcoder.animSplitPaneInt);
}
// Now set the interval to animate it in/out
top.ICEcoder.animSplitPaneInt = setInterval(function() {
// Animate split pane in
if (top.ICEcoder.splitPane && top.ICEcoder.splitPaneLeftPerc > 50.1) {
top.ICEcoder.splitPaneLeftPerc = ((top.ICEcoder.splitPaneLeftPerc-50)/1.8)+50;
// Animate split pane out
} else if (!top.ICEcoder.splitPane && top.ICEcoder.splitPaneLeftPerc < 99.9) {
top.ICEcoder.splitPaneLeftPerc = (50-((100-top.ICEcoder.splitPaneLeftPerc)/1.8))+50;
// Finish animating split pane in/out
} else {
top.ICEcoder.splitPaneLeftPerc = top.ICEcoder.splitPane ? 50 : 100;
clearInterval(top.ICEcoder.animSplitPaneInt);
}
top.ICEcoder.setLayout();
},4);
},
// Doc Explorer show item
docExplorerShow: function(item) {
var cM;
if (item == "terminal") {
get('terminal').style.display = 'block';
setTimeout(function(){
top.ICEcoder.terminal.contentWindow.document.getElementById('command').focus();
},0);
} else {
get('terminal').style.display = 'none';
get('miniMap').style.display = item == "miniMap" ? 'block' : 'none';
get('functionClassList').style.display = item == "functionClassList" ? 'block' : 'none';
if (item == "miniMap") {
top.miniMapInt = setInterval(function(){
if (get('miniMapContent').getBoundingClientRect().height != 0) {
cM = top.ICEcoder.getcMInstance();
top.ICEcoder.setMinimapLayout(cM);
clearInterval(top.miniMapInt);
}
},10);
}
}
},
// Set the width of the file manager on demand
changeFilesW: function(expandContract) {
if (!ICEcoder.lockedNav||ICEcoder.filesW==ICEcoder.minFilesW) {
if ("undefined" != typeof ICEcoder.changeFilesInt) {clearInterval(ICEcoder.changeFilesInt)};
ICEcoder.changeFilesInt = setInterval(function() {ICEcoder.changeFilesWStep(expandContract)},10);
}
},
// Expand/contract the file manager in half-steps
changeFilesWStep: function (expandContract) {
if (expandContract=="expand") {
ICEcoder.filesW < ICEcoder.maxFilesW-1 ? ICEcoder.filesW += Math.ceil((ICEcoder.maxFilesW-ICEcoder.filesW)/2) : ICEcoder.filesW = ICEcoder.maxFilesW;
} else {
ICEcoder.filesW > ICEcoder.minFilesW+1 ? ICEcoder.filesW -= Math.ceil((ICEcoder.filesW-ICEcoder.minFilesW)/2) : ICEcoder.filesW = ICEcoder.minFilesW;
}
if ((expandContract=="expand" && ICEcoder.filesW == ICEcoder.maxFilesW)||(expandContract=="contract" && ICEcoder.filesW == ICEcoder.minFilesW)) {
clearInterval(ICEcoder.changeFilesInt);
}
// Redo the layout to match
ICEcoder.setLayout();
},
// Can click-drag file manager width?
canResizeFilesW: function() {
// If we have the cursor set we must be able!
if (top.ICEcoder.ready && top.document.body.style.cursor == "w-resize") {
// If our mouse is down (and went down on the CM instance's gutter) and we're within a 250-400px range
if (top.ICEcoder.mouseDown && top.ICEcoder.mouseDownInCM == "gutter") {
top.ICEcoder.filesW = top.ICEcoder.maxFilesW = top.ICEcoder.mouseX >=250 && top.ICEcoder.mouseX <= 400
? top.ICEcoder.mouseX : top.ICEcoder.mouseX <250 ? 250 : 400;
// Set various widths based on the new width
top.ICEcoder.files.style.width = top.ICEcoder.filesFrame.style.width = top.ICEcoder.filesW + "px";
top.ICEcoder.setLayout();
top.ICEcoder.draggingFilesW = true;
}
} else {
top.ICEcoder.draggingFilesW = false;
}
},
// Lock & unlock the file manager navigation on demand
lockUnlockNav: function() {
var lockIcon;
lockIcon = top.ICEcoder.filesFrame.contentWindow.document.getElementById('fmLock');
ICEcoder.lockedNav = !ICEcoder.lockedNav;
lockIcon.style.backgroundPosition = ICEcoder.lockedNav ? "0 0" : "-16px 0";
},
// Show/hide the plugins on demand
showHidePlugins: function(showHide) {
get('plugins').style.width = showHide=="show" ? '55px' : '3px';
get('plugins').style.background = showHide=="show" ? '#333' : 'transparent';
if (showHide=="show") {
ICEcoder.changeFilesW('expand');
}
},
// ==============
// EDITOR
// ==============
// On focus
cMonFocus: function(thisCM,cMinstance) {
top.ICEcoder.getCaretPosition();
top.ICEcoder.updateCharDisplay();
top.ICEcoder.updateByteDisplay();
top.ICEcoder.editorFocusInstance = cMinstance;
top.ICEcoder.getCaretPosition();
},
// On blur
cMonBlur: function(thisCM,cMinstance) {
// Nothing as yet
},
// On key up
cMonKeyUp: function(thisCM,cMinstance) {
if ("undefined" != typeof top.doFind) {
clearInterval(top.doFind);
}
top.doFind = setTimeout(function() {
top.ICEcoder.findReplace(top.get('find').value,true,false);
},500);
top.ICEcoder.getCaretPosition();
top.ICEcoder.updateCharDisplay();
top.ICEcoder.updateByteDisplay();
},
// On cursor activity
cMonCursorActivity: function(thisCM,cMinstance) {
var thisCMPrevLine;
top.ICEcoder.getCaretPosition();
top.ICEcoder.updateCharDisplay();
top.ICEcoder.updateByteDisplay();
thisCM.removeLineClass(top.ICEcoder['cMActiveLine'+cMinstance], "background");
if(thisCM.getCursor('start').line == thisCM.getCursor().line) {
top.ICEcoder['cMActiveLine'+cMinstance] = thisCM.addLineClass(thisCM.getCursor().line, "background","cm-s-activeLine");
}
if (top.ICEcoder.caretLocType=="CSS") {
top.ICEcoder.cssColorPreview();
}
thisCMPrevLine = top.ICEcoder.editorFocusInstance.indexOf('diff') > -1 ? top.ICEcoder.prevLineDiff : top.ICEcoder.prevLine;
if (thisCMPrevLine != thisCM.getCursor().line &&
thisCM.getLine(thisCMPrevLine) &&
thisCM.getLine(thisCMPrevLine).length > 0 &&
thisCM.getLine(thisCMPrevLine).replace(/\s/g, '').length == 0) {
thisCM.replaceRange("",{line: thisCMPrevLine, ch: 0},{line: thisCMPrevLine, ch: 1000000});
}
// Set the cursor to text height, not line height
setTimeout(function() {
var paneMatch;
// Loop through styles to check if we have to adjust cursor height
for (var i=0; i<top.ICEcoder.renderLineStyle.length; i++) {
// We have no matching pane to start with
paneMatch = false;
// Is the pane we need to set the cursor on this pane?
if (
(top.ICEcoder.renderLineStyle[i][0] != "diff" && cMinstance.indexOf("diff") == -1) ||
(top.ICEcoder.renderLineStyle[i][0] == "diff" && cMinstance.indexOf("diff") > -1)
)
{paneMatch = true;}
// If the pane matches & also the line we're on is the line we have a style set for, set that cursor height
if (paneMatch && thisCM.getCursor().line+1 == top.ICEcoder.renderLineStyle[i][1]) {
thisCM.setOption("cursorHeight",thisCM.defaultTextHeight() / thisCM.lineInfo(thisCM.getCursor().line).handle.height);
} else {
thisCM.setOption("cursorHeight",1);
}
}
},0);
},
// On before change
cMonBeforeChange: function(thisCM,cMinstance,changeObj,cM) {
var sels, tagInfo, tagOpp, thisData;
// Get the selections
sels = thisCM.listSelections();
// For each of the user selections
for (var i=0; i<sels.length; i++) {
// Get the matching tagInfo for current cursor position
tagInfo = cM.findMatchingTag(thisCM, sels[i].anchor);
// If we're not ending a tag (autocompletion) and we have tagInfo and not undoing/redoing (which handles changes itself)
if (changeObj.text[0].indexOf(">") !== 0 && "undefined" != typeof tagInfo && changeObj.origin != "undo" && changeObj.origin != "redo") {
// If we also have both open and close tag info
if ("undefined" != typeof tagInfo.open && "undefined" != typeof tagInfo.close) {
// Log the opposite tag info
tagOpp = tagInfo.at == "open" ? "close" : "open";
if (tagInfo[tagOpp] !== null) {
thisData = tagInfo[tagOpp].tag + ";" + tagInfo[tagOpp].from.line + ":" + tagInfo[tagOpp].from.ch;
// Check that string firstly isn't in array and if not, push it in
if (top.ICEcoder.oppTagReplaceData.indexOf(thisData) == -1) {
top.ICEcoder.oppTagReplaceData.push(thisData);
}
}
}
}
}
},
// On change
cMonChange: function(thisCM,cMinstance,changeObj,cM) {
var sels, rData, theTag, thisLine, thisChar, tagInfo, charDiff, closeDiff, repl1, repl2, thisToken, tTS, filepath, filename, fileExt;
// Get the selections
sels = thisCM.listSelections();
// If we're not loading the file, it's a change, so update tab
if (!top.ICEcoder.loadingFile) {
top.ICEcoder.redoTabHighlight(top.ICEcoder.selectedTab);
// File load needs to force a simple change to get minimap functional
} else {
setTimeout(function(){
thisCM.replaceRange('X',{line: 1, ch: 1},{line: 1, ch: 1});
thisCM.undo();
thisCM.clearHistory();
top.ICEcoder.savedPoints[top.ICEcoder.selectedTab-1] = thisCM.changeGeneration();
top.ICEcoder.savedContents[top.ICEcoder.selectedTab-1] = thisCM.getValue();
},0);
}
// Detect if we have a scrollbar & set layout again
setTimeout(function() {
top.ICEcoder.scrollBarVisible = thisCM.getScrollInfo().height > thisCM.getScrollInfo().clientHeight;
top.ICEcoder.setLayout();
},0);
// If we're replacing opposite tag strings, do that
if ("undefined" != typeof top.ICEcoder.oppTagReplaceData[0]) {
// For each one of them, grab our data to work with
for (var i=0; i<top.ICEcoder.oppTagReplaceData.length; i++) {
// Extract data from that string
rData = top.ICEcoder.oppTagReplaceData[i].split(";");
theTag = rData[0];
thisLine = rData[1].split(":")[0]*1;
thisChar = rData[1].split(":")[1]*1;
// Get the tag info for matching tag
if (sels[i]) {
tagInfo = cM.findMatchingTag(thisCM, sels[i].anchor);
}
// If we have tagInfo
if ("undefined" != typeof tagInfo) {
// Get the opposite tag string
theTag = tagInfo.at == "open" ? tagInfo.open.tag : tagInfo.close.tag;
// If we have changeObj.from info to work with
if ("undefined" != typeof changeObj.from) {
// Same line changing needs a chararacter pos shift
charDiff = thisLine == changeObj.from.line
? changeObj.text[0].length - changeObj.removed[0].length
: 0;
// Also need to adjust if we're in the close tag on same line
closeDiff = tagInfo.at == "close" && thisLine == changeObj.from.line
? changeObj.removed[0].length - changeObj.text[0].length + 1
: 1
// Work out the replace from and to positions
repl1 = {line: thisLine, ch: thisChar+charDiff+(tagInfo.at == "open" ? 2 : closeDiff)};
repl2 = {line: thisLine, ch: thisChar+charDiff+(tagInfo.at == "open" ? 2 : closeDiff)+rData[0].length};
}
}
// Replace our string over the range, if this token string isn't blank and the end tag matches our original tag
if (theTag.trim() != "" && "undefined" != typeof repl1 && "undefined" != typeof repl2 && thisCM.getRange(repl1,repl2) == rData[0]) {
thisCM.replaceRange(theTag, repl1, repl2);
// If at the close tag, don't autocomplete
if (tagInfo.at == "close") {
top.ICEcoder.autocompleteSkip = true;
}
}
}
}
// Reset our array for next time
top.ICEcoder.oppTagReplaceData = [];
top.ICEcoder.getCaretPosition();
top.ICEcoder.updateCharDisplay();
top.ICEcoder.updateByteDisplay();
top.ICEcoder.updateNestingIndicator();
if (top.ICEcoder.findMode) {
top.ICEcoder.results.splice(top.ICEcoder.findResult,1);
top.get('results').innerHTML = top.ICEcoder.results.length + " " + top.t['results'];
top.ICEcoder.findMode = false;
}
// Update the list of functions and classes
top.ICEcoder.updateFunctionClassList();
// Update the minimap nav
if ("undefined" != typeof top.doMiniNav) {
clearTimeout(top.doMiniNav);
}
if (top.ICEcoder.loadingFile) {
// Load event means set it straight away
top.ICEcoder.setMinimap();
} else {
// Update event means do it after 1 sec of inactivity
top.doMiniNav = setTimeout(function() {
top.ICEcoder.setMinimap();
},1000);
}
filepath = top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1];
if (filepath) {
filename = filepath.substr(filepath.lastIndexOf("/")+1);
fileExt = filename.substr(filename.lastIndexOf(".")+1);
}
// Update diffs if we have a split pane
if (top.ICEcoder.splitPane) {
// Need 0ms tickover so we handle char change first
setTimeout(function(){top.ICEcoder.updateDiffs();},0);
}
// Update HTML edited files live
if (filepath && top.ICEcoder.previewWindow.location && filepath != "/[NEW]") {
top.ICEcoder.updatePreviewWindow(thisCM,filepath,filename,fileExt);
}
// Update the title tag to indicate any changes
top.ICEcoder.indicateChanges();
},
cMonUpdate: function(thisCM,cMinstance) {
// Update the minimap background to match theme
setTimeout(function() {
get('docExplorer').style.background = window.getComputedStyle(thisCM.getWrapperElement(),null).getPropertyValue('background');
},0);
// Set the Minimap layout
top.ICEcoder.setMinimapLayout(thisCM,cMinstance);
},
// On scroll
cMonScroll: function(thisCM,cMinstance) {
var cM, cMdiff, otherCM;
top.ICEcoder.mouseDown=false;
top.ICEcoder.mouseDownInCM=false;
if (top.ICEcoder.splitPane) {
// Get both main & diff instance and work out the instance we're not scrolling
cM = top.ICEcoder.getcMInstance();
cMdiff = top.ICEcoder.getcMdiffInstance();
otherCM = cMinstance.indexOf('diff') > -1 ? cM : cMdiff;
if (cM) {
// Scroll other pane x & y to match this one we're scrolling, after a 0ms tickover to avoid judder
setTimeout(function(){otherCM.scrollTo(thisCM.getScrollInfo().left, thisCM.getScrollInfo().top);},0);
}
}
// Set the Minimap layout
top.ICEcoder.setMinimapLayout(thisCM,cMinstance);
},
// On input read
cMonInputRead: function(thisCM,cMinstance) {
if (top.ICEcoder.autoComplete == "keypress" && top.ICEcoder.codeAssist) {
// Debounce timeout wrapper left here for now, but can be removed in future if no negative effects seen
// clearTimeout(top.ICEcoder.debounce);
if (!thisCM.state.completionActive) {
// top.ICEcoder.debounce = setTimeout(function() {
if (!top.ICEcoder.autocompleteSkip) {
top.ICEcoder.autocomplete();
} else {
top.ICEcoder.autocompleteSkip = false;
}
// },0);
}
}
},
// On gutter click
cMonGutterClick: function(thisCM,line,gutter,evt,cMinstance) {
top.ICEcoder.mouseDownInCM = "gutter";
},
// On mouse down
cMonMouseDown: function(thisCM,cMinstance) {
top.ICEcoder.mouseDownInCM = "editor";
},
// On drag over
cMonDragOver: function(thisCM,evt,cMinstance) {
top.ICEcoder.setDragCursor(evt,'editor');
},
// On render line
cMonRenderLine: function(thisCM,cMinstance,line,element) {
var paneMatch;
// Loop through styles to use when rendering lines
for (var i=0; i<top.ICEcoder.renderLineStyle.length; i++) {
// We have no matching pane to start with
paneMatch = false;
// Is the pane we need to style this pane?
if (
(top.ICEcoder.renderLineStyle[i][0] != "diff" && cMinstance.indexOf("diff") == -1) ||
(top.ICEcoder.renderLineStyle[i][0] == "diff" && cMinstance.indexOf("diff") > -1)
)
{paneMatch = true;}
// If the pane matches & also the line we're rendering is the line we have a style set for, set that style
if (paneMatch && thisCM.lineInfo(line).line+1 == top.ICEcoder.renderLineStyle[i][1]) {
element.style[top.ICEcoder.renderLineStyle[i][2]] = top.ICEcoder.renderLineStyle[i][3];
}
}
},
// Update diffs shown to the user in each pane
updateDiffs: function() {
var cM, cMdiff, mainText, diffText, sm, opcodes, cMmarks, cMdiffMarks, amt, sDiffs;
// Reset the style array container and main vs diff pane shift difference
top.ICEcoder.renderLineStyle = [];
top.ICEcoder.renderPaneShiftAmount = 0;
cM = top.ICEcoder.getcMInstance();
cMdiff = top.ICEcoder.getcMdiffInstance();
// Get the baseText and newText values from the two textboxes, and split them into lines
mainText = cM ? difflib.stringAsLines(cM.getValue()) : "";
diffText = cMdiff ? difflib.stringAsLines(cMdiff.getValue()) : "";
// Create a SequenceMatcher instance that diffs the two sets of lines
sm = new difflib.SequenceMatcher(mainText, diffText);
// Get the opcodes from the SequenceMatcher instance
// Opcodes is a list of 3-tuples describing what changes should be made to the base text in order to yield the new text
opcodes = sm.get_opcodes();
if (cM) {
// Clear all main pane marks
cMmarks = cM.getAllMarks();
for (var i=0; i<cMmarks.length; i++) {
cMmarks[i].clear();
}
// Clear all diff pane marks
cMdiffMarks = cMdiff.getAllMarks();
for (var i=0; i<cMdiffMarks.length; i++) {
cMdiffMarks[i].clear();
}
}
if (cM && cMdiff.getValue() != "") {
// For each opcode returned by jsdifflib
for (var i=0; i<opcodes.length; i++) {
// If not 'equal' status for the section, we have a 'replace', 'delete' or 'insert' status, so do something
if (opcodes[i][0] !== "equal") {
// =========
// MAIN PANE
// =========
// Replacing? Pad out main pane line to match equivalent last line in diff pane
if (opcodes[i][0] == "replace") {
// Line amount is diff between end of both panes at this point in our loop, plus 1 line and our overall document shift, multiplied by font size
amt = ((opcodes[i][4] - opcodes[i][2] + 1 + top.ICEcoder.renderPaneShiftAmount) * cM.defaultTextHeight());
// Add on the extra heights for any wrapped lines
for (var j=opcodes[i][4]-1; j<=opcodes[i][2]-1; j++) {
if (cMdiff.getLineHandle(j).height > cM.defaultTextHeight()) {
amt += cMdiff.getLineHandle(j).height - cM.defaultTextHeight();
}
}
// If we have an height greater than the default text height, add a new style
if (amt > cM.defaultTextHeight()) {
top.ICEcoder.renderLineStyle.push(["main", opcodes[i][2], "height", amt + "px"]);
}
// Mark text in 2 colours, for each line
for (var j=0; j<(opcodes[i][2]) - (opcodes[i][1]); j++) {
sDiffs = (top.ICEcoder.findStringDiffs(cM.getLine(opcodes[i][1]+j),cMdiff.getLine(opcodes[i][3]+j)));
cM.markText({line: opcodes[i][1]+j, ch: 0}, {line: opcodes[i][3]+j + top.ICEcoder.renderPaneShiftAmount, ch: sDiffs[0]}, {className: "diffGreyLighter"});
cM.markText({line: opcodes[i][1]+j, ch: sDiffs[0]}, {line: opcodes[i][3]+j + top.ICEcoder.renderPaneShiftAmount, ch: sDiffs[0]+sDiffs[1]}, {className: "diffGrey"});
cM.markText({line: opcodes[i][1]+j, ch: sDiffs[0]+sDiffs[1]}, {line: opcodes[i][3]+j + top.ICEcoder.renderPaneShiftAmount, ch: 1000000}, {className: "diffGreyLighter"});
}
// Inserting
} else {
cM.markText({line: opcodes[i][1], ch: 0}, {line: opcodes[i][2]-1, ch: 1000000}, {className: "diffGreen"});
}
// If inserting or deleting and the main pane hasn't changed, we need to pad out the line in that pane
if (opcodes[i][0] != "replace" && opcodes[i][1] == opcodes[i][2]) {
top.ICEcoder.renderLineStyle.push(["main", opcodes[i][2], "height", ((opcodes[i][4] - opcodes[i][3] + 1) * cM.defaultTextHeight()) + "px"]);
// Mark the range with empty class
cM.markText({line: opcodes[i][2]-1, ch: 0}, {line: opcodes[i][2]-1, ch: 1000000}, {className: "diffNone"});
}
// =========
// DIFF PANE
// =========
// Replacing? Pad out diff pane line to match equivalent last line in main pane
if (opcodes[i][0] == "replace") {
// Line amount is diff between end of both panes at this point in our loop, plus 1 line and our overall document shift, multiplied by font size
amt = ((opcodes[i][2] - opcodes[i][4] + 1 - top.ICEcoder.renderPaneShiftAmount) * cM.defaultTextHeight());
// Add on the extra heights for any wrapped lines
for (var j=opcodes[i][4]-1; j<=opcodes[i][2]-1; j++) {
if (cM.getLineHandle(j).height > cM.defaultTextHeight()) {
amt += cM.getLineHandle(j).height - cM.defaultTextHeight();
}
}
// If we have an height greater than the default text height, add a new style
if (amt > cM.defaultTextHeight()) {
top.ICEcoder.renderLineStyle.push(["diff", opcodes[i][4], "height", amt + "px"]);
}
// Mark text in 2 colours, for each line
for (var j=0; j<(opcodes[i][4]) - (opcodes[i][3]); j++) {
sDiffs = (top.ICEcoder.findStringDiffs(cM.getLine(opcodes[i][1]+j),cMdiff.getLine(opcodes[i][3]+j)));
cMdiff.markText({line: opcodes[i][1]+j - top.ICEcoder.renderPaneShiftAmount, ch: 0}, {line: opcodes[i][3]+j, ch: sDiffs[0]}, {className: "diffGreyLighter"});
cMdiff.markText({line: opcodes[i][1]+j - top.ICEcoder.renderPaneShiftAmount, ch: sDiffs[0]}, {line: opcodes[i][3]+j, ch: sDiffs[0]+sDiffs[2]}, {className: "diffGrey"});
cMdiff.markText({line: opcodes[i][1]+j - top.ICEcoder.renderPaneShiftAmount, ch: sDiffs[0]+sDiffs[2]}, {line: opcodes[i][3]+j, ch: 1000000}, {className: "diffGreyLighter"});
}
// Deleting
} else {
cMdiff.markText({line: opcodes[i][3], ch: 0}, {line: opcodes[i][4]-1, ch: 1000000}, {className: "diffRed"});
}
// If inserting or deleting and the diff pane hasn't changed, we need to pad out the line in that pane
if (opcodes[i][0] != "replace" && opcodes[i][3] == opcodes[i][4]) {
top.ICEcoder.renderLineStyle.push(["diff", opcodes[i][4], "height", ((opcodes[i][2] - opcodes[i][1] + 1) * cM.defaultTextHeight()) + "px"]);
// Mark the range with empty class
cMdiff.markText({line: opcodes[i][4]-1, ch: 0}, {line: opcodes[i][4]-1, ch: 1000000}, {className: "diffNone"});
}
// Finally, set the last amount shifted for this change
top.ICEcoder.renderPaneShiftAmount = (opcodes[i][2] - opcodes[i][4]);
}
}
}
},
// Find diffs between 2 strings
findStringDiffs: function(a, b) {
if ("undefined" == typeof a) {a = ""};
if ("undefined" == typeof b) {b = ""};
for (var c = 0, // start from the first character
d = a.length, e = b.length; // and from the last characters of both strings
a[c] && // if not at the end of the string and
a[c] == b[c]; // if both strings are equal at this position
c++); // go forward
for (; d > c & e > c & // stop at the position found by the first loop
a[d - 1] == b[e - 1]; // if both strings are equal at this position
d--) e--; // go backward
return[c, d - c, e - c] // return position and lengths of the two substrings found
},
// Update preview window content
updatePreviewWindow: function(thisCM,filepath,filename,fileExt) {
if (top.ICEcoder.previewWindow.location.pathname==filepath) {
if (["htm","html","txt"].indexOf(fileExt) > -1) {
top.ICEcoder.previewWindow.document.documentElement.innerHTML = thisCM.getValue();
} else if (["md"].indexOf(fileExt) > -1) {
top.ICEcoder.previewWindow.document.documentElement.innerHTML = mmd(thisCM.getValue());
}
} else if (["css"].indexOf(fileExt) > -1) {
if (top.ICEcoder.previewWindow.document.documentElement.innerHTML.indexOf(filename) > -1) {
var css = thisCM.getValue();
var style = document.createElement('style');
style.type = 'text/css';
style.id = "ICEcoder"+filepath.replace(/\//g,"_");
if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
if (top.ICEcoder.previewWindow.document.getElementById(style.id)) {
top.ICEcoder.previewWindow.document.documentElement.removeChild(top.ICEcoder.previewWindow.document.getElementById(style.id));
}
top.ICEcoder.previewWindow.document.documentElement.appendChild(style);
}
}
// Do the pesticide plugin if it exists
try {top.ICEcoder.doPesticide();} catch(err) {};
// Do the stats.js plugin if it exists
try {top.ICEcoder.doStatsJS('update');} catch(err) {};
// Do the responsive plugin if it exists
try {top.ICEcoder.doResponsive();} catch(err) {};
},
// Clean up our loaded code
contentCleanUp: function() {
var cM, cMdiff, thisCM, content;
// Replace any temp /textarea value
cM = ICEcoder.getcMInstance();
cMdiff = ICEcoder.getcMdiffInstance();
thisCM = top.ICEcoder.editorFocusInstance.indexOf('diff') > -1 ? cMdiff : cM;
content = thisCM.getValue();
content = content.replace(/<ICEcoder:\/:textarea>/g,'<\/textarea>');
// Then set the content in the editor & clear the history
thisCM.setValue(content);
thisCM.clearHistory();
top.ICEcoder.savedPoints[top.ICEcoder.selectedTab-1] = thisCM.changeGeneration();
top.ICEcoder.savedContents[top.ICEcoder.selectedTab-1] = thisCM.getValue();
},
// Undo last change
undo: function() {
var cM, cMdiff, thisCM;
cM = ICEcoder.getcMInstance();
cMdiff = ICEcoder.getcMdiffInstance();
thisCM = top.ICEcoder.editorFocusInstance.indexOf('diff') > -1 ? cMdiff : cM;
thisCM.undo();
},
// Redo change
redo: function() {
var cM, cMdiff, thisCM;
cM = ICEcoder.getcMInstance();
cMdiff = ICEcoder.getcMdiffInstance();
thisCM = top.ICEcoder.editorFocusInstance.indexOf('diff') > -1 ? cMdiff : cM;
thisCM.redo();
},
// Indent more/less
indent: function(moreLess) {
var cM, cMdiff, thisCM;
cM = ICEcoder.getcMInstance();
cMdiff = ICEcoder.getcMdiffInstance();
thisCM = top.ICEcoder.editorFocusInstance.indexOf('diff') > -1 ? cMdiff : cM;
if (moreLess=="more") {
top.ICEcoder.content.contentWindow.CodeMirror.commands.indentMore(thisCM);
} else {
top.ICEcoder.content.contentWindow.CodeMirror.commands.indentLess(thisCM);
}
},
// Move current line up/down
moveLines: function(dir) {
var cM, cMdiff, thisCM, lineStart, lineEnd, swapLineNo, swapLine;
cM = top.ICEcoder.getcMInstance();
cMdiff = top.ICEcoder.getcMdiffInstance();
thisCM = top.ICEcoder.editorFocusInstance.indexOf('diff') > -1 ? cMdiff : cM;
// Get start & end lines plus the line we'll swap with
lineStart = thisCM.getCursor('start');
lineEnd = thisCM.getCursor('end');
if (dir=="up" && lineStart.line>0) {swapLineNo = lineStart.line-1}
if (dir=="down" && lineEnd.line<thisCM.lineCount()-1) {swapLineNo = lineEnd.line+1}
// If we have a line to swap with
if (!isNaN(swapLineNo)) {
// Get the content of the swap line and carry out the swap in a single operation
swapLine = thisCM.getLine(swapLineNo);
thisCM.operation(function() {
// Move lines in turn up
if (dir=="up") {
for (var i=lineStart.line; i<=lineEnd.line; i++) {
thisCM.replaceRange(thisCM.getLine(i),{line:i-1,ch:0},{line:i-1,ch:1000000});
}
// ...or down
} else {
for (var i=lineEnd.line; i>=lineStart.line; i--) {
thisCM.replaceRange(thisCM.getLine(i),{line:i+1,ch:0},{line:i+1,ch:1000000});
}
}
// Now swap our final line with the swap line to complete the move
thisCM.replaceRange(swapLine,{line: dir=="up" ? lineEnd.line : lineStart.line, ch: 0},{line: dir=="up" ? lineEnd.line : lineStart.line, ch:1000000});
// Finally set the moved selection
thisCM.setSelection(
{line: lineStart.line+(dir=="up" ? -1 : 1), ch: lineStart.ch},
{line: lineEnd.line+(dir=="up" ? -1 : 1), ch: lineEnd.ch}
);
});
}
},
// Highlight specified line
highlightLine: function(line) {
var cM, cMdiff, thisCM;
cM = top.ICEcoder.getcMInstance();
cMdiff = top.ICEcoder.getcMdiffInstance();
thisCM = top.ICEcoder.editorFocusInstance.indexOf('diff') > -1 ? cMdiff : cM;
thisCM.setSelection({line:line,ch:0}, {line:line,ch:thisCM.lineInfo(line).text.length});
},
// Focus the editor
focus: function(diff) {
var cM, cMdiff, thisCM;
if (!(/iPhone|iPad|iPod/i.test(navigator.userAgent))) {
cM = top.ICEcoder.getcMInstance();
cMdiff = top.ICEcoder.getcMdiffInstance();
thisCM = diff ? cMdiff : cM;
if (thisCM) {
thisCM.focus();
}
}
},
// Go to a specific line number
goToLine: function(lineNo) {
var cM, cMdiff, thisCM;
lineNo = lineNo ? lineNo-1 : top.get('goToLineNo').value-1;
cM = ICEcoder.getcMInstance();
cMdiff = ICEcoder.getcMdiffInstance();
thisCM = top.ICEcoder.editorFocusInstance.indexOf('diff') > -1 ? cMdiff : cM;
top.ICEcoder.scrollingOnLine = thisCM.getCursor().line;
// Scroll cursor into middle of view
if ("undefined" != typeof top.ICEcoder.scrollInt) {
clearInterval(top.ICEcoder.scrollInt);
}
top.ICEcoder.scrollInt = setInterval(function() {
top.ICEcoder.scrollingOnLine = top.ICEcoder.scrollingOnLine+((lineNo-top.ICEcoder.scrollingOnLine)/5);
thisCM.scrollTo(0,(thisCM.defaultTextHeight()*top.ICEcoder.scrollingOnLine)-(thisCM.getScrollInfo().clientHeight/10));
top.ICEcoder.setMinimapLayout(thisCM);
if (Math.round(top.ICEcoder.scrollingOnLine) == lineNo) {
clearInterval(top.ICEcoder.scrollInt);
}
},10);
thisCM.setCursor(lineNo);
top.ICEcoder.focus();
// Also do this after a 0ms tickover incase DOM wasn't ready
setTimeout(function(){top.ICEcoder.focus();},0);
return false;
},
// Comment/uncomment line or selected range on keypress
lineCommentToggle: function() {
var cM, cMdiff, thisCM, cursorPos, linePos, lineContent, lCLen;
cM = ICEcoder.getcMInstance();
cMdiff = ICEcoder.getcMdiffInstance();
thisCM = top.ICEcoder.editorFocusInstance.indexOf('diff') > -1 ? cMdiff : cM;
cursorPos = thisCM.getCursor().ch;
linePos = thisCM.getCursor().line;
lineContent = thisCM.getLine(linePos);
lCLen = lineContent.length;
ICEcoder.lineCommentToggleSub(thisCM, cursorPos, linePos, lineContent, lCLen);
},