-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
87 lines (71 loc) · 2.36 KB
/
index.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
<!doctype html>
<html>
<head>
<title></title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
html{ height:100%; }
body { font: 13px Helvetica, Arial; height:100%;}
#selection{ height:100%; width:100%;}
</style>
<script type="text/javascript" src="/ace-builds/src-min/ace.js"></script>
<script src="/socket.io/socket.io.js"></script>
</head>
<body>
<div id="selection"></div>
<script>
function doSelection( options ) {
var doc = editor.getSession().getDocument();
var lines = doc.getAllLines();
var offsetToPos = function( offset ) {
var row = 0, col = 0;
var pos = 0;
while ( row < lines.length && pos + lines[row].length < offset) {
pos += lines[row].length;
pos++; // for the newline
row++;
}
col = offset - pos;
return {row: row, column: col};
}
var start = offsetToPos( options.start ),
end = offsetToPos( options.end );
var sel = editor.getSelection();
var range = sel.getRange();
range.setStart( start.row, start.column );
range.setEnd( end.row, end.column );
sel.setSelectionRange( range );
}
var socket = io();
var currentSelection = null;
socket.on('msg', function(msg){
if( typeof msg == "string"){
var data = JSON.parse(msg);
if(data.action == 'select'){
document.title = data.file;
var sel = editor.getSelection();
currentSelection = data.selection;
doSelection(data.selection);
} else if( data.action == "changefile" ){
editor.setValue(data.data);
} else if( data.action == "update" ){
editor.setValue(data.data);
if(currentSelection!=null){
doSelection(currentSelection);
}
}
} else {
console.log('not a string');
}
});
socket.on('file', function (msg) {
console.log("file", msg);
});
var editor = ace.edit("selection");
editor.renderer.setShowGutter(false);
editor.setTheme("ace/theme/monokai");
editor.setReadOnly(true);
editor.getSession().setMode("ace/mode/javascript");
</script>
</body>
</html>