Behaviour SwRS-MDOKFSTUDIO-CODE-017
A Copy code button appears on a hovered or focused code block
When the pointer is over a code block of the preview content, or the block holds keyboard focus, the extension SHALL show a 26 px Copy code button 6 px inside the block's top-right corner, below the sticky heading band and the floating toolbar when they cover that corner, and hide it whenever the pointer, a click, scrolling, a resize or a content patch makes it unusable.
Step 1 of path 1 in StRS-MDOKFSTUDIO-CODE-004: from “A code block is in the preview” to “The Copy code button is shown”.
Scenarios 9
The situations the tests check; open one to read it.
nominalThe button appears on hover
Givena code block under the pointer
Whenthe pointer enters the block
Thena 26 px Copy code button appears 6 px inside its top-right corner
boundaryNo button before the first hover
Givenno code block has been hovered yet
Whenthe page is loaded
Thenno copy button exists in the page
refusalSome blocks never get a button
| Block | Outcome |
|---|---|
| a block that is open for editing | no copy button appears |
| a code block inside a block editor | no copy button appears |
| the source of a Mermaid or PlantUML diagram | no copy button appears |
| a code block in the toolbar or a panel outside the preview content | no copy button appears |
nominalThe button stays clear of the sticky band and toolbar
Givena block whose top edge is under the sticky heading band, or whose default button position would overlap the floating toolbar
Whenthe pointer enters the block
Thenthe button is placed below the band or below the toolbar
boundaryThe button follows the visible part of the block
| Situation | Outcome |
|---|---|
| the button is shown and the block scrolls under the sticky band to 29 px visible | the button is hidden |
| the block scrolls back to exactly 30 px visible with the pointer over it | the button is shown again |
| the window is resized and the button is shown | the button moves to 6 px inside the resized block's top-right corner |
| the resize leaves less than 30 px of the block visible | the button is hidden |
| several scroll events arrive before the next animation frame | the button is placed once, in that frame, for the block's position then |
boundaryEvents that hide the button
| Event | Outcome |
|---|---|
| the reader clicks inside the hovered block | the button is hidden until the pointer moves again; a pointer move within the block shows it again |
| the pointer leaves the block | the button is hidden |
| the pointer moves from the block onto the button | the mouseout fires and the button stays shown |
| scrolling stops for 120 ms with the pointer outside the hovered block | the button is hidden |
| scrolling stops for 120 ms with the pointer still over the block | the button stays shown |
| a content patch updates the preview in place while the button is shown | the button is hidden |
| a content patch is applied while no button is shown | nothing changes and no error occurs |
boundaryThe Copied state is reset by another block
| Situation | Outcome |
|---|---|
| the button shows Copied on block A and the pointer enters block B | the button on block B reads Copy code with no check mark |
| the button shows Copied and the pointer stays in the same block | the Copied state is kept until the 1.5 s end |
nominalThe keyboard reaches the button
| Step | Outcome |
|---|---|
| Tab moves focus to a code block | the block shows a focus ring and the Copy code button appears at the same place as on hover |
| Tab is pressed again | focus moves to the button, which shows a focus ring |
| Enter or Space is pressed on the button | the raw code is copied and the button shows Copied |
| Shift+Tab is pressed on the button | focus returns to the block and the button stays shown |
| focus leaves the block and the button | the button is hidden |
refusalBlocks that are not tab stops
Givena block being edited, a code block inside a block editor, or the source of a Mermaid or PlantUML diagram
Whenthe reader tabs through the page
Thenthe block is not a tab stop and no copy button appears for it
Implemented in 2
Tested by 3
Replaces
SwRS-MDOKFSTUDIO-CODE-018Hide the copy button below 30 px of visible block superseded superseded by SwRS-MDOKFSTUDIO-CODE-017 Markdown file
SwRS-MDOKFSTUDIO-CODE-022Offer no copy button for edited blocks, editors, diagram sources and blocks outside the content superseded superseded by SwRS-MDOKFSTUDIO-CODE-017 Markdown file
SwRS-MDOKFSTUDIO-CODE-023Hide the copy button on a click inside the block until the pointer moves superseded superseded by SwRS-MDOKFSTUDIO-CODE-017 Markdown file
SwRS-MDOKFSTUDIO-CODE-024Hide the copy button when a content patch updates the page superseded superseded by SwRS-MDOKFSTUDIO-CODE-017 Markdown file
SwRS-MDOKFSTUDIO-CODE-029Hide the copy button when the pointer leaves the block superseded superseded by SwRS-MDOKFSTUDIO-CODE-017 Markdown file
SwRS-MDOKFSTUDIO-CODE-032Hide the copy button when scrolling stops outside the block superseded superseded by SwRS-MDOKFSTUDIO-CODE-017 Markdown file
SwRS-MDOKFSTUDIO-CODE-033Reposition the copy button on window resize superseded superseded by SwRS-MDOKFSTUDIO-CODE-017 Markdown file
SwRS-MDOKFSTUDIO-CODE-034Keep the copy button clear of the sticky band and toolbar superseded superseded by SwRS-MDOKFSTUDIO-CODE-017 Markdown file
SwRS-MDOKFSTUDIO-CODE-035Reset the Copied state when another block is hovered superseded superseded by SwRS-MDOKFSTUDIO-CODE-017 Markdown file