-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscript.js
104 lines (103 loc) · 2.82 KB
/
script.js
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
var point=0,line=1,isChar=false;isControl=false; isAlt=false; command = "", cursor=String.fromCharCode(9611);
function stopDefault( e ) {
// Prevent the default browser action (W3C)
if ( e && e.preventDefault )
e.preventDefault();
// A shortcut for stoping the browser action in IE
else
window.event.returnValue = false;
return false;
}
$(document).ready(function() {
$('.buffer').css('height',function() {
return $(window).height()-70;
});
$(window).resize(function() {
$('.buffer').css('height',function() {
return $(window).height()-70;
});
});
$('.buffer')[0].innerText = $('.buffer')[0].innerText+cursor; // Acknowledge content and add Cursor
point=$('.buffer')[0].innerText.length -1;// Find the Length of the whole preexisting content and set it to point
$(window).keypress(function(e) {
ch = e.keyCode;
if(isControl) {
return;
}
$('.buffer')[0].innerText = $('.buffer')[0].innerText.substr(0,point) + $('.buffer')[0].innerText.substr(point+1); // Removes the Cursor character
$('.buffer')[0].innerText = $('.buffer')[0].innerText+String.fromCharCode(ch);
$('.buffer')[0].innerText = $('.buffer')[0].innerText+String.fromCharCode(9611); //Adds the Cursor index character after edit.
$("#minibuffer").html("");
point++;
isChar=false;
});
$(window).keydown(function(e) {
ch = e.keyCode;//alert(ch);
switch(ch) {
case 17:
isControl = true;
return;
break;
};
if(isControl) {
//alert('hi');
stopDefault(e);
e.cancelBubble = true;
if(e.stopPropagation)
e.stopPropagation();
return;
}
if(ch==8) {//backspace
if(point==0) return;
$('.buffer')[0].innerText = $('.buffer')[0].innerText.substr(0,point-1) + $('.buffer')[0].innerText.substr(point);
$("#minibuffer").html("");
point--;
return;
}
if(ch==46) {//delete key
spos=point+1;
if(point==0) return;
$('.buffer').html($('.buffer').html().substr(0,spos)+$('.buffer').html().substr(spos+1));
$("#minibuffer").html("");
point-=point-spos;
return;
}
if(ch==32) {
// $('.buffer').html($('.buffer').html()+' ');
//point+=6;
}
});
$(window).keyup(function(e) {
ch = e.keyCode;//alert(ch);
switch(ch) {
case 17:
//alert(command);
execute(command);
command = "";
isControl = false;
break;
};
if(isControl) {
command += "C-"+String.fromCharCode(ch)+' ';
execute(command);
$("#minibuffer").html(command);
if(ch==71)//G for C-G
$("#minibuffer").html("Quit");
return;
}
});
window.onkeydown=function(e) {
//alert(e.keyCode);
if(isControl) {
stopDefault(e);
e.cancelBubble = true;
if(e.stopPropagation)
e.stopPropagation();
return;
}
//stopDefault(e);
};
window.onfocus = function() {
isControl=false; isAlt=false;
};
});