-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSVIM.js
88 lines (83 loc) · 2.87 KB
/
JSVIM.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
// Generated by CoffeeScript 1.3.3
(function() {
window.VIMEditorDefaults = {
cursorColor: 'black',
cursorWidth: 9,
cursorHeight: 18,
cursorLeft: 0,
cursorTop: 0
};
window.VIMEditorActions = {
keypressHandler: function(e) {
var content, keyCodeStr;
e = e || window.event;
console.log(e.keyCode);
keyCodeStr = String.fromCharCode(e.keyCode);
switch (keyCodeStr) {
case "k":
return (function() {
var cursorTopMargin;
VIMEditorDefaults.cursorTop -= VIMEditorDefaults.cursorTop === 0 ? 0 : 1;
cursorTopMargin = VIMEditorDefaults.cursorTop * VIMEditorDefaults.cursorHeight;
return $('#cursor').css('marginTop', cursorTopMargin);
})();
case "j":
return (function() {
var cursorTopMargin;
VIMEditorDefaults.cursorTop += 1;
cursorTopMargin = VIMEditorDefaults.cursorTop * VIMEditorDefaults.cursorHeight;
return $('#cursor').css('marginTop', cursorTopMargin);
})();
case "l":
return (function() {
var cursorLeftMargin;
VIMEditorDefaults.cursorLeft += 1;
cursorLeftMargin = VIMEditorDefaults.cursorLeft * VIMEditorDefaults.cursorWidth;
return $('#cursor').css('marginLeft', cursorLeftMargin);
})();
case "h":
return (function() {
var cursorLeftMargin;
VIMEditorDefaults.cursorLeft -= VIMEditorDefaults.cursorLeft === 0 ? 0 : 1;
cursorLeftMargin = VIMEditorDefaults.cursorLeft * VIMEditorDefaults.cursorWidth;
return $('#cursor').css('marginLeft', cursorLeftMargin);
})();
case "x":
return (function() {
var content;
content = $('#vimEditor-content').html();
content = content.split('');
content.splice((VIMEditorDefaults.cursorLeft === 0 ? 0 : VIMEditorDefaults.cursorLeft - 1), 1);
return $('#vimEditor-content').html(content.join(''));
})();
case "esc":
return (function() {
return console.log('ESC');
})();
case "i":
case "":
return (function() {
VIMEditor.mode = 'insert';
return $('#cursor').width('2px');
})();
default:
content = $('#vimEditor-content').html();
content = content.split('');
content.splice(VIMEditorDefaults.cursorLeft - 1, 0, keyCodeStr);
return $('#vimEditor-content').html(content.join(''));
}
}
};
window.VIMEditor = {
init: (function() {
setInterval((function() {
return $('#cursor').toggle();
}), 500);
return $(document).on('keypress', VIMEditorActions.keypressHandler);
}),
mode: 'normal'
};
jQuery(function() {
return VIMEditor.init();
});
}).call(this);