Ionaru / Ionaru/easy-markdown-editor
Replace toolbar without recreating EasyMDE instance
- Dominant language
- JavaScript
- Stars
- 3.1k
- Forks
- 363
- PR merge metrics
- No merged PRs in 30d
Description
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!
Contributor guide
Research direction
Start by tracing the existing createToolbar and toTextArea lifecycle on the EasyMDE instance, then review how previewRender is configured. Define how replacing the toolbar and preview renderer should preserve the instance and its textarea behavior, and add coverage for the requested replacement operations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100