Markdown OKF-Schema Studio

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
InputOutcome
An editor that posted its first autosave, the host handles itThe 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 editorThe 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
InputOutcome
An open editor and a render to defer, the work is queuedpreviewEditorWatch with the editor id is posted
More work queued for the same editorNo second watch is posted
nominalThe page reports the close of a watched editor
InputOutcome
An open editor the host watches closes unchangedpreviewEditClosed with its id is posted although no save was sent
A watch for an editor that is already closed, also for the next documentpreviewEditClosed is posted at once
An editor the host does not watch closesThe close stays silent
boundaryThe close of another editor releases nothing
InputOutcome
An open editor and previewEditClosed of another editor idThe work keeps waiting
previewEditClosed of the open editorThe work runs
boundaryA reloaded page releases the lock
InputOutcome
A held edit and a previewReady with another requestIdThe lock is released and the queued work runs, so another block can be edited
A previewReady of the same render that reports no open editorThe lock is released
A previewReady of the same render that reports an open editorThe lock is kept
A previewReady without a lockNothing is released
Time passes with no eventThe lock is not released
boundaryA change outside the open block
InputOutcome
Three characters inserted above the block in the text editorThe block offset grows by 3 and the editor stays open
A change at or after the end of the blockThe offset is unchanged
Several changes in one eventThey add up; their offsets refer to the text before the event
refusalA change inside the open block
InputOutcome
A change that lies inside or across the blockThe 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 elsewhereNo conflict is reported; only a change at its own offset conflicts
boundaryA table cell editor
InputOutcome
A held edit of a table cell editor and an outside change (undo, redo, revert) that overlaps its tableNo 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 editorThe conflict above applies
boundaryThe page closed the editor during its final save
InputOutcome
previewEditClosed with detached for the editor of the held editThe edit completes with no restore and is always answered with previewEditSource done
An open that arrives while the edit is detachedIt 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 detachedThe lock is kept
A previewReady that reports none, a page replaced or a document switchThe detached edit is released
The release of a detached edit while a newer page editor is recordedOnly the host hold is freed; the render keeps waiting for the newer editor
A failure or an outside change of a detached editThe 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

Implemented in 5

Tested by 6