summaryrefslogtreecommitdiff
path: root/js/lex.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lex.js')
-rw-r--r--js/lex.js28
1 files changed, 15 insertions, 13 deletions
diff --git a/js/lex.js b/js/lex.js
index 7066ddb..d61f561 100644
--- a/js/lex.js
+++ b/js/lex.js
@@ -1,3 +1,5 @@
+direction = [1,0]
+
function Lex (x,y) {
if (typeof x == "number") {
this.x = x
@@ -16,7 +18,7 @@ Lex.prototype.build = function(){
this.span.innerHTML = this.html()
}
Lex.prototype.css = function(){
- return "f" + letters[mod(this.fg,16)] + "b" + letters[mod(this.bg,15)]
+ return "f" + letters[mod(this.fg,16)] + "b" + letters[mod(this.bg,16)]
}
Lex.prototype.html = function(){
return this.char == " " ? " " : this.char || " "
@@ -78,7 +80,6 @@ Lex.prototype.demolish = function(){
this.span.parentNode.removeChild(this.span)
this.span = null
}
-
Lex.prototype.key = function(char, keyCode) {
console.log(keyCode, this.y, this.x)
switch (keyCode) {
@@ -89,29 +90,30 @@ Lex.prototype.key = function(char, keyCode) {
return
case 13: // return
canvas.focusLex(0, this.x+1)
- break
+ return
case 38: // up
- canvas.focusLex(this.y, this.x-1)
+ direction[0] = 0
+ direction[1] = -1
break
case 40: // down
- canvas.focusLex(this.y, this.x+1)
+ direction[0] = 0
+ direction[1] = 1
break
case 37: // left
- canvas.focusLex(this.y-1, this.x)
+ direction[0] = -1
+ direction[1] = 0
break
case 39: // right
- canvas.focusLex(this.y+1, this.x)
+ direction[0] = 1
+ direction[1] = 0
break
default:
+ if (! char) { return }
this.char = char
this.fg = brush.bg
this.build()
this.blur()
- if (this.y < canvas.w-1) {
- canvas.aa[this.x][this.y+1].focus()
- }
- else {
- canvas.focusLex(0, this.x+1)
- }
+ break
}
+ canvas.focusLex(this.y + direction[0], this.x + direction[1])
}