-
Notifications
You must be signed in to change notification settings - Fork 1
/
code colorer OLD.html
2049 lines (1713 loc) · 59.6 KB
/
code colorer OLD.html
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Code Colorer</title>
<!--
-->
<link rel="stylesheet" href="code%20colorer.css" type="text/css" />
<style>
#coloredCodeContainer
{
position: relative;
white-space: pre-wrap;
font-family: monaco;
font-size: 7pt;
epadding: 1em;
}
#coloredCode
{
outline: none;
position: relative;
z-index: 20;
}
/*
*
* Dump styles
*
*/
td
{
vertical-align: top;
}
.selectedLine
{
position: absolute;
width: 100%;
ebackground-color: red;
border: solid 1px #fc8;
border-left: 0;
border-right: 0;
margin-top: -2px;
background: -webkit-gradient(linear, left top, left bottom, from(#fec), to(#fda));
}
.selectedLinePosition
{
position: absolute;
right: 0;
bottom: 0;
text-align: right;
color: #f80;
vertical-align: bottom;
margin-right: 4px;
efont-size: 70%;
}
.selectionDump
{
width: 350px;
}
.selectionDump, .selectionDump td
{
border: solid 1px #aaa;
}
.selectionDump .header
{
font-weight: bold;
}
#undoStackDump
{
color: #8c0;
}
.newline
{
/* cursor won't land an empty lines with white-space: normal */
/* but if normal, shift-selecting up stops on newline */
/* inline-block works OK */
white-space: normal;
}
.newline-blank
{
white-space: pre;
/* border: solid 1px red; */
}
.fakeTab
{
ewhite-space: normal;
edisplay: inline-block;
epadding-right: 20px;
emargin-right: 20px;
eborder: solid 1px red;
eletter-spacing: -4px;
eletter-spacing: -0.5em;
eletter-spacing: -0.5pt;
epadding-right: 40px;
emargin-right: -20px;
ebackground: -webkit-gradient(linear, left top, right top, from(#f44), to(#fcc));
background: -webkit-gradient(linear, left top, right top, from(rgba(220, 245, 200, 0.81)), to(rgba(100, 255, 100, 0.81)));
}
</style>
</head>
<body>
<ul><li>REMOVE STYLESHEET
<li>make an automated undo tester : random commands (including undo/redo) + consistency test : replay to initial state, then back to final
</ul>
<table border='1' style='table-layout: fixed; width: 100%; height: 800px; height: 650px' cellPadding='0' cellSpacing='0'><tr>
<td>
<div id='coloredCodeContainer'><div id='coloredCode'></div></div>
</td>
<td style='width: 300px'>
<div id='birdView'></div>
<hr>
<div id='birdViewDump'>LOG ALL COMMANDS HERE. typing (typing count, line extent + sel) + move + undo/redo</div>
<hr>
<div id='selectionDump'>SELECTION DUMP</div>
<div id='undoStackDump'>UNDO DUMP</div>
<button onclick='undo()'>undo</button>
<button onclick='redo()'>redo</button>
<button onclick='dumpUndoStack()'>dump undo</button>
</td>
</tr></table>
<textarea style='display: none'>
2 3 4
5 6 7
1 * +
abcd****1234+
4 2 +
abcd****1234+
1 2 3 +
abcd****1234+
12 34 56 +
abcd****1234+
123 456 789 +
3 +
+ +
1 + * +
12 + * +
123 + * +
1234 + +
12345 + +
123456 + +
1234567 + +
12345678 +
</textarea>
// List launched applications
var apps = [[NSWorkspace sharedWorkspace] launchedApplications]
for (var i=0; i<apps.length; i++)
// option-right from next EOL
log(apps[i].NSApplicationName)
// Instead of using alloc/init and releasing ...
var url = [[NSURL alloc] initFileURLWithPath:"/tmp" isDirectory:true]
[url release]
// Replace 'init' in the method name with 'instance' to get an object managed by JavascriptCore
var url = [NSURL instanceFileURLWithPath:"/tmp" isDirectory:true]
// Mark object as collectable
url = null
// Mix and match ObjJ and Javascript syntax
var a = [NSArray arrayWithObjects:'hello', [7, 8, 9], 'world']
log('a[1][2]=' + [[a objectAtIndex:1] objectAtIndex:2])
log('a[1][1]=' + [a[1] objectAtIndex:1])
log('a[1][0]=' + a[1][0])
// Syntactic sugar for selector notation
var o = [SomeObject instance]
[o performSelector:@selector(doStuff:) withObject:anObject afterDelay:500]
//
// Define a Cocoa class in Javascript
// It can then be used from Javascript or Cocoa (use it as a delegate class, create a new NSView, ...)
//
class MyObject < NSObject
{
// Find objects containing at least one capital letter
- (NSArray*)findObjectsInArray:(NSArray*)array
{
return array.filter(function (elt) { return elt.match(/[A-Z]/) })
}
// Use radix = 16 to parse hex
// Use radix = 36 to parse a Reddit story number
- (NSNumber*)parseNumberInString:(NSString*)str withRadix:(int)radix
{
return parseInt(str, radix)
}
// NSApplication delegate method
- (void)applicationWillBecomeActive:(NSNotification *)notification
{
log('Hello ! ' + notification.name)
}
}
// Instance our new class
var obj = [MyObject instance]
log([obj parseNumberInString:'9q5vm' withRadix:'36'])
// Register it as application delegate
[NSApplication sharedApplication].delegate = obj
//
// Swizzle a method from an existing class
//
class NSButton
{
swizzle - (void)drawRect:(NSRect)rect
{
// Call original method
this.Original(arguments)
log('drawRect: called on button ' + this)
}
}
</textarea>
<pre id='dump'></pre>
<table style='table-layout: fixed; width: 100%'><tr><td style='width: 480px'>
<tr><td>
<pre id='dump2'></pre>
<td>
<pre id='dump3'></pre>
<pre id='dump4'></pre>
</tr></table>
<button onclick="clearDumps()">Clear</button>
<pre id='dump5'></pre>
<pre id='dump6'></pre>
<script src="crockford/json2.js"></script>
<script src="crockford/jslint-jscocoa.js"></script>
<script src='showdown.js'></script>
<script>
var MarkDownConverter = new Showdown.converter()
function htmlEncode(str)
{
// return str
return str.replace(/</g, '<')
return str.replace(/</g, '<')
return str.replace(/</g, '<')
}
function getTickCount()
{
return (new Date).getTime()
}
function dumpHash(o)
{
var str = ''
for (var i in o) str += i + '=' + (o[i]) + '\n'
return str
}
function dumpHashNoFunction(o)
{
var str = ''
for (var i in o) { if (typeof o[i] == 'function') continue; str += i + '=' + (o[i].toString == 'toStringToken' in this ? ('*TOKEN*'+o[i].value + '*') : o[i]) + '\n' }
return str
}
function newNodeAsChildOf(node, tagName)
{
var n2 = document.createElement(tagName||'DIV')
node.appendChild(n2)
return n2
}
// Walkers
function nextNode(n)
{
if (n.firstChild) return n.firstChild
while (n)
{
if (n.nextSibling) return n.nextSibling
n = n.parentNode
}
return null
}
function previousNode(n)
{
if (n.previousSibling)
{
n = n.previousSibling
while (n && n.lastChild)
n = n.lastChild
return n
}
n = n.parentNode
return n
}
//
// Code colorer class
//
function CodeColorer(editorNode, containerNode, birdViewNode)
{
this.initWithNodes(editorNode, containerNode, birdViewNode)
}
var CCp = CodeColorer.prototype
CCp.initWithNodes = function (editorNode, containerNode, birdViewNode)
{
this.editorNode = editorNode
this.birdViewNode = birdViewNode
this.containerNode = containerNode
/*
><div id='bubbleContainer'></div><div id='lineNumbers'></div><div id='selectedLine'><div id='selectedLinePosition'></div></div><div id='highlightedContainer'><div id='tracesContainer'></div><div id='whiteSpaceRevealer'></div>
*/
this.editorNode.contentEditable = true
this.bubbleContainer = newNodeAsChildOf(this.containerNode)
this.lineNumbers = newNodeAsChildOf(this.containerNode)
this.selectedLine = newNodeAsChildOf(this.containerNode)
this.selectedLinePosition = newNodeAsChildOf(this.selectedLine)
this.tracesContainer = newNodeAsChildOf(this.containerNode)
this.whiteSpaceRevealer = newNodeAsChildOf(this.containerNode)
this.selectedLine.className = 'selectedLine'
this.selectedLinePosition.className = 'selectedLinePosition'
// Measure width of one character
this.charWidthMeasurer = newNodeAsChildOf(this.containerNode)
this.selectionStack = []
this.undoStack = []
this.redoStack = []
// Create lint and register our logs
var logNames = ['logToken', 'logExtraSyntax']
var logs = {}
var self = this
for (var i=0; i<logNames.length; i++) {
var name = logNames[i]
// Close name
logs[name] = function (name) { return function () { return self[name].apply(self, arguments) } }(name)
}
this.JSLINT = JSLintWithLogs(logs)
this.jslint = this.JSLINT()
// Events
var self = this
this.editorNode.onkeydown = function () { return self.keydown.apply(self, arguments) }
this.editorNode.oncopy = function () { return self.copy.apply(self, arguments) }
this.editorNode.oncut = function () { return self.cut.apply(self, arguments) }
this.editorNode.onpaste = function () { return self.paste.apply(self, arguments) }
this.editorNode.onmousedown = function () { return self.mousedown.apply(self, arguments) }
this.postKeydownEventFunction = function () { return self.postKeydown.apply(self, arguments) }
}
//
// Helpers
//
CCp.warn = function (str)
{
document.getElementById('dump3').innerHTML = getTickCount() + '<br>' + '<span style="color: red">' + str + '</span>'
}
CCp.dumpLintErrors = function (errors)
{
var str = ''
for (var i=0; i<errors.length; i++)
if (errors[i]) str += '(' + errors[i].line + ',' + errors[i].character + ')=' + errors[i].reason + '\n'
return str
}
CCp.toString = function () {
return 'CodeColorer'
}
//
// Text loading
//
CCp.loadText = function (text)
{
// Should remove \r
var lines = text.split('\n')
this.loadLines(lines)
}
CCp.loadLines = function (lines)
{
this.measureCharWidth()
var src = []
if (lines.length == 0) lines = ['']
for (var i=0; i<lines.length; i++)
{
var l = lines[i]
l = this.replaceTabsInLine(l)
l = '<div class="line">' + l + '\n</div>'
src.push(l)
}
this.editorNode.innerHTML = src.join('')
}
CCp.lineCount = function()
{
return this.editorNode.childNodes.length
}
CCp.rawText = function ()
{
return this.editorNode.innerText
}
CCp.measureCharWidth = function ()
{
var str = '<span>*</span><br/>'
this.charWidthMeasurer.innerHTML = str
this.charWidth = this.charWidthMeasurer.firstChild.offsetWidth
this.charTabWidths = {}
/*
this.charTabWidths = {}
var style = 'letter-spacing: -' + (this.charWidth-1) + 'px'
// alert('measure=' + style)
for (var i=0; i<=8; i++)
{
var str = ''
for (var j=0; j<i; j++) str += '*'
str += '<span class="fakeTab" style="' + style + '"> </span>'
this.charWidthMeasurer.innerHTML = str
var tabWidth = this.charWidthMeasurer.lastChild.offsetWidth
this.charTabWidths[8-i] = tabWidth
// alert('html=' + this.charWidthMeasurer.innerHTML + '\ntab character length=' + i + '\ntab pixel width=' + tabWidth + '\ncharWidth=' + this.charWidth)
}
// alert(dumpHash(this.charTabWidths))
// alert(this.charWidth)
*/
}
CCp.sourceFromLine = function(line)
{
if (typeof line == 'number')
line = this.lineNodeFromLineNumber(line)
var t = line.innerText
// When suppr-ing text from the end of line, Safari might delete newline - readd it
if (!t.match(/\n/)) t += '\n'
// if (line.lastChild && line.lastChild.className == 'newline') t += '\n'
return t
}
//
// Line and offset computation
//
CCp.lineNodeFromNode = function (node)
{
while (node)
{
if (node.nodeType == 1 && node.className.match(/\bline\b/))
return node
node = node.parentNode
}
return node
}
CCp.lineNumberFromNode = function (node)
{
node = this.lineNodeFromNode(node)
if (!node) return
var i = 0
node = node.previousSibling
while (node)
{
i++
node = node.previousSibling
}
return i
}
CCp.lineNodeFromLineNumber = function (i)
{
return this.editorNode.childNodes[i]
}
// Given a relative (node, offset), return an absolute offset in the matching line
CCp.lineAndOffsetFromNodeAndOffset = function (node, offset)
{
var n = node
var offset2 = offset, lineNumber = this.lineNumberFromNode(n)
if (n.className != 'line')
{
n = previousNode(n)
while (n && n.className != 'line')
{
if (n.nodeType == 3) offset2 += n.nodeValue.length
n = previousNode(n)
}
}
return { line : lineNumber, offset : offset2, isDiv : node.className == 'line' && offset == 0 }
}
// Given an absolute (line, offset), return an inner line node and offset
CCp.nodeAndOffsetFromLineAndOffset = function (line, offset, isDiv)
{
var lineNode = this.lineNodeFromLineNumber(line)
if (isDiv && offset == 0) return { node : lineNode, offset : offset }
var currentOffset = 0
var n = nextNode(lineNode)
while (n && n.className != 'line')
{
if (n.nodeType == 3)
{
var t = n.nodeValue
if (currentOffset + t.length >= offset)
return { node : n, offset : offset-currentOffset }
else
currentOffset += t.length
}
n = nextNode(n)
}
return { node : null, offset : undefined }
}
//
// Selection handling
//
CCp.rawSelection = function ()
{
var sel = getSelection()
return sel.getRangeAt(0)
}
CCp.setRawSelection = function (r)
{
var sel = getSelection()
sel.removeAllRanges()
sel.addRange(r)
}
CCp.selectionAsLineAndOffset = function ()
{
var sel = getSelection()
var raw = this.rawSelection()
sel.modify('extend', 'left', 'paragraphboundary')
var selectionText = sel.toString()
var length = selectionText.length
var range = sel.getRangeAt(0)
var h = { type : 'Caret', line : this.lineNumberFromNode(sel.baseNode), offset : length }
this.setRawSelection(raw)
return h
}
CCp.setSelectionAsLineAndOffset = function (line, offset)
{
var line = this.lineNodeFromLineNumber(line)
var sel = getSelection()
sel.setPosition(line, 0)
for (var i=0; i<offset; i++)
sel.modify('move', 'right', 'character')
}
CCp.setRangeSelectionAsLinesAndOffsets = function (line1, offset1, line2, offset2)
{
var sel = getSelection()
this.setSelectionAsLineAndOffset(line1, offset1)
var baseNode = sel.baseNode
var baseOffset = sel.baseOffset
this.setSelectionAsLineAndOffset(line2, offset2)
var extentNode = sel.extentNode
var extentOffset= sel.extentOffset
sel.setBaseAndExtent(baseNode, baseOffset, extentNode, extentOffset)
}
// Return the current range selection as
// {
// base : { line, offset }
// ,extent : { line, offset }
// }
CCp.rangeSelectionAsLineAndOffset = function()
{
var sel = getSelection()
var names = ['anchor', 'extent', 'focus', 'base']
var base = { line : 999999999, offset : 999999999 }
var extent = { line : -1, offset : -1 }
for (var i=0; i<names.length; i++)
{
var name = names[i]
var s = this.lineAndOffsetFromNodeAndOffset(sel[name + 'Node'], sel[name + 'Offset'])
if (s.line < base.line) base = s
if (s.line == base.line && s.offset < base.offset) base = s
if (s.line > extent.line) extent = s
if (s.line == extent.line && s.offset > extent.offset) extent = s
}
return { base : base, extent : extent }
}
CCp.pushCaretSelection = function()
{
this.selectionStack.push(this.selectionAsLineAndOffset())
}
CCp.popCaretSelection = function()
{
var s = this.selectionStack.pop()
this.setSelectionAsLineAndOffset(s.line, s.offset)
}
CCp.pushRangeSelection = function()
{
this.selectionStack.push(this.rangeSelectionAsLineAndOffset())
}
CCp.popRangeSelection = function()
{
var s = this.selectionStack.pop()
this.setRangeSelectionAsLinesAndOffsets(s.base.line, s.base.offset, s.extent.line, s.extent.offset)
}
CCp.caretSelectionOnStack = function()
{
if (!this.selectionStack.length) return
return this.selectionStack[this.selectionStack.length-1]
}
CCp.pushSelection = function ()
{
this.pushCaretSelection()
}
CCp.popSelection = function ()
{
this.popCaretSelection()
}
CCp.pushSelection2 = function ()
{
}
CCp.popSelection2 = function ()
{
}
// Return position - offset differs from selection offset, as tabs will count for 1 to 4 chars
CCp.textPositionAsLineAndOffset = function ()
{
var sel = getSelection()
var s = this.selectionAsLineAndOffset()
var line = this.lineNodeFromNode(sel.baseNode)
var str = this.sourceFromLine(line).substr(0, s.offset)
var o = {}
this.replaceTabsInLine(str, null, null, o)
return { line : s.line, offset : o.totalWidth }
}
CCp.gatherLinesToLint = function ()
{
var lines = []
var f = this.editorNode.firstChild
while (f)
{
var text = this.sourceFromLine(f)
lines.push(text)
f = f.nextSibling
}
return lines
}
CCp.lintLines = function (lines)
{
var options = { forin : true, laxbreak : true, indent : true }
//### FIX INSTANCE VARS
this.tokensByLine = {}
this.functionLines = []
// this.traceTokens = []
var res = this.jslint(lines, options)
return { tokens : this.tokensByLine, res : !!res, functionLines : this.functionLines, errors : this.JSLINT.errors }
}
//
// Color code
//
CCp.colorCode = function ()
{
// return
// this.measureCharWidth()
var lines = this.gatherLinesToLint()
var lint = this.lintLines(lines.join(''))
if (!lint.res)
{
this.warn('Lint error dump ... ' + getTickCount() + '\n' + this.dumpLintErrors(lint.errors))
}
else
{
document.getElementById('dump3').innerHTML = getTickCount() + ' <span style="color: lime; font-weight: bold">OK</span>'
}
//
// Color
//
this.pushSelection()
var f = this.editorNode.firstChild
var i = 0
while (f)
{
var tokens = lint.tokens[i]
if (!tokens) tokens = []
var line = lines[i]
this.writeTokensToLine(f, tokens, line, i)
f = f.nextSibling
i++
}
this.popSelection()
}
//
//
// Write functions
//
//
// Replace tabs switched methods ...
// fully deleting the tab with letter-spacing messes up caret AND selection indices when selecting a range (yields a baseOffset of 1 when a full line is selected)
CCp.replaceTabsInLine = function (line, html, customReplaceFunction, o)
{
if (!html) html = htmlEncode(line)
var tabWidths = []
var tabWidths8 = []
function countTabs(str, idx)
{
var length = (idx+deltaTabPosition) % tabWidth
length = tabWidth - length
// Add spaces to position (minus one to 'remove' the tab)
deltaTabPosition += length-1
tabWidths.push(length)
var length8 = (idx+deltaTabPosition8) % 8
length8 = 8 - length8
// Add spaces to position (minus one to 'remove' the tab)
deltaTabPosition8 += length8-1
tabWidths8.push(length8)
}
var tabIndex = 0
var charWidth = this.charWidth
var charTabWidths = this.charTabWidths
function replaceTabs(str, idx)
{
// A tab is surrounded by a SPAN nulling its width (with negative letter-spacing) and padding it to the correct 4-size with charWidth (measured in charWidthMeasurer)
totalWidth += tabWidths[tabIndex]
// alert(tabWidths[tabIndex] + '\n' + tabWidths8[tabIndex])
var w1 = charWidth
var w2 = tabWidths[tabIndex]*charWidth
var w = tabWidths[tabIndex]*charWidth
var p = w
var ls = charWidth
//alert(tabWidths8[tabIndex] + '\n\n*****\n' + dumpHash(charTabWidths))
var p = tabWidths[tabIndex]*charWidth-charTabWidths[tabWidths8[tabIndex]]
var ls = (charWidth-1)
p = tabWidths[tabIndex]*charWidth-3
// p = 21
//alert('letterspacing=' + ls + '\ntab width 4=' + tabWidths[tabIndex] + '\ntab character count=' + tabWidths8[tabIndex] + '\ntab pixel width=' + charTabWidths[tabWidths8[tabIndex]] + '\np=' + p + '\n\ncharTabWidths=\n' + dumpHash(charTabWidths))
//alert(tabWidths8[tabIndex] + '\n*\n' + charTabWidths[tabWidths8[tabIndex]] + '\n*\n' + dumpHash(charTabWidths))
var style = 'letter-spacing: -' + ls + 'px; padding-right: ' + p + 'px'
style = ' display: inline-block'
//ls = charWidth
//p = 0
// var style = 'letter-spacing: -' + ls + 'px; margin-right: -' + (p) + 'px'
// var style = 'letter-spacing: -' + charWidth + 'px; emargin-right: -' + (p) + 'px'
// style = ''
// alert(style)
// var style = 'letter-spacing: -' + ls + 'px; margin-right: -' + (charTabWidths[tabWidths8[tabIndex]]) + 'px'
//var mr = -charTabWidths[tabWidths8[tabIndex]]
//style = 'margin-right: ' + mr + 'px'
tabIndex++
//style = ''
//style = 'letter-spacing: -' + charWidth + 'px'
//alert(style)
style = 'display: inline-block'
style = 'white-space: normal; eborder-top: solid 1px red; padding-right: ' + w2 + 'px; '
style = 'white-space: normal; letter-spacing: ' + w2 + 'px; border-left: solid 3px red; edisplay: inline-block'
style = ''
style = 'display: inline-table; width: 20px'
style = 'display: -webkit-inline-box; width: ' + w + 'px'
style = 'display: inline-block; width: ' + w + 'px; eheight: 7px; overflow: hidden'
/*
-webkit-box-align: alignment;
baseline
Elements are aligned with the baseline of the box.
center
Elements are aligned with the center of the box.
end
Elements are aligned with the end of the box.
start
Elements are aligned with the start of the box.
stretch
Elements are stretched to fill the box.
*/
//alert(style)
//style='white-space: normal; margin-right: 10px'
style = ''
style = 'display: -webkit-inline-box; width: ' + w + 'px'
return '<span class="fakeTab" style="' + style + '"> </span>'
return '<span class="fakeTab" style="letter-spacing: -' + w1 + 'px; padding-right: ' + w2 + 'px"> </span>'
// w1 = 0
// w2 = 100
// return '<span class="fakeTab" style="eletter-spacing: ' + w1 + 'px; padding-right: ' + w2 + 'px; white-space:normal; border: solid 1px red"> </span>'
}
var tabWidth = this.tabWidth()
var deltaTabPosition = 0
var deltaTabPosition8 = 0
// Count tabs
line.replace(/\t/g, countTabs)
// Total character width of line (counting a full tab as tabWidth())
var totalWidth = line.length - tabWidths.length
// Replace tabs
html = html.replace(/\t/g, customReplaceFunction ? function () { return customReplaceFunction(tabWidths[tabIndex++]) } : replaceTabs)
//alert(html)
// Output totalWidth
if (o) o.totalWidth = totalWidth
return html
}
CCp.tabWidth = function ()
{
return 4
}
CCp.writeTokensToLine = function (node, tokens, line, lineNumber)
{
var i = 0
var lastIndex = 0
var str = ''
while (tokens[i])
{
var token = tokens[i]
// Skip endline
if (token.id == '(endline)')
{
i++
continue
}
if (token.rawValue && token.from > lastIndex)
{
var space = line.substr(lastIndex, token.from-lastIndex)
str += htmlEncode(space)
}
var c = ''
var v = token.value
v = line.substr(token.from, token.character-token.from)
if (token.identifier) c = 'identifier-' + token.value
if (token.reserved) c = 'keyword'
if (token.id && !token.reserved)
{
c = 'exps'
}
if (token.type == '(number)') c = 'number'
if (token.type == '(string)')
{
c = 'string'
}
if (token.type == '(comment)')
{
c = 'comment'
// alert(line + '*\ncharacter=' + token.character + '\nline.length=' + line.length + '\nv=' + v + '*')
// Single line markdown comment
// if (v.match(/^\/\/md/))
// {
// v = v.replace(/^\/\/md\s?/, '')
// v = MarkDownConverter.makeHtml(v)
// v = '<span class="markdown-singleline-container"><span class="markdown-singleline">' + v + '</span></span>'
// printEndLine = false
// }
}
if (token.isObjCCall)
{
c += ' objcCall'
if (!token.isObjCCallOpener && !token.isObjCCallCloser && !token.isObjCFirstCall)
c+= ' objcCallSelector'
if (token.isObjCCallOpener || token.isObjCCallCloser)
c += ' objcCallBracket'
}
v = htmlEncode(v)
str += '<span class="' + c + '">' + v + '</span>'
lastIndex = token.character
i++
}
// Copy end of line
if (lastIndex < line.length)
{
var space = line.substr(lastIndex)
str += htmlEncode(space)
}
// TABS ! sized to any size you want.
str = this.replaceTabsInLine(line, str)
// if (lineNumber == 1) alert(line.length + ' ' + (line == '\n'))
if (line == '\n') str = str.replace(/\n/, '<span class="newline-blank">\n</span>')
else str = str.replace(/\n/, '<span class="newline">\n</span>')
// str = str.replace(/\n/, String.fromCharCode(0x200b))
// str = str.replace(/\n/, String.fromCharCode(0x0001))
// str = str.replace(/\n/, String.fromCharCode(0x0001))
node.innerHTML = str
}
//
// Logs
//
CCp.logToken = function (token)
{
/*
var el = token.id == '(endline)' ? '\n' : ''
var id = token.id ? ('<span style="color: blue">(<b>' + token.id + '</b>)</span> ') : ''
document.getElementById('dump2').innerHTML += token.value + id + el
*/
// if (this.lines[token.line]) token.rawValue = lines[token.line].substr(token.from, token.character-token.from)
// else token.rawValue = ''
// alert('handle rawvalue'), eaz()
var line = token.line
if (!this.tokensByLine[line]) this.tokensByLine[line] = []
this.tokensByLine[line].push(token)
}
CCp.logExtraSyntax = function (syntaxName, token)
{
// alert(syntaxName)
}
CCp.mousedown = function()
{
var self = this
function h()
{
self.highlightSelectedLine()
}
setTimeout(h, 0)
this.closeUndoAction()
}
//
// Undo
//
CCp.newUndoAction = function ()
{