mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-15 02:59:01 +08:00
fix missing focus event, fix #347
This commit is contained in:
parent
0cc18dfca2
commit
b381e50043
@ -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,
|
||||
})
|
||||
},
|
||||
},
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user