summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-11-22 18:03:48 -0500
committerJules Laplace <jules@okfoc.us>2014-11-22 18:03:48 -0500
commit8c544b08e8a855635007147cf21e795d74876025 (patch)
tree748622ba33cd618a718a9e7f171366edef92254a /js
parentd14b3d777182602093364874ceeccae1d595e3a9 (diff)
fixing cursor focus shit
Diffstat (limited to 'js')
-rw-r--r--js/app.js59
-rw-r--r--js/lex.js43
2 files changed, 58 insertions, 44 deletions
diff --git a/js/app.js b/js/app.js
index 43ab047..223edcc 100644
--- a/js/app.js
+++ b/js/app.js
@@ -41,10 +41,9 @@ function bind () {
if (current_tool.name == "shader") { return }
cursor_input.focus()
})
+
+ var direction = [0,1]
cursor_input.addEventListener('keydown', function(e){
- if (! e.metaKey && ! e.ctrlKey && ! e.altKey) {
- e.preventDefault()
- }
console.log("keycode:", e.keyCode)
@@ -54,29 +53,75 @@ function bind () {
break
case 219: // [
if (current_tool.name != "text") {
+ e.preventDefault()
brush.contract(1)
break
}
case 221: // ]
if (current_tool.name != "text") {
+ e.preventDefault()
brush.expand(1)
break
}
- default:
- if (focused) { focused.key(undefined, e.keyCode) }
+ case 8:
+ e.preventDefault()
+ canvas.focusLex(focused.y-1, focused.x)
+ focused.char = " "
+ focused.build()
+ return
+ case 13: // return
+ e.preventDefault()
+ canvas.focusLex(focused.y, focused.x+1)
+ return
+ case 38: // up
+ e.preventDefault()
+ direction[0] = -1
+ direction[1] = 0
+ canvas.focusLex(focused.y + direction[0], focused.x + direction[1])
+ break
+ case 40: // down
+ e.preventDefault()
+ direction[0] = 1
+ direction[1] = 0
+ canvas.focusLex(focused.y + direction[0], focused.x + direction[1])
+ break
+ case 37: // left
+ e.preventDefault()
+ direction[0] = 0
+ direction[1] = -1
+ canvas.focusLex(focused.y + direction[0], focused.x + direction[1])
+ break
+ case 39: // right
+ e.preventDefault()
+ direction[0] = 0
+ direction[1] = 1
+ canvas.focusLex(focused.y + direction[0], focused.x + direction[1])
+ break
+// default:
+// if (focused) { focused.key(undefined, e.keyCode) }
}
})
+
cursor_input.addEventListener('input', function(e){
+/*
+ if (! e.metaKey && ! e.ctrlKey && ! e.altKey) {
+ e.preventDefault()
+ }
+*/
if (current_tool.name == "shader") {
cursor_input.value = ""
return
}
var char = cursor_input.value
-// cursor_input.value = ""
+ cursor_input.value = ""
console.log("input:", char)
- if (focused) { focused.key(char, e.keyCode) }
+ if (focused && char) {
+ var y = focused.y, x = focused.x
+ focused.key(char, e.keyCode)
+ canvas.focusLex(y + direction[0], focused.x + direction[1])
+ }
})
var contentType = 'text/plain;charset=utf-8'
diff --git a/js/lex.js b/js/lex.js
index a35829f..56d8280 100644
--- a/js/lex.js
+++ b/js/lex.js
@@ -1,5 +1,3 @@
-direction = [1,0]
-
function Lex (x,y) {
if (typeof x == "number") {
this.y = y
@@ -82,40 +80,11 @@ 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) {
- case 8:
- canvas.focusLex(this.y-1, this.x)
- focused.char = " "
- focused.build()
- return
- case 13: // return
- canvas.focusLex(0, this.x+1)
- return
- case 38: // up
- direction[0] = 0
- direction[1] = -1
- break
- case 40: // down
- direction[0] = 0
- direction[1] = 1
- break
- case 37: // left
- direction[0] = -1
- direction[1] = 0
- break
- case 39: // right
- direction[0] = 1
- direction[1] = 0
- break
- default:
- if (! char) { return }
- this.char = char
- this.fg = brush.bg
- this.build()
- this.blur()
- break
- }
- canvas.focusLex(this.y + direction[0], this.x + direction[1])
+ if (! char) { return }
+ this.char = char
+ this.fg = brush.bg
+ this.build()
}