Skip to content

Commit

Permalink
feat(EscapeKey): Only accept ESC key if it was pressed while the app …
Browse files Browse the repository at this point in the history
  • Loading branch information
pdanpdan committed Jul 8, 2020
1 parent b711db5 commit eac838a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ui/src/utils/escape-key.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import { isKeyCode } from './key-composition.js'

let handlers = []
let escDown = false

export default {
__install () {
this.__installed = true
window.addEventListener('keydown', evt => {
escDown = evt.keyCode === 27
})
window.addEventListener('blur', () => {
escDown === true && (escDown = false)
})
window.addEventListener('keyup', evt => {
if (handlers.length !== 0 && isKeyCode(evt, 27) === true) {
handlers[handlers.length - 1].fn(evt)
if (escDown === true) {
escDown = false

if (handlers.length !== 0 && isKeyCode(evt, 27) === true) {
handlers[handlers.length - 1].fn(evt)
}
}
})
},
Expand Down

0 comments on commit eac838a

Please sign in to comment.