Behaviour SwRS-MDOKFSTUDIO-PALETTE-058
The Colour picker wraps the selection in a safe colour span
When the writer presses Colour, the extension SHALL open a picker with the tabs Text and Background, sixteen colour swatches, a field for a colour code and a Remove button, apply a swatch, a valid colour code or Remove to the property of the open tab as a span whose only attribute is a colour style, and produce no edit for a value the sanitizer would strip.
Step 1 of path 2 in StRS-MDOKFSTUDIO-PALETTE-007: from “The palette is shown above the text box” to “The colour picker is open”.
Scenarios 7
The situations the tests check; open one to read it.
nominalPicker contents
an open table cell editor
the writer presses Colour in the cell formatting group
the same picker opens
The action is a strict-mode action for blocks and cells with a swatch popover; the sixteen swatches are distinct and each is a colour the sanitizer keeps.
nominalA swatch or a valid code applies the colour of the open tab
the Background tab open
the field holds #c00 and a word is selected
the writer presses a swatch
the writer presses Enter
the span gets a background colour instead
the colour is applied like a swatch and the picker closes
The action receives the argument text:{colour} or background:{colour} and the picker is removed before the edit. The edit is one undo step and keeps the editor open.
refusalInvalid colour code in the field
The field is validated as the writer types too: a non-empty invalid value sets aria-invalid, an empty or valid value removes it; the valid values are the colour grammar of the sanitizer, named colours and hsl() included (see SwRS-MDOKFSTUDIO-GFM-034).
nominalThe span written and updated
In this table `[ ]` marks the selection and `|` marks the caret.
a table cell editor
the action runs
the span is written without escaping any pipe, because it contains none
| Input | Argument | Outcome |
|---|---|---|
| `say [foo] now` | `text:#c00` | say <span style="color:#c00">[foo]</span> now |
| `say [foo] now` | `background:#ff0` | say <span style="background-color:#ff0">[foo]</span> now |
| `say | now` | `text:#c00` | say <span style="color:#c00">|</span> now |
| `a[ foo ]b` (edge blanks ignored) | `text:#c00` | a <span style="color:#c00">[foo]</span> b |
| x <span style="color:#c00">[foo]</span> y (span around the selection) | `text:#00f` | the colour of the same span is replaced, no new span |
| x <span style="color:#c00">f|oo</span> y (caret in the span) | `text:#00f` | the colour is replaced and the caret stays where it was |
| x <span style="color:#c00">[foo]</span> y | `background:#ff0` | `style="color:#c00; background-color:#ff0"`, the same span carries both colours |
| a span with both colours | `background:rgb(1, 2, 3)` | the background colour is replaced, the text colour is kept |
| `[foo]` in a table cell | `text:#c00` | <span style="color:#c00">[foo]</span> |
| a span with a colour, caret in it, in a table cell | `background:#ff0` | `style="color:#c00; background-color:#ff0"` |
The written opening tag is a span element with a single style attribute whose value is color:#c00; with two declarations they are separated by a semicolon and a space, color first. A span is recognised only when its tag has a style attribute with colour declarations the sanitizer keeps, and no other attribute.
boundaryPartial selection and whole content
the whole content of the span selected
a colour is applied
the outer span is updated instead
| Input | Argument | Outcome |
|---|---|---|
| x <span style="color:#c00">a[b]c</span> | `text:#00f` | x <span style="color:#c00">a<span style="color:#00f">[b]</span>c</span>, the outer span is unchanged |
| a[b<span style="color:#c00">cd</span>e]f (balanced span inside the selection) | `text:#00f` | the selection is wrapped in a new span around the balanced span |
nominalRemove drops the property of the open tab
a span with only a text colour and the caret inside
the content selected
a word outside any generated span
the text colour is removed
the colour is removed
the writer presses Remove
the tags are gone, the content stays and the caret stays on its character
the content stays selected
the text is unchanged
The action receives text: or background: with an empty colour; when no property is left the span is unwrapped (the edit replaces the whole span with its inner text); a property the span does not carry, or no generated span, gives no edit.
refusalWhat the sanitizer would strip
a selection that starts inside a span and ends outside it
the colour action runs
no edit is produced, in both directions
| Input | Outcome |
|---|---|
| argument `text:redd`, `text:#12`, `text:#ggg`, `text:url(x)`, `text:#c00;position:fixed`, text:#c00"><script>, `text:rgb(1,2,3`, `text:var(--x)`, `text:#c00 !important`, `sky:#c00`, `#c00`, empty, or no argument | no edit (the colour is invalid or holds a control character) |
| ab<span style="color:#c00">c[d</span>e]f | no edit (selection straddles a span boundary) |
| a[b<span style="color:#c00">c]d</span>ef | no edit (selection straddles a span boundary, the other direction) |
| ab<span style="co[lor:#c00">cd</span>e]f | no edit (a boundary lies inside the text of a tag) |
| a<b onclick="x|y">c</b> | no edit (a boundary lies inside the text of a tag) |
| a slice with an unmatched span tag | no edit |
| the registry built without a colour validator | no edit |
The action returns undefined. Everything the action writes passes the sanitizer grammar (see SwRS-MDOKFSTUDIO-GFM-034).