mdx-editor / mdx-editor/editor
[BUG] insertMarkdown() doesn't work correctly when editing in "source" mode
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 3.7k
- Forks
- 307
- Avg merge
- 14h 22m
- Merged PRs (30d)
- 5
Description
- I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- I have read the documentation and cannot find an answer.
Describe the bug
insertMarkdown() doesn't work correctly when editing in "source" mode with the diffSourcePlugin - specifically, any edits made in "source" mode will be undone, and the text will be inserted based on the last state from "rich-text" mode.
Reproduction
See https://codesandbox.io/p/sandbox/mdx-editor-base-forked-tzrt6v
To Reproduce
- Click the toggle into source mode
- Add some markdown
- Click the "Insert Markdown" button
- See that your changes are lost
Expected behavior
I would expect insertMarkdown() to behave the same way in "rich-text" and "source" mode.
Screenshots
N/A
Desktop (please complete the following information):
- OS: Windows 11
- Browser: Chrome
Additional context
N/A
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked CodeSandbox reproduction and trace insertMarkdown() together with diffSourcePlugin while switching from source mode. Verify that current source edits are used for insertion rather than the last rich-text state; done when the behavior is consistent in both modes and the reproduction no longer loses text.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100