diff --git a/src/client/ui/ui-code-editor.js b/src/client/ui/ui-code-editor.js index c83cb00a..040ed4a6 100644 --- a/src/client/ui/ui-code-editor.js +++ b/src/client/ui/ui-code-editor.js @@ -40,7 +40,7 @@ class CodeEditor { this.closeKey = ((e)=>{ // this handler may remain dangling if closing with ctrl+enter // we ignore this as it has no effect - if (e.keyCode !== 27) return + if (e.key != 'Escape') return this.field.classList.remove('fullscreen') this.editor.setOptions({maxLines: 30}) this.editor.fullscreen = false @@ -52,7 +52,7 @@ class CodeEditor { this.closeClick = ((e)=>{ if (e.target === this.field) { - this.closeKey({keyCode: 27}) + this.closeKey({key: 'Escape'}) } }).bind(this) diff --git a/src/client/ui/ui-colorpicker.js b/src/client/ui/ui-colorpicker.js index 21748bfb..43e3cbbd 100644 --- a/src/client/ui/ui-colorpicker.js +++ b/src/client/ui/ui-colorpicker.js @@ -46,11 +46,11 @@ class ColorPicker extends UiWidget { this.opened = 0 this.escKeyHandler = ((e)=>{ - if (e.keyCode==27) this.close() + if (e.key == 'Escape') this.close() }).bind(this) this.enterKeyHandler = ((e)=>{ - if (e.keyCode == 13) this.confirm() + if (e.key == 'Enter') this.confirm() }).bind(this) } diff --git a/src/client/ui/ui-console.js b/src/client/ui/ui-console.js index c85a1b0d..708c3aa6 100644 --- a/src/client/ui/ui-console.js +++ b/src/client/ui/ui-console.js @@ -69,10 +69,10 @@ class UiConsole extends UiSidePanel { this.widget.hash = 'CONSOLE' this.input.addEventListener('keydown', (event)=>{ - if (event.keyCode === 13 && !event.shiftKey) { + if (event.key === 'Enter' && !event.shiftKey) { event.preventDefault() this.inputValidate() - } else if (event.keyCode === 38) { + } else if (event.key == 'ArrowUp') { if (this.cursor < this.history.length - 1) { if (this.input.value.substr(0, this.input.selectionStart).split('\n').length !== 1) return @@ -81,7 +81,7 @@ class UiConsole extends UiSidePanel { this.input.value = this.history[this.cursor] event.preventDefault() } - } else if (event.keyCode === 40) { + } else if (event.key == 'ArrowDown') { if (this.cursor > 0) { var nLines = this.input.value.split('\n').length if (this.input.value.substr(0, this.input.selectionStart).split('\n').length !== nLines) return @@ -90,7 +90,7 @@ class UiConsole extends UiSidePanel { this.input.value = this.history[this.cursor] event.preventDefault() } - } else if (event.keyCode === 9 && this.input.value !== '') { + } else if (event.key == 'DOM_VK_TAB' && this.input.value !== '') { var cur = this.input.selectionStart, val = this.input.value this.input.value = val.slice(0, cur) + ' ' + val.slice(cur) diff --git a/src/client/ui/ui-filebrowser.js b/src/client/ui/ui-filebrowser.js index e448e957..0454ea53 100644 --- a/src/client/ui/ui-filebrowser.js +++ b/src/client/ui/ui-filebrowser.js @@ -95,7 +95,7 @@ module.exports = function UiFilebrowser(options, callback) { function keyDownHandler(e){ - if (e.keyCode === 13) { + if (e.key == 'Enter') { if (save) { document.addEventListener('keyup', keyUpHandler) } else { @@ -103,7 +103,7 @@ module.exports = function UiFilebrowser(options, callback) { } } else if (e.target === saveInput) { return - } else if (e.keyCode === 8) { + } else if (e.key == 'DOM_VK_BACK_SPACE') { list.childNodes[0].firstElementChild.checked = true submit() } else if (e.key.length === 1) { @@ -131,7 +131,7 @@ module.exports = function UiFilebrowser(options, callback) { } function keyUpHandler(e){ - if (e.keyCode === 13) { + if (e.key == 'Enter') { setTimeout(submit, 100) document.removeEventListener('keyup', keyUpHandler) } diff --git a/src/client/ui/ui-inspector.js b/src/client/ui/ui-inspector.js index 1db74ecc..8c40a5b6 100644 --- a/src/client/ui/ui-inspector.js +++ b/src/client/ui/ui-inspector.js @@ -330,7 +330,7 @@ class UiInspector extends UiWidget { if (event.target.tagName === 'TEXTAREA') { - if (event.keyCode === 13 && + if (event.key == 'Enter' && ((!event.shiftKey && !event.target._ace) || (event[codeEditorModKey] && event.target._ace)) ) { @@ -338,7 +338,7 @@ class UiInspector extends UiWidget { event.preventDefault() DOM.dispatchEvent(event.target, 'change') - } else if (event.keyCode === 27) { + } else if (event.key == 'Escape') { event.preventDefault() event.target.value = event.target.textContent diff --git a/src/client/ui/ui-modal.js b/src/client/ui/ui-modal.js index 45a44e56..54c5c50b 100644 --- a/src/client/ui/ui-modal.js +++ b/src/client/ui/ui-modal.js @@ -56,13 +56,13 @@ class UiModal extends UiWidget { if (this.escKey) { this.escKeyHandler = ((e)=>{ - if (e.keyCode==27) this.close() + if (e.key == 'Escape') this.close() }).bind(this) } if (this.enterKey) { this.enterKeyHandler = ((e)=>{ - if (e.keyCode == 13) this.enterKey.call(this, e) + if (e.key == 'Enter') this.enterKey.call(this, e) }).bind(this) } diff --git a/src/client/ui/zoom.js b/src/client/ui/zoom.js index fef60424..61e65d58 100644 --- a/src/client/ui/zoom.js +++ b/src/client/ui/zoom.js @@ -31,12 +31,12 @@ class Zoom extends EventEmitter { document.addEventListener('keydown', (event)=>{ if (event[mod]) { - if (event.keyCode == 96 || event.keyCode == 48) { + if (event.key == 'DOM_VK_0' || event.key == 'Numpad0') { this.setGlobalZoom(INITIALZOOM) this.setLocalZoom(1) } - else if (event.keyCode == 107 || event.keyCode == 109) { - this.setGlobalZoom((event.keyCode == 107 ? 0.1 : -0.1) + PXSCALE) + else if (event.key == '+' || event.key == '-') { + this.setGlobalZoom((event.key == '+' ? 0.1 : -0.1) + PXSCALE) } } diff --git a/src/client/widgets/basics/input.js b/src/client/widgets/basics/input.js index d0d30435..161a8816 100644 --- a/src/client/widgets/basics/input.js +++ b/src/client/widgets/basics/input.js @@ -90,8 +90,8 @@ class Input extends Canvas { } this.input.addEventListener('keydown', (e)=>{ - if (e.keyCode === 13) this.blur() // enter - else if (e.keyCode === 27) this.blur(false) // esc + if (e.key == 'Enter') this.blur() + else if (e.key == 'Escape') this.blur(false) else if (asYouType) { setTimeout(()=>{ this.inputChange() diff --git a/src/client/widgets/basics/textarea.js b/src/client/widgets/basics/textarea.js index 77f49c8d..ab44b09d 100644 --- a/src/client/widgets/basics/textarea.js +++ b/src/client/widgets/basics/textarea.js @@ -49,12 +49,12 @@ class TextArea extends Widget { }, {element: this.input}) this.input.addEventListener('keydown', (e)=>{ - if (e.keyCode === 13 && !e.shiftKey) { + if (e.key == 'Enter' && !e.shiftKey) { // enter e.preventDefault() this.blur() } - else if (e.keyCode === 27) { + else if (e.key == 'Escape') { // esc this.blur(false) this.input.value = this.value diff --git a/src/client/widgets/containers/modal.js b/src/client/widgets/containers/modal.js index 8da88304..25c26909 100644 --- a/src/client/widgets/containers/modal.js +++ b/src/client/widgets/containers/modal.js @@ -123,7 +123,7 @@ class Modal extends Panel { this.escapeKeyHandler = ((e)=>{ - if (e.keyCode==27) this.setValue(0, {sync:true, send:true}) + if (e.key == 'Escape') this.setValue(0, {sync:true, send:true}) }).bind(this) this.value = 0