do not prevent clicks in menus, fix #454, fix #470

This commit is contained in:
Philipp Kühn 2019-10-04 13:23:02 +02:00
parent 5f5b3eac25
commit 3656c16b61
4 changed files with 55 additions and 13 deletions

View File

@ -9,6 +9,12 @@ export default {
}, },
}, },
data() {
return {
focused: false,
}
},
watch: { watch: {
editor: { editor: {
immediate: true, immediate: true,
@ -19,6 +25,16 @@ export default {
editor, editor,
element: this.$el, element: this.$el,
})) }))
this.focused = editor.focused
editor.on('focus', () => {
this.focused = true
})
editor.on('menubar:focusUpdate', focused => {
this.focused = focused
})
}) })
} }
}, },
@ -31,7 +47,7 @@ export default {
} }
return this.$scopedSlots.default({ return this.$scopedSlots.default({
focused: this.editor.view.focused, focused: this.focused,
focus: this.editor.focus, focus: this.editor.focus,
commands: this.editor.commands, commands: this.editor.commands,
isActive: this.editor.isActive, isActive: this.editor.isActive,

View File

@ -11,18 +11,25 @@ class Menu {
}, },
...options, ...options,
} }
this.preventHide = false
this.editorView = editorView this.editorView = editorView
this.isActive = false this.isActive = false
this.top = 0 this.top = 0
// the mousedown event is fired before blur so we can prevent it // the mousedown event is fired before blur so we can prevent it
this.options.element.addEventListener('mousedown', this.handleClick) this.mousedownHandler = this.handleClick.bind(this)
this.options.element.addEventListener('mousedown', this.mousedownHandler)
this.options.editor.on('focus', ({ view }) => { this.options.editor.on('focus', ({ view }) => {
this.update(view) this.update(view)
}) })
this.options.editor.on('blur', ({ event }) => { this.options.editor.on('blur', ({ event }) => {
if (this.preventHide) {
this.preventHide = false
return
}
this.hide(event) this.hide(event)
}) })
@ -38,8 +45,8 @@ class Menu {
} }
} }
handleClick(event) { handleClick() {
event.preventDefault() this.preventHide = true
} }
update(view, lastState) { update(view, lastState) {
@ -103,7 +110,7 @@ class Menu {
} }
destroy() { destroy() {
this.options.element.removeEventListener('mousedown', this.handleClick) this.options.element.removeEventListener('mousedown', this.mousedownHandler)
if (this.resizeObserver) { if (this.resizeObserver) {
this.resizeObserver.unobserve(this.editorView.dom) this.resizeObserver.unobserve(this.editorView.dom)

View File

@ -4,17 +4,28 @@ class Menu {
constructor({ options }) { constructor({ options }) {
this.options = options this.options = options
this.preventHide = false
// the mousedown event is fired before blur so we can prevent it // the mousedown event is fired before blur so we can prevent it
this.options.element.addEventListener('mousedown', this.handleClick) this.mousedownHandler = this.handleClick.bind(this)
this.options.element.addEventListener('mousedown', this.mousedownHandler)
this.options.editor.on('blur', () => {
if (this.preventHide) {
this.preventHide = false
return
} }
handleClick(event) { this.options.editor.emit('menubar:focusUpdate', false)
event.preventDefault() })
}
handleClick() {
this.preventHide = true
} }
destroy() { destroy() {
this.options.element.removeEventListener('mousedown', this.handleClick) this.options.element.removeEventListener('mousedown', this.mousedownHandler)
} }
} }

View File

@ -67,21 +67,28 @@ class Menu {
this.left = 0 this.left = 0
this.bottom = 0 this.bottom = 0
this.top = 0 this.top = 0
this.preventHide = false
// the mousedown event is fired before blur so we can prevent it // the mousedown event is fired before blur so we can prevent it
this.options.element.addEventListener('mousedown', this.handleClick) this.mousedownHandler = this.handleClick.bind(this)
this.options.element.addEventListener('mousedown', this.mousedownHandler)
this.options.editor.on('focus', ({ view }) => { this.options.editor.on('focus', ({ view }) => {
this.update(view) this.update(view)
}) })
this.options.editor.on('blur', ({ event }) => { this.options.editor.on('blur', ({ event }) => {
if (this.preventHide) {
this.preventHide = false
return
}
this.hide(event) this.hide(event)
}) })
} }
handleClick(event) { handleClick() {
event.preventDefault() this.preventHide = true
} }
update(view, lastState) { update(view, lastState) {
@ -146,6 +153,7 @@ class Menu {
} }
hide(event) { hide(event) {
console.log('hide', { event })
if (event if (event
&& event.relatedTarget && event.relatedTarget
&& this.options.element.parentNode.contains(event.relatedTarget) && this.options.element.parentNode.contains(event.relatedTarget)
@ -158,7 +166,7 @@ class Menu {
} }
destroy() { destroy() {
this.options.element.removeEventListener('mousedown', this.handleClick) this.options.element.removeEventListener('mousedown', this.mousedownHandler)
} }
} }