unregister plugins correctly, fix #188

This commit is contained in:
Philipp Kühn 2019-05-18 00:22:05 +02:00
parent c0713b64af
commit 0742ca8abe
5 changed files with 23 additions and 2 deletions

View File

@ -52,4 +52,8 @@ export default {
})
},
beforeDestroy() {
this.editor.unregisterPlugin('floating_menu')
},
}

View File

@ -63,4 +63,8 @@ export default {
})
},
beforeDestroy() {
this.editor.unregisterPlugin('menu_bubble')
},
}

View File

@ -439,6 +439,17 @@ export default class Editor extends Emitter {
this.view.updateState(newState)
}
unregisterPlugin(name = null) {
if (!name || !this.view.docView) {
return
}
const newState = this.state.reconfigure({
plugins: this.state.plugins.filter(plugin => !plugin.key.startsWith(`${name}$`)),
})
this.view.updateState(newState)
}
destroy() {
if (!this.view) {
return

View File

@ -1,4 +1,4 @@
import { Plugin } from 'prosemirror-state'
import { Plugin, PluginKey } from 'prosemirror-state'
class Menu {
@ -75,6 +75,7 @@ class Menu {
export default function (options) {
return new Plugin({
key: new PluginKey('floating_menu'),
view(editorView) {
return new Menu({ editorView, options })
},

View File

@ -1,4 +1,4 @@
import { Plugin } from 'prosemirror-state'
import { Plugin, PluginKey } from 'prosemirror-state'
function textRange(node, from, to) {
const range = document.createRange()
@ -135,6 +135,7 @@ class Menu {
export default function (options) {
return new Plugin({
key: new PluginKey('menu_bubble'),
view(editorView) {
return new Menu({ editorView, options })
},