easy-markdown-editor icon indicating copy to clipboard operation
easy-markdown-editor copied to clipboard

Replace toolbar without recreating EasyMDE instance

Open RenanStigliani opened this issue 4 years ago • 0 comments

After the editor has been created, I need to pass new functions to custom buttons on the toolbar.

I'd like to do something like: instance.setToolbar(myNewToolbar) or instance.createToolbar(myNewToolbar, { replaceExisting: true })

Currently, my workaround looks like:

    const toolbar = createToolbar(...)

    const existingToolbar = document.getElementsByClassName(`editor-toolbar`)
    if (existingToolbar) {
        for (const element of existingToolbar) {
            element.remove()
        }
    }
    if (instance) {
        (instance as any).createToolbar(toolbar)
    }

The problem with my solution is that it breaks .toTextArea() method, and it could lead to unexpected behaviour.

I also like to replace the previewRender function is possible.

Many thanks Ionaru for maintaining the project!

RenanStigliani avatar Apr 17 '21 22:04 RenanStigliani