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,
},
handleDOMEvents: {
focus: event => {
focus: (view, event) => {
this.emit('focus', {
event,
state: this.state,
view: this.view,
state: view.state,
view,
})
},
blur: event => {
blur: (view, event) => {
this.emit('blur', {
event,
state: this.state,
view: this.view,
state: view.state,
view,
})
},
},

View File

@ -14,7 +14,12 @@ class Menu {
this.isActive = false
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) {
@ -30,7 +35,7 @@ class Menu {
return
}
const currentDom = view.domAtPos(state.selection.$anchor.pos)
const currentDom = view.domAtPos(state.selection.anchor)
const isActive = currentDom.node.innerHTML === '<br>'
&& currentDom.node.tagName === 'P'
@ -42,7 +47,7 @@ class Menu {
}
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
this.isActive = true

View File

@ -67,7 +67,12 @@ class Menu {
this.left = 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) {