fix missing focus event, fix #347

This commit is contained in:
Philipp Kühn 2019-06-08 23:52:13 +02:00
parent 0cc18dfca2
commit b381e50043
3 changed files with 20 additions and 10 deletions

View File

@ -205,18 +205,18 @@ export default class Editor extends Emitter {
tabindex: 0, tabindex: 0,
}, },
handleDOMEvents: { handleDOMEvents: {
focus: event => { focus: (view, event) => {
this.emit('focus', { this.emit('focus', {
event, event,
state: this.state, state: view.state,
view: this.view, view,
}) })
}, },
blur: event => { blur: (view, event) => {
this.emit('blur', { this.emit('blur', {
event, event,
state: this.state, state: view.state,
view: this.view, view,
}) })
}, },
}, },

View File

@ -14,7 +14,12 @@ class Menu {
this.isActive = false this.isActive = false
this.top = 0 this.top = 0
this.options.editor.on('blur', this.hide.bind(this)) this.options.editor.on('focus', ({ view }) => {
this.update(view)
})
this.options.editor.on('blur', event => {
this.hide(event)
})
} }
update(view, lastState) { update(view, lastState) {
@ -30,7 +35,7 @@ class Menu {
return return
} }
const currentDom = view.domAtPos(state.selection.$anchor.pos) const currentDom = view.domAtPos(state.selection.anchor)
const isActive = currentDom.node.innerHTML === '<br>' const isActive = currentDom.node.innerHTML === '<br>'
&& currentDom.node.tagName === 'P' && currentDom.node.tagName === 'P'
@ -42,7 +47,7 @@ class Menu {
} }
const editorBoundings = this.options.element.offsetParent.getBoundingClientRect() const editorBoundings = this.options.element.offsetParent.getBoundingClientRect()
const cursorBoundings = view.coordsAtPos(state.selection.$anchor.pos) const cursorBoundings = view.coordsAtPos(state.selection.anchor)
const top = cursorBoundings.top - editorBoundings.top const top = cursorBoundings.top - editorBoundings.top
this.isActive = true this.isActive = true

View File

@ -67,7 +67,12 @@ class Menu {
this.left = 0 this.left = 0
this.bottom = 0 this.bottom = 0
this.options.editor.on('blur', this.hide.bind(this)) this.options.editor.on('focus', ({ view }) => {
this.update(view)
})
this.options.editor.on('blur', event => {
this.hide(event)
})
} }
update(view, lastState) { update(view, lastState) {