The copy button of a code block is an <a href="#"> inside the card viewer.
Its own listener copied the text and prevented the navigation, but the click
went on to the viewer's 'click a' handler, which opens every link it sees in
a new tab - here this page plus "#". The button now stops the click, and the
viewer handler leaves the copy button alone and no longer opens a link to a
place on the page ("#", "#section") in a new tab; it moves to the target in
place when there is one.
tests/copyCodeBlock.test.cjs pins both and their order before window.open;
tests/playwright/specs/viewer-copy-code.e2e.js clicks the button and checks
that no tab opens, the page stays and the block's text is copied.
Thanks to carl-unique and xet7 !
Fixes#6753.
The copy-code-block feature existed but the reporter saw it 'work very sporadically (only a handful of items have it)' and lost after editing. Root causes: it ran ONCE in Template.editor.onRendered with a global document.querySelectorAll('.viewer > pre'), so it decorated only whichever viewers were on the page at that instant and never re-added the button after an edit re-rendered the viewer; and it copied the HTML-escaped innerHTML of the <pre>'s first child node (often the wrong content or undefined) via the deprecated execCommand. Now the decoration lives in Template.viewer.onRendered, so EVERY viewer (card description, checklist item, comment) gets a copy button and it is restored on every re-render; it is de-duplicated (skips a <pre> that already has its button) so re-renders never stack buttons; it copies the RAW code text (pre.textContent) via navigator.clipboard.writeText with an execCommand fallback; and the button title is translated (the existing 'copy-text-to-clipboard' i18n key) instead of a hard-coded English string.
Tests: tests/copyCodeBlock.test.cjs (5 checks) guards that the decoration is in Template.viewer.onRendered scoped to the viewer's <pre>, copies textContent (not innerHTML), de-dups, is translated, and uses the async Clipboard API with a fallback.
Thanks to C0rn3j and xet7 !
Fixes#5149,