summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/app.js77
-rw-r--r--js/matrix.js2
-rw-r--r--js/ui/keys.js83
3 files changed, 85 insertions, 77 deletions
diff --git a/js/app.js b/js/app.js
index f42507a..fd375cf 100644
--- a/js/app.js
+++ b/js/app.js
@@ -31,6 +31,7 @@ function bind () {
palette.bind()
brush.bind()
controls.bind()
+ keys.bind()
window.addEventListener('mouseup', function(){
dragging = erasing = false
@@ -42,82 +43,6 @@ function bind () {
cursor_input.focus()
})
- var direction = [0,1]
- cursor_input.addEventListener('keydown', function(e){
-
- console.log("keycode:", e.keyCode)
-
- switch (e.keyCode) {
- case 27: // esc
- if (focused) focused.blur()
- break
- case 219: // [
- if (current_tool.name != "text") {
- e.preventDefault()
- brush.contract(1)
- brush.modified = false
- break
- }
- case 221: // ]
- if (current_tool.name != "text") {
- e.preventDefault()
- brush.expand(1)
- brush.modified = false
- break
- }
- case 8:
- e.preventDefault()
- current_canvas.focusLex(focused.y-1, focused.x)
- focused.char = " "
- focused.build()
- return
- case 13: // return
- e.preventDefault()
- current_canvas.focusLex(focused.y, focused.x+1)
- return
- case 38: // up
- e.preventDefault()
- current_canvas.focusLex(focused.y - 1, focused.x + 0)
- break
- case 40: // down
- e.preventDefault()
- current_canvas.focusLex(focused.y + 1, focused.x + 0)
- break
- case 37: // left
- e.preventDefault()
- current_canvas.focusLex(focused.y + 0, focused.x - 1)
- break
- case 39: // right
- e.preventDefault()
- current_canvas.focusLex(focused.y + 0, focused.x + 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 = ""
-
- console.log("input:", char)
-
- if (focused && char) {
- var y = focused.y, x = focused.x
- focused.key(char, e.keyCode)
- current_canvas.focusLex(y + direction[0], focused.x + direction[1])
- }
- })
-
document.addEventListener('DOMContentLoaded', function(){
if (current_tool.name != 'shader') { cursor_input.focus() }
document.body.classList.remove('loading')
diff --git a/js/matrix.js b/js/matrix.js
index 8d3392f..0bb2492 100644
--- a/js/matrix.js
+++ b/js/matrix.js
@@ -132,7 +132,7 @@ Matrix.prototype.irssi = function(){
.replace(/\n/g, '\\n')
.replace(/\x02/g, '\\x02')
.replace(/\x03/g, '\\x03')
-console.log(txt.length)
+ // console.log(txt.length)
var escaped_txt = "", kode
for (var i = 0; i < txt.length; i++) {
kode = txt.charCodeAt(i)
diff --git a/js/ui/keys.js b/js/ui/keys.js
new file mode 100644
index 0000000..7711e9d
--- /dev/null
+++ b/js/ui/keys.js
@@ -0,0 +1,83 @@
+var keys = (function(){
+
+ var keys = {}
+ var direction = [0,1]
+ keys.bind = function(){
+ cursor_input.addEventListener('keydown', function(e){
+
+ console.log("keycode:", e.keyCode)
+
+ switch (e.keyCode) {
+ case 27: // esc
+ if (focused) focused.blur()
+ break
+ case 219: // [
+ if (current_tool.name != "text") {
+ e.preventDefault()
+ brush.contract(1)
+ brush.modified = false
+ break
+ }
+ case 221: // ]
+ if (current_tool.name != "text") {
+ e.preventDefault()
+ brush.expand(1)
+ brush.modified = false
+ break
+ }
+ case 8:
+ e.preventDefault()
+ current_canvas.focusLex(focused.y-1, focused.x)
+ focused.char = " "
+ focused.build()
+ return
+ case 13: // return
+ e.preventDefault()
+ current_canvas.focusLex(focused.y, focused.x+1)
+ return
+ case 38: // up
+ e.preventDefault()
+ current_canvas.focusLex(focused.y - 1, focused.x + 0)
+ break
+ case 40: // down
+ e.preventDefault()
+ current_canvas.focusLex(focused.y + 1, focused.x + 0)
+ break
+ case 37: // left
+ e.preventDefault()
+ current_canvas.focusLex(focused.y + 0, focused.x - 1)
+ break
+ case 39: // right
+ e.preventDefault()
+ current_canvas.focusLex(focused.y + 0, focused.x + 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 = ""
+
+ console.log("input:", char)
+
+ if (focused && char) {
+ var y = focused.y, x = focused.x
+ focused.key(char, e.keyCode)
+ current_canvas.focusLex(y + direction[0], focused.x + direction[1])
+ }
+ })
+ }
+
+ return keys
+})()