Skip to content

Fix/mode aware copy paste + heading anchor bug#2839

Open
pory-gone wants to merge 2 commits intostackernews:masterfrom
pory-gone:fix/mode-aware-copy-paste
Open

Fix/mode aware copy paste + heading anchor bug#2839
pory-gone wants to merge 2 commits intostackernews:masterfrom
pory-gone:fix/mode-aware-copy-paste

Conversation

@pory-gone
Copy link
Contributor

@pory-gone pory-gone commented Mar 2, 2026

Description

fix #2833
Proposed implementation of mode-aware copy/paste that transforms content between Lexical and Markdown formats on paste. Also fixed a bug where heading anchor links rendered duplicate visible text in replies.

Screenshots

Video.del.2026-03-02.20-26-38.mp4
Video.del.2026-03-02.21-34-29.mp4

Additional Context

While testing the copy/paste feature, I discovered that headings in replies were rendering anchor link text visibly, causing duplicated text (e.g. "Markdown TestMarkdown Test")

Checklist

Are your changes backward compatible? Please answer below:
yes

On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:
8/10

For frontend changes: Tested on mobile, light and dark mode? Please answer below:
yes

Did you introduce any new environment variables? If so, call them out explicitly here:
no

Did you use AI for this? If so, how much did it assist you?
the AI ​​helped me understand any side effects of the changes

@Soxasora
Copy link
Member

Soxasora commented Mar 3, 2026

Hey thanks for the thought! All the issues in #2832 are reserved to us because they must be implemented after Stage 3, which is in development at #2780. My bad, I should've assigned myself to those issues.

While this is almost what we're going to do, the new copy/paste mechanism should involve grabbing the Lexical payload on copy and converting it to Markdown on paste (checking the presence of the Lexical payload). This PR is already near that! But I can't review it, nor even move this forward because the specifications of how this should work are not available yet/can't be applied.

Thanks again for the help, because now I have a clearer way forward for copy/paste, hope we didn't waste your time!

link.className = 'sn-heading__link'
link.setAttribute('href', `#${headingId}`)
link.textContent = textContent
link.setAttribute('aria-label', textContent)
Copy link
Member

@Soxasora Soxasora Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this is that the <a> link tag doesn't have anything to render and the heading won't be clickable, that's why we place a "duplicate" text content.
I know this caused issues with copy, and it's because in the DOM we have the same heading twice:

  • heading: abc1
  • link heading: abc1

resulting in abc1abc1.

Ours was a best-effort attempt to introduce heading anchors in Lexical, but they can be much better and I'm glad you tried to find a better way.

@pory-gone
Copy link
Contributor Author

Don't worry, it's my fault. I thought it was a specific issue, but I wanted to try. No, you didn't make me lose anything!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mode-aware copy/paste

2 participants