Behaviour SwRS-MDOKFSTUDIO-PALETTE-276
Inline marker buttons toggle their markers around the selection
When the writer presses Bold, Italic, Strikethrough, Subscript, Superscript, Key or Key (MyST), the extension SHALL wrap the selection, or the word at a collapsed caret, in the markers of that button, remove the markers when they are already there, and produce no edit when the markers cannot be written safely.
Step 2 of path 1 in StRS-MDOKFSTUDIO-PALETTE-019: from “The palette is shown above the text box” to “The selection is wrapped in markers”.
Part of StRS-MDOKFSTUDIO-PALETTE-020, outside the paths drawn on its map.
Part of StRS-MDOKFSTUDIO-PALETTE-021, outside the paths drawn on its map.
Scenarios 9
The situations the tests check; open one to read it.
nominalBold and Italic wrap and unwrap
| Action | Input | Outcome |
|---|---|---|
| Bold | `say [foo] now` | `say **[foo]** now` |
| Italic | `say [foo] now` | `say *[foo]* now` |
| Bold | `say **[foo]** now` (markers outside the selection) | `say [foo] now` |
| Italic | `say *[foo]* now` (markers outside the selection) | `say [foo] now` |
| Bold | `say [**foo**] now` (markers inside the selection) | `say [foo] now` |
| Italic | `say [*foo*] now` (markers inside the selection) | `say [foo] now` |
| Bold | `say **fo|o** now` (caret in the word) | `say fo|o now` |
| Italic | `say *fo|o* now` (caret in the word) | `say fo|o now` |
| Bold | `**foo|**` | `foo|` |
| Bold, then Italic, then Italic, then Bold on `x foo y` with foo selected | `x ***foo*** y` after the first two presses, then `x foo y` with the same selection |
nominalEmpty pair
| Action | Input | Outcome |
|---|---|---|
| Bold | `say | now` | `say **|** now` |
| Italic | `say foo| now` (caret after a word) | `say foo*|* now` |
| Bold | `|` | `**|**` |
| Bold | `x **|** y` (empty pair) | `x | y` |
| Italic | `x *|* y` (empty pair) | `x | y` |
| Strikethrough | `say | now` (caret outside a word) | `say ~~|~~ now` |
| Strikethrough | `x ~~|~~ y` (empty pair) | `x | y` |
nominalBold and Italic share a run of asterisks
the text foo selected inside *foo*
Bold is pressed
the run becomes ***foo***
| Action | Input | Outcome |
|---|---|---|
| Bold | `*[foo]*` | `***[foo]***` |
| Italic | `**[foo]**` | `***[foo]***` |
| Italic | `***[foo]***` | `**[foo]**` |
| Bold | `***[foo]***` | `*[foo]*` |
| Bold | `***fo|o***` | `*fo|o*` |
| Italic | `***fo|o***` | `**fo|o**` |
nominalStrikethrough wraps and unwraps a double tilde pair
the caret inside ~~foo~~
Strikethrough is pressed
the markers are removed and the caret stays in the word
| Input | Outcome |
|---|---|
| `say ~~[foo]~~ now` (markers outside the selection) | `say [foo] now` |
| `say [~~foo~~] now` (markers inside the selection) | `say [foo] now` |
| `say ~~fo|o~~ now` | `say fo|o now` |
| `a[ foo ]b` (blanks at the selection edges are ignored) | `a ~~[foo]~~ b` |
| `[a` newline `b]` (multi-line selection) | `~~[a` newline `b]~~` |
The Strikethrough button has no keyboard shortcut.
nominalSubscript and Superscript wrap the selection in a role
the caret in a table cell editor
Subscript or Superscript is pressed
both buttons work as in a block editor
nominalKey (MyST) wraps the selection in the kbd role
no selection
Key (MyST) is pressed
`{kbd}` with the sample Ctrl+K is inserted with Ctrl+K selected
| Input | Outcome |
|---|---|
| Key (MyST) pressed in a table cell | The action works |
| Key (MyST) pressed on text that already has markup | Unlike Key, it never removes existing markup |
nominalKey wraps the selection in kbd tags
| Input | Outcome |
|---|---|
| The caret with no selection | A kbd element holding Key is inserted with Key selected |
| Key pressed in a table cell editor | Key works in a table cell too |
refusalA selection that cuts into a marker run, or that a role cannot hold
a selection that covers the content with its whole run
a selection that contains a backtick (Subscript, Superscript or Key (MyST)) or a line break (Subscript or Superscript)
Bold is pressed
the button is pressed
the markers are handled as usual
no edit is produced
| Action | Input | Outcome |
|---|---|---|
| Bold | `**f[oo]**` | no edit |
| Italic | `*[fo]o*` | no edit |
| Bold | `[*foo*]` (selection includes the markers) | not refused: the markers are handled as usual (this input is untested) |
| Superscript | a selection that contains a backtick | no edit |
| Key (MyST) | a selection that contains a backtick | no edit |
boundaryEdges, lines and other markers
| Action | Input | Outcome |
|---|---|---|
| Bold | `a[ foo ]b` (blanks at the selection edges) | `a **[foo]** b` (the markers go around the trimmed content) |
| Bold | `**a**[ b ]**c**` (blanks between two spans) | `**a** **[b]** **c**` (not a wrapped selection) |
| Bold | `[a` newline `b]` (multi-line selection) | `**[a` newline `b]**` (one span) |
| Bold | `[_foo_]` (underscores) | `**[_foo_]**` (underscores are not recognised as markers and stay in place) |
A run holds bold when it has two or more asterisks and italic when its length is odd.