Markdown OKF-Schema Studio

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
BlockOutcome
a block that is open for editingno copy button appears
a code block inside a block editorno copy button appears
the source of a Mermaid or PlantUML diagramno copy button appears
a code block in the toolbar or a panel outside the preview contentno 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
SituationOutcome
the button is shown and the block scrolls under the sticky band to 29 px visiblethe button is hidden
the block scrolls back to exactly 30 px visible with the pointer over itthe button is shown again
the window is resized and the button is shownthe button moves to 6 px inside the resized block's top-right corner
the resize leaves less than 30 px of the block visiblethe button is hidden
several scroll events arrive before the next animation framethe button is placed once, in that frame, for the block's position then
boundaryEvents that hide the button
EventOutcome
the reader clicks inside the hovered blockthe button is hidden until the pointer moves again; a pointer move within the block shows it again
the pointer leaves the blockthe button is hidden
the pointer moves from the block onto the buttonthe mouseout fires and the button stays shown
scrolling stops for 120 ms with the pointer outside the hovered blockthe button is hidden
scrolling stops for 120 ms with the pointer still over the blockthe button stays shown
a content patch updates the preview in place while the button is shownthe button is hidden
a content patch is applied while no button is shownnothing changes and no error occurs
boundaryThe Copied state is reset by another block
SituationOutcome
the button shows Copied on block A and the pointer enters block Bthe button on block B reads Copy code with no check mark
the button shows Copied and the pointer stays in the same blockthe Copied state is kept until the 1.5 s end
nominalThe keyboard reaches the button
StepOutcome
Tab moves focus to a code blockthe block shows a focus ring and the Copy code button appears at the same place as on hover
Tab is pressed againfocus moves to the button, which shows a focus ring
Enter or Space is pressed on the buttonthe raw code is copied and the button shows Copied
Shift+Tab is pressed on the buttonfocus returns to the block and the button stays shown
focus leaves the block and the buttonthe 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