Behaviour SwRS-MDOKFSTUDIO-TRUST-065
A page message is matched to the shown render or document by the gate of its type
When a page message reaches the host, the extension SHALL pass it only to the handler of its type after it matches the render or document the host holds by the gate of that type (render, comment, document, own-id or page-state), drop a message that fails the gate without an answer, and answer a write whose document is newer than the render with "The preview is out of date. Try again once it has refreshed." or a reopen hint.
Part of StRS-MDOKFSTUDIO-BLOCK-006, outside the paths drawn on its map.
Part of StRS-MDOKFSTUDIO-BLOCK-014, outside the paths drawn on its map.
Part of StRS-MDOKFSTUDIO-BLOCK-016, outside the paths drawn on its map.
Part of StRS-MDOKFSTUDIO-BLOCK-025, outside the paths drawn on its map.
Part of StRS-MDOKFSTUDIO-TOOLBAR-011, outside the paths drawn on its map.
Step 2 of path 1 in StRS-MDOKFSTUDIO-TRUST-009: from “The message is a registered one” to “The message reaches the handler of its type”.
Scenarios 6
The situations the tests check; open one to read it.
nominalCurrent render passes the render gate
boundaryThe five gates
Every page message type has one gate. A message with a registered type and a valid envelope (see SwRS-MDOKFSTUDIO-TRUST-052) is matched by it:
| Gate | Message types | Passes when | Otherwise |
|---|---|---|---|
| render | previewHistoryGo, previewViewPreferenceChanged, previewPaletteModeChanged, previewLabelRename, previewThreadReply, previewThreadDelete, previewBlockMove, previewBlocksCopy, previewBlocksCut, previewBlocksPaste, previewListTargets, previewListCitations, previewPickDocument, previewPickImage, previewPasteImage, previewPasteHtml | its document, revision and request identifiers equal those of the render the host holds, the preview is alive and has a rendered stage | dropped with no change; a request that waits for an answer (see the scenario below) is answered with the out-of-date reason, previewHistoryGo, previewViewPreferenceChanged and previewPaletteModeChanged are not requests and get no answer |
| comment | previewCommentCreate, previewCommentReply, previewCommentResolve, previewCommentDelete | its document and request identifiers equal those of the render the host holds, whatever its revision (comments live in a sidecar file and the quote is anchored again, so typed text is not lost to a race with typing) | dropped, with no answer and no write |
| document | previewCopyText, previewPlantUmlInclude, previewShowProblems, previewWarningBannerClosed | the preview is alive and its documentId equals that of the document the preview shows, even one render behind; revision and request are not compared | dropped without an answer |
| own-id | previewEditClosed, previewEditFlushed | the preview is not disposed, whatever document, revision and request the message names (the waiting host matches the answer by the identifier it sent) | dropped (disposed preview) |
| page-state | previewReady, previewScroll, previewReveal, previewState, previewLink, previewLinkDiscover, previewThemeModeChanged, previewRefresh, previewAnchorModeChanged, previewEditModeChanged, previewEditOpen, previewEditSave, previewEditCancel, previewFrontmatterSave, previewCheckboxToggle | it names the render the host holds, or it is one of the exceptions below | dropped without changing anything |
The page-state exceptions are the ready reports (see SwRS-MDOKFSTUDIO-LIFE-071), the save or cancel of the block editor the host has open for exactly the render that message names (same editId, document, revision and request), and the stale save, cancel or frontmatter save of the second table.
refusalOlder render is answered, foreign render is dropped
| Input | Outcome |
|---|---|
| previewBlockMove naming revision 3 while the host holds revision 4 | answered with previewBlockMoveResult ok false and "The preview is out of date. Try again once it has refreshed."; nothing changes |
| previewBlockMove, previewBlocksCopy, previewBlocksCut or previewBlocksPaste naming an earlier request id | answered with ok false and the out-of-date reason (previewBlocksResult carries the operation); nothing changes |
| previewThreadReply, previewThreadDelete, previewListTargets, previewListCitations, previewPickDocument, previewPickImage, previewPasteImage or previewPasteHtml naming an older render | answered with its Result message, ok false and the out-of-date reason; no file is read and no dialog is opened, and the page clears its pending request |
| previewEditOpen or previewCheckboxToggle naming an older render of a preview | answered with the out-of-date reason (the block editor error, the checkbox error); for the open, the frame of the block editor shows the reason and can be left (see SwRS-MDOKFSTUDIO-BLOCK-216) |
| a request of the render gate naming another document, or of a disposed preview | dropped without an answer |
| previewCopyText of a page whose document version or render request is no longer current | handled: the text is written to the clipboard and the page is answered, because a copy edits nothing |
| previewCopyText naming another document | dropped, the clipboard is not written |
| previewLink with another document identity, revision or request than the host render | ignored: nothing opens and nothing is recorded |
| previewLink after the preview was disposed | ignored: nothing happens |
| message of a disposed preview, or of a preview without a rendered stage | dropped |
| previewCommentReply naming another request | dropped, nothing is written |
| previewCommentCreate naming another document id | dropped, nothing is written |
| previewScroll naming request 8 while the host holds request 9 | dropped, the text editor does not scroll |
| previewLabelRename for a stale render revision | answered with ok false and The label is no longer on that line. Refresh the preview.; nothing is written |
| previewPlantUmlInclude, previewShowProblems or previewWarningBannerClosed naming another document | dropped without an answer |
| previewEditFlushed or previewEditClosed on a disposed preview | dropped |
nominalGates that accept an older revision
| Input | Outcome |
|---|---|
| previewCommentCreate naming revision 3 of the same render while the host holds revision 4 | the handler runs and the thread is written and answered ok |
| previewWarningBannerClosed for the shown document from a preview one render behind | the handler runs |
| previewPlantUmlInclude addressed to the current document from a page one render behind | the include is answered |
| previewEditFlushed or previewEditClosed naming an older render, on a live preview | the handler runs and the waiting host continues |
| previewEditSave of the block editor opened on revision 3 after the document moved to revision 4, same editId | accepted |
| previewListTargets, previewListCitations, previewPickDocument or previewPickImage naming render 3 while the block editor the host holds is open on render 3 and its own saves moved the document to revision 4 | the request is answered as for a current preview (the preview refreshes only when the editor closes) |
refusalStale write answered out of date or with a reopen hint
A message that passes its gate but writes for a document newer than the render is answered with a reason and changes nothing. The page-state gate answers a stale save or cancel of a live preview instead of dropping it:
| Request | Stale case | Answer |
|---|---|---|
| previewBlockMove | the document was edited after the last render | ok false, "The preview is out of date. Try again once it has refreshed."; a render of the current text plans the move |
| previewBlocksCopy, previewBlocksCut, previewBlocksPaste | the document changed since the render | ok false, "The preview is out of date. Try again once it has refreshed."; a render of the current text plans the copy |
| previewLabelRename | the document was edited after rendering | "The preview is out of date. Try again once it has refreshed." and nothing changes |
| previewListTargets | the document is no longer the one of the render, or was edited after it with no block editor open on that render | ok false, "The preview is out of date. Try again once it has refreshed."; an unedited document answers the labels |
| previewListCitations | the document is no longer the one of the render, or was edited after it with no block editor open on that render | ok false, "The preview is out of date. Try again once it has refreshed." and no file is read; an unedited document answers the keys |
| previewPickImage | the preview is out of date (no block editor open on that render), or the document is an untitled document that is not a saved Markdown file | "The preview is out of date, or the document is not a file." and the dialog is not opened |
| previewPickDocument | the preview is out of date (no block editor open on that render), or the document is not a saved Markdown file | "The preview is out of date, or the document is not a file." and the dialog is not opened |
| previewThreadReply, previewThreadDelete | the request names another revision of the document than the host holds | "The preview is out of date. Try again once it has refreshed." and nothing changes; a request naming the current revision is handled |
| previewEditSave, previewEditCancel (block editor) | the editor was opened on an older page than the host holds | "The preview changed while this block was being edited. Copy your text, then reopen the block." |
| previewFrontmatterSave | the editor was opened on an older render (render 1 while the host shows render 2 of the same document) | "The preview changed while this field was being edited. Reopen the field." and the document is unchanged |
refusalNo stale answer where none is owed
| Input | Outcome |
|---|---|
| stale previewFrontmatterSave naming another document | no answer is sent |
| stale save of a disposed preview | no stale answer is sent |
| stale previewScroll or any other page-state message that is not a save, cancel or frontmatter save | dropped without an answer |
Implemented in 5
Tested by 12
- test/host/fmtableReq.requirements.test.tsunit
- test/integration/blockClipboard.test.tsintegration
- test/integration/blockMove.test.tsintegration
- test/integration/commentWrite.test.tsintegration
- test/integration/labelRename.test.tsintegration
- test/session/blockReq.requirements.test.tsunit
- test/session/diagReq.plantuml.requirements.test.tsunit
- test/session/paletteReq.requirements.test.tsunit
- test/session/renderReq.codeCopy.requirements.test.tsunit
- test/session/reviewReqThreads.requirements.test.tsunit
- test/session/toolbarReq.requirements.test.tsunit
- test/session/trustReq.requirements.test.tsunit
Known limits (1)
- the include request (previewPlantUmlInclude) is not an edit: it is allowed in Restricted Mode and for a standalone file.