Markdown OKF-Schema Studio

Behaviour SwRS-MDOKFSTUDIO-PALETTE-203

A pasted image is sent to the host and its name inserted on its own paragraph

When the writer pastes into the block text box a clipboard that holds no text and a png, jpeg, gif or webp file of at most 10 MB, the extension SHALL take over the paste, remember the selection, read the first such file as base64, send it to the host with its type, and when the host answers a file name replace the remembered selection with ![name](name) as a paragraph of its own, showing any refusal or read failure in the status line and inserting nothing.

Step 1 of path 1 in StRS-MDOKFSTUDIO-PALETTE-018: from “A block text box is open in edit mode” to “The host receives the image”.

Scenarios 5

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

nominalA screenshot is saved and inserted
Givena clipboard with one png file and no text, and a block editor with a selection
that request
Whenthe writer pastes
the host answers image.png
Thenthe default paste is prevented, the selection is remembered, the status line shows Saving image… and previewPasteImage is posted with the type image/png and the base64 data
the reference is inserted over the remembered selection (not the live one), the edit is autosaved and the status line shows its usual text again

The host side of this request is SwRS-MDOKFSTUDIO-PALETTE-196; the answer correlation is SwRS-MDOKFSTUDIO-TRUST-090.

boundaryWhat the paste hook takes over
ClipboardOutcome
text and an imagethe paste stays native and nothing is sent to the host (text wins)
an item of another type, such as svgthe item is ignored and the paste stays native
no file at allthe paste stays native
several png, jpeg, gif or webp files, no textthe first such file is read and sent
an image of 1 MBthe image is sent to the host
an image of 11 MBthe paste is prevented, the status line shows The image is larger than 10 MB and was not pasted. and nothing is posted (the limit is 10 times 1024 times 1024 bytes)
refusalThe image cannot be read or the host refuses it

Each case inserts nothing. The status line changes only while the editor and text box that received the paste are the open ones and not finishing.

CaseStatus line
the file reader fails (a failing reader)The image could not be read. (nothing is posted)
the editor closed meanwhile and the reader failsnot touched
the host answers a refusal with a reasonthat reason
the host answers a refusal without a reasonThe image was not saved.
the host answers an edit id that is not the pending oneignored
the editor closed or is finishing when the answer arrivesnot touched and nothing is inserted
nominalThe reference goes on a paragraph of its own

The alternative text equals the file name; no dialog asks for it.

Text around the selectionResult
caret at the end of a paragrapha blank line and the reference follow the paragraph, and a blank line follows the reference unless it ends the text
caret in the middle of a linethe line is split around a paragraph that holds only the reference
caret at the start of the textno blank line before the reference
blank lines already therethey are reused, not doubled
the paragraph ends with a typed space, or spaces and tabs surround the caretthe spaces and tabs around the paste position go with the break, so no line keeps trailing blanks; line breaks are kept
caret directly at the endthe text before it is unchanged
boundaryThe selection and the positions
Remembered selectionOutcome
a selection of two wordsthe selection is replaced by the paragraph and the file name inside the reference is selected
a position beyond the textthe positions are clamped to the length of the text

Implemented in 1

Tested by 3