mdx-editor / editor

A rich text editor React component for markdown
https://mdxeditor.dev
MIT License
1.63k stars 131 forks source link

[BUG] Standardize meaning of "Title" in link dialog #443

Open braincore opened 2 months ago

braincore commented 2 months ago

If you want to ask for support or request features, sponsor the project and contact me over email.

Describe the bug When a link is first created, the "Title" field indicates the anchor text. However, if the link is edited, the "Title" field will add a Markdown link-title while confusingly being populated by the anchor text.

Expected behavior While I can't speak for all use cases, I suspect the Markdown link-title has little utility compared to the anchor text. I recommend making the anchor text modifiable with the current field (rename "Title" to "Link Text"/"Text"). Optionally, add a new and separate field for link-title that can be specified on link creation, but consider adding a flag to omit it.

petyosi commented 2 months ago

I agree with you. The only reason for this behavior is a lack of resources on my side. Implementing a separate field for the link text is the way to go, but then there's complexity coming from the fact, that the link may contain formatting or even images - how are those represented? Notion solves this in a way, by converting to plain text, but then changing the plain text loses the formatting.

Of course, the field might be shown only if no selection is present, but then it becomes inconsistent.

braincore commented 2 months ago

The complexity of non-text anchors makes sense. For anyone deciding to submit a PR, the short term solution then is to:

  1. When creating a new link, have two distinct fields: anchor text and link-title.
  2. When modifying a link, omit the anchor text field (cannot be changed), and have the link-title input be strictly the existing link-title.
  3. Have a flag to hide the link-title input in LinkDialog for both the creation and modification flows.