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,
|
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,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -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
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user