mdx-editor / mdx-editor/editor

[BUG] insertMarkdown() doesn't work correctly when editing in "source" mode

Open
#636 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

  1. Click the toggle into source mode
  2. Add some markdown
  3. Click the "Insert Markdown" button
  4. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.