Markdown OKF-Schema Studio

Behaviour SwRS-MDOKFSTUDIO-PALETTE-069

The Colour code button edits a colour code at the caret

When the caret or selection lies inside a #rgb, #rrggbb or rgb() colour code that is not part of a word or a character reference, the extension SHALL show the Colour code button with a swatch of that colour, hide it otherwise, and let its picker, started on the colour of the code with no tabs and no Remove button, replace the code under the caret in place and close when the caret leaves the code.

Part of StRS-MDOKFSTUDIO-PALETTE-007, outside the paths drawn on its map.

Scenarios 6

The situations the tests check; open one to read it.

nominalCaret in a code
Giventhe text color #1e88e5 with the caret inside the code
Whenthe caret moves into the code
Thenthe Colour code button appears and its swatch shows the colour
boundaryWhere the button shows and hides
Giventhe text { with the caret inside
Whenthe caret moves
Thenthe button stays hidden

In this table `|` marks the caret.

InputButton
`a #c00| b` (right edge)shown
`a |#c00 b` (left edge)shown
`a #c|c0000 b`shown
`a rgb(1, 2,| 3) b`shown
`a |rgba(1,2,3,0.5)`shown
`a| #c00 b` (one space before)hidden
`a #c00 |b` (one space after)hidden
`a #c0| b` (two digits)hidden
`a #c00x| b` (followed by a letter)hidden
`a x#c00| b` (preceded by a letter)hidden
`a #ccccc| b` (five digits)hidden
`a rgb(300,0,0)| b` (out of range)hidden
`a rgb(1,2| b` (unclosed)hidden
`plain| text`hidden
`{` with the caret inside (character reference)hidden

The code must be accepted by the colour grammar of the sanitizer (hex with 3, 4, 6 or 8 digits, rgb, rgba), a hex code must not be preceded by a word character, an ampersand or a hash and not followed by a word character; the button follows keyup, mouseup and select events.

nominalThe picker starts on the code and replaces it in place
Giventhe caret in #c00
Whenthe picker is opened and a swatch is chosen
Thenthe code is replaced by the swatch colour with the caret after it
InputArgumentOutcome
`a #c0|0 b``#00f``a #00f| b`
`a rgb(1, 2, 3)| b``#ff8800``a #ff8800| b`

The popover has no element with data-color-tab and none with data-color-remove, and the field starts with the code; the field takes the focus without saving.

refusalInvalid colour code
Giventhe same picker
Whenan invalid colour code is typed and Enter is pressed
Thennothing is replaced and the field is marked aria-invalid
InputArgumentOutcome
`a #c0|0 b``red`no edit
`a #c0|0 b``rgb(1,2,3);"`no edit
`a plain| b` (no code at the caret)`#00f`no edit
`a #c0|0 b`no argumentno edit
nominalCaret leaves the code
Giventhe picker open on a colour code
Whenthe caret moves out of the code
Thenthe button is hidden and the picker is closed
boundaryCaret stays in the code
Giventhe picker open
Whenthe caret moves inside the code
Thenthe picker stays open

updateAvailability hides the button and calls closePopover when the open button is the hidden one.

Implemented in 1

Tested by 3