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
boundaryWhere the button shows and hides
In this table `|` marks the caret.
| Input | Button |
|---|---|
| `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
| Input | Argument | Outcome |
|---|---|---|
| `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
| Input | Argument | Outcome |
|---|---|---|
| `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 argument | no edit |
nominalCaret leaves the code
boundaryCaret stays in the code
updateAvailability hides the button and calls closePopover when the open button is the hidden one.