diff options
Diffstat (limited to 'js')
| -rw-r--r-- | js/app.js | 59 | ||||
| -rw-r--r-- | js/lex.js | 43 |
2 files changed, 58 insertions, 44 deletions
@@ -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' @@ -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() } |
