Behaviour SwRS-MDOKFSTUDIO-BLOCK-191
The host holds an open block edit and ends it when the block changes
When a block editor saves for the first time, the host SHALL hold an edit lock for that block, and release it, running the page work that waited for it, when the final save is applied, the page reports the close of the editor or a reload, or the block changes in the document; a change inside the open block ends the edit with an error and keeps the text the writer typed.
Part of StRS-MDOKFSTUDIO-BLOCK-006, outside the paths drawn on its map.
Scenarios 11
The situations the tests check; open one to read it.
nominalFirst and later saves
| Input | Outcome |
|---|---|
| An editor that posted its first autosave, the host handles it | The host holds an edit with the block's offset and the original text taken from the document |
| A held edit and a second save of the same editor | The original text is not read from the document again; the held edit and its last written text are used |
A first save that does not match the document is refused, see SwRS-MDOKFSTUDIO-BLOCK-216.
nominalThe final save or a cancel releases the lock
Givena held edit with queued page work
Whenthe final save is applied, or a cancel writes the original text back
Thenthe lock is released and the queued work runs, newest render last
nominalThe host asks once per editor to report its close
| Input | Outcome |
|---|---|
| An open editor and a render to defer, the work is queued | previewEditorWatch with the editor id is posted |
| More work queued for the same editor | No second watch is posted |
nominalThe page reports the close of a watched editor
| Input | Outcome |
|---|---|
| An open editor the host watches closes unchanged | previewEditClosed with its id is posted although no save was sent |
| A watch for an editor that is already closed, also for the next document | previewEditClosed is posted at once |
| An editor the host does not watch closes | The close stays silent |
boundaryThe close of another editor releases nothing
| Input | Outcome |
|---|---|
| An open editor and previewEditClosed of another editor id | The work keeps waiting |
| previewEditClosed of the open editor | The work runs |
boundaryA reloaded page releases the lock
| Input | Outcome |
|---|---|
| A held edit and a previewReady with another requestId | The lock is released and the queued work runs, so another block can be edited |
| A previewReady of the same render that reports no open editor | The lock is released |
| A previewReady of the same render that reports an open editor | The lock is kept |
| A previewReady without a lock | Nothing is released |
| Time passes with no event | The lock is not released |
boundaryA change outside the open block
| Input | Outcome |
|---|---|
| Three characters inserted above the block in the text editor | The block offset grows by 3 and the editor stays open |
| A change at or after the end of the block | The offset is unchanged |
| Several changes in one event | They add up; their offsets refer to the text before the event |
refusalA change inside the open block
| Input | Outcome |
|---|---|
| A change that lies inside or across the block | The editor shows "The source block changed outside the preview while it was being edited. Copy your text, then reopen the block." with the typed text kept, and the lock is free for a new edit |
| An insertion editor (an empty block) and a change elsewhere | No conflict is reported; only a change at its own offset conflicts |
boundaryA table cell editor
| Input | Outcome |
|---|---|
| A held edit of a table cell editor and an outside change (undo, redo, revert) that overlaps its table | No error is shown: the edit is released without writing and the render of the buffer reaches the page, whose content patch closes the editor (SwRS-MDOKFSTUDIO-TABLE-119); the text was autosaved live, so the buffer already holds it |
| The same change over a prose block editor | The conflict above applies |
boundaryThe page closed the editor during its final save
| Input | Outcome |
|---|---|
| previewEditClosed with detached for the editor of the held edit | The edit completes with no restore and is always answered with previewEditSource done |
| An open that arrives while the edit is detached | It is held, at most one: a later open replaces it and the replaced one is answered "Another Markdown block is already being edited."; it is handled with its usual checks when the edit succeeds and refused when it fails |
| A previewReady that reports an open editor while the edit is detached | The lock is kept |
| A previewReady that reports none, a page replaced or a document switch | The detached edit is released |
| The release of a detached edit while a newer page editor is recorded | Only the host hold is freed; the render keeps waiting for the newer editor |
| A failure or an outside change of a detached edit | The page editor lock of the failed edit is kept until previewEditReopen; with reopened false the edit is released, the preview renders and the Copy text warning is shown |
refusalAn outside change during a final save keeps the text unwritten and the editor open
Givena held edit whose final save is requested and not written
Whenthe document changes from outside the preview
Thennothing is written, the page gets the error with the text, the host edit is released with the page editor kept and the render waits