From b381e50043baee0f2594d212e30ab0750bf7df80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Sat, 8 Jun 2019 23:52:13 +0200 Subject: [PATCH] fix missing focus event, fix #347 --- packages/tiptap/src/Editor.js | 12 ++++++------ packages/tiptap/src/Plugins/FloatingMenu.js | 11 ++++++++--- packages/tiptap/src/Plugins/MenuBubble.js | 7 ++++++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/tiptap/src/Editor.js b/packages/tiptap/src/Editor.js index df647b9d4..aa914b02e 100644 --- a/packages/tiptap/src/Editor.js +++ b/packages/tiptap/src/Editor.js @@ -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, }) }, }, diff --git a/packages/tiptap/src/Plugins/FloatingMenu.js b/packages/tiptap/src/Plugins/FloatingMenu.js index 04f647ebb..d262acbd7 100644 --- a/packages/tiptap/src/Plugins/FloatingMenu.js +++ b/packages/tiptap/src/Plugins/FloatingMenu.js @@ -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 === '
' && 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 diff --git a/packages/tiptap/src/Plugins/MenuBubble.js b/packages/tiptap/src/Plugins/MenuBubble.js index 244424e00..1540ee9a0 100644 --- a/packages/tiptap/src/Plugins/MenuBubble.js +++ b/packages/tiptap/src/Plugins/MenuBubble.js @@ -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) {