Re: #451, remove menu event handlers on destroy

This commit is contained in:
Daniel
2020-04-01 19:34:27 -05:00
parent 6044536821
commit 91f75e5305
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)
}
}