Skip to content

Desktop: Fixes #14852: Duplicate codeblocks when copying from note vi…#14860

Open
Ashutoshx7 wants to merge 2 commits intolaurent22:devfrom
Ashutoshx7:fix/viewer-copy-duplicate-codeblocks
Open

Desktop: Fixes #14852: Duplicate codeblocks when copying from note vi…#14860
Ashutoshx7 wants to merge 2 commits intolaurent22:devfrom
Ashutoshx7:fix/viewer-copy-duplicate-codeblocks

Conversation

@Ashutoshx7
Copy link
Copy Markdown
Contributor

@Ashutoshx7 Ashutoshx7 commented Mar 21, 2026

Fixes #14852
This PR builds directly on top of the PR #14474.

Problem
When you copy from the viewer and paste into MS Word etc, the code blocks appear twice because browser copying includes Joplin's hidden "source" version. Also, an internal accessibility link ("Note viewer top") leaks into the clipboard.

Screencast.from.2026-03-21.18-03-13.mp4

Solution:
I updated the logic that handles copying to strip these internal elements before they're sent to the clipboard.
Since there was already a cleanup step in the code to handle theme backgrounds, I just added a few more lines to also remove

Screencast.from.2026-03-21.07-59-30.mp4

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 75843e46-56b4-48bd-b69f-51a68658a0ec

📥 Commits

Reviewing files that changed from the base of the PR and between 5139ece and c7e21af.

📒 Files selected for processing (1)
  • packages/app-desktop/gui/note-viewer/index.html
✅ Files skipped from review due to trivial changes (1)
  • packages/app-desktop/gui/note-viewer/index.html

📝 Walkthrough

Walkthrough

The PR modifies clipboard HTML generation in the note viewer to remove additional hidden markup—specifically .joplin-source <pre> elements (raw Markdown) and the #joplin-content-focus-dummy accessibility container—preventing them from leaking into pasted content.

Changes

Cohort / File(s) Summary
Clipboard HTML cleanup
packages/app-desktop/gui/note-viewer/index.html
Strip .joplin-source <pre> elements and remove the #joplin-content-focus-dummy container from the cloned selection before writing text/html/text/plain to the clipboard, preserving existing <style> stripping logic.

Possibly related PRs

Suggested labels

bug, desktop, accessibility


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Pr Description Must Follow Guidelines ❌ Error The PR description lacks an explicit Test Plan or Verification Steps section as required by the pull request guidelines, despite including Problem/User-impact and Solution explanation sections. Add a dedicated Test Plan section outlining steps to reproduce the issue, expected behaviour after the fix, and confirmation that pasting into Joplin's Rich Text Editor still functions correctly.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing issue #14852 regarding duplicate codeblocks when copying from the note viewer.
Description check ✅ Passed The description is clearly related to the changeset, explaining the problem (duplicate codeblocks and leaked accessibility link) and the solution (stripping internal elements from clipboard content).
Linked Issues check ✅ Passed The code changes directly address all requirements from issue #14852: removing hidden .joplin-source elements to prevent duplication and stripping the accessibility link from clipboard content.
Out of Scope Changes check ✅ Passed All changes are narrowly focused on the copy event handler in index.html, removing .joplin-source elements and the accessibility link container—directly aligned with the stated objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai bot added bug It's a bug desktop All desktop platforms accessibility Related to accessibility labels Mar 21, 2026
@laurent22
Copy link
Copy Markdown
Owner

When you copy from the viewer and paste into MS Word

But your video doesn't show this?

@Ashutoshx7
Copy link
Copy Markdown
Contributor Author

@laurent22 updated the decription

@laurent22
Copy link
Copy Markdown
Owner

Could you please read the issue again? Ask ChatGPT to explain it for you maybe. You're not understanding what needs to be done

@laurent22
Copy link
Copy Markdown
Owner

What you need to do to replicate is this:

  • Select the markdown editor (not the RTE as one of your videos show)
  • Then copy from the Viewer panel in the right (not the editor panel as another of your videos show)
  • Then paste in Word

Currently it shows duplicate codeblocks and other hidden elements. Instead the pasted text should be clean

@Ashutoshx7
Copy link
Copy Markdown
Contributor Author

What you need to do to replicate is this:

  • Select the markdown editor (not the RTE as one of your videos show)
  • Then copy from the Viewer panel in the right (not the editor panel as another of your videos show)
  • Then paste in Word

Currently it shows duplicate codeblocks and other hidden elements. Instead the pasted text should be clean

Screencast.from.2026-03-25.04-35-40.mp4

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

Labels

accessibility Related to accessibility bug It's a bug desktop All desktop platforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text copied from note viewer and pasted in an external rich text editor duplicates the codeblocks

3 participants