Merge pull request #650 from danderozier/gh-451-clean-up-event-handlers

Remove menu event handlers on destroy
This commit is contained in:
Philipp Kühn 2020-04-02 09:15:13 +02:00 committed by GitHub
commit 15eb791b31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 10 deletions

View File

@ -20,18 +20,20 @@ class Menu {
this.mousedownHandler = this.handleClick.bind(this)
this.options.element.addEventListener('mousedown', this.mousedownHandler, { capture: true })
this.options.editor.on('focus', ({ view }) => {
this.focusHandler = ({ view }) => {
this.update(view)
})
}
this.options.editor.on('focus', this.focusHandler)
this.options.editor.on('blur', ({ event }) => {
this.blurHandler = ({ event }) => {
if (this.preventHide) {
this.preventHide = false
return
}
this.hide(event)
})
}
this.options.editor.on('blur', this.blurHandler)
// sometimes we have to update the position
// because of a loaded images for example
@ -116,6 +118,9 @@ class Menu {
if (this.resizeObserver) {
this.resizeObserver.unobserve(this.editorView.dom)
}
this.options.editor.off('focus', this.focusHandler)
this.options.editor.off('blur', this.blurHandler)
}
}

View File

@ -10,14 +10,15 @@ class Menu {
this.mousedownHandler = this.handleClick.bind(this)
this.options.element.addEventListener('mousedown', this.mousedownHandler, { capture: true })
this.options.editor.on('blur', () => {
this.blurHandler = () => {
if (this.preventHide) {
this.preventHide = false
return
}
this.options.editor.emit('menubar:focusUpdate', false)
})
}
this.options.editor.on('blur', this.blurHandler)
}
handleClick() {
@ -26,6 +27,7 @@ class Menu {
destroy() {
this.options.element.removeEventListener('mousedown', this.mousedownHandler)
this.options.editor.off('blur', this.blurHandler)
}
}

View File

@ -73,18 +73,20 @@ class Menu {
this.mousedownHandler = this.handleClick.bind(this)
this.options.element.addEventListener('mousedown', this.mousedownHandler, { capture: true })
this.options.editor.on('focus', ({ view }) => {
this.focusHandler = ({ view }) => {
this.update(view)
})
}
this.options.editor.on('focus', this.focusHandler)
this.options.editor.on('blur', ({ event }) => {
this.blurHandler = ({ event }) => {
if (this.preventHide) {
this.preventHide = false
return
}
this.hide(event)
})
}
this.options.editor.on('blur', this.blurHandler)
}
handleClick() {
@ -167,6 +169,8 @@ class Menu {
destroy() {
this.options.element.removeEventListener('mousedown', this.mousedownHandler)
this.options.editor.off('focus', this.focusHandler)
this.options.editor.off('blur', this.blurHandler)
}
}