-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathace_emit.js
33 lines (27 loc) · 1.11 KB
/
ace_emit.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
var Position = function (row, column){
this.row = row;
this.column = column;
}
var Ace_Emit = function (emit_system){
this.system = emit_system;
this.cursor_prev_p = new Position(0,0);
this.cursor_current_p = new Position(0,0);
}
Ace_Emit.prototype.passChar = function (character){
this.system.processChar(character);
}
Ace_Emit.prototype.updateCursor = function (cursor_position){
this.cursor_prev_p = this.cursor_current_p;
this.cursor_current_p = cursor_position;
var moved_left = (this.cursor_current_p.column - this.cursor_prev_p.column) == -1;
var moved_right = (this.cursor_current_p.column - this.cursor_prev_p.column) == 1;
var moved_up = (this.cursor_current_p.row - this.cursor_prev_p.row) == -1;
var moved_down = (this.cursor_current_p.row - this.cursor_prev_p.row) == 1;
if(moved_left) this.system.cursorMoved("left");
else if(moved_right) this.system.cursorMoved("right");
else if(moved_up) this.system.cursorMoved("up");
else if(moved_down) this.system.cursorMoved("down");
}
Ace_Emit.prototype.removeChar = function (){
this.system.removeChar ();
}