Behaviour SwRS-MDOKFSTUDIO-LIFE-169
A view choice made on the page is stored for the workspace
When the writer changes a view choice on the page, the extension SHALL keep it in the saved state of the panel, post it to the host with the identity of the page, and let the host validate it and store it for the workspace according to the table of view choices.
Step 1 of path 2 in StRS-MDOKFSTUDIO-LIFE-014: from “The reader changes a view choice on the page” to “The view choice is stored”.
Another outcome at step 2 of path 1 in StRS-MDOKFSTUDIO-BLOCK-001, in the state “Edit mode is on”.
Scenarios 12
The situations the tests check; open one to read it.
nominalOne row per view choice
Givena preview with the identity of its current render
Whenthe writer changes one of the view choices of the table
Thenthe page writes the saved-state field of the row next to the other saved fields, posts the message of the row with the document, revision and request identity of the page, and the host stores the value under the storage key of the row
| View choice | Page control | Saved-state field | Message and field | Accepted values | Host validation | Storage key | Preview with restricted reads |
|---|---|---|---|---|---|---|---|
| Edit mode | Edit button | editMode | previewEditModeChanged, editMode | boolean | Dropped unless the value is a boolean | markdownOkfSchemaStudio.editMode | Stored like any other |
| Palette mode | Mode select of the block editor | paletteMode | previewPaletteModeChanged, mode | strict, gfm, myst, full | Dropped unless the mode is one of the four | markdownOkfSchemaStudio.paletteMode | Stored like any other |
| Theme mode | Theme button | previewThemeMode | previewThemeModeChanged, previewThemeMode | current, dark, white, cream | Dropped unless the value is one of the four | previewThemeMode | Stored |
| Zoom | Zoom in and Zoom out | viewZoom | previewViewPreferenceChanged, preference zoom | integer from 70 to 200 | Refused outside the range or when not an integer | markdownOkfSchemaStudio.viewPreferences, field zoom | Stored |
| Width mode | Width button | viewWidthMode | previewViewPreferenceChanged, preference widthMode | margin, auto, full | Refused for any other value | markdownOkfSchemaStudio.viewPreferences, field widthMode | Stored |
| Table of contents | Table of contents button | viewToc | previewViewPreferenceChanged, preference toc | boolean | Refused when not a boolean | markdownOkfSchemaStudio.viewPreferences, field toc | Stored |
| Toolbar collapsed | Chevron of the toolbar | viewToolbarCollapsed | previewViewPreferenceChanged, preference toolbarCollapsed | boolean | Refused when not a boolean | markdownOkfSchemaStudio.viewPreferences, field toolbarCollapsed | Stored |
| Comments | Comments button | viewComments | previewViewPreferenceChanged, preference comments | boolean | Refused when not a boolean | markdownOkfSchemaStudio.viewPreferences, field comments | Stored |
| Incoming changes | Diff button | viewIncomingChanges | previewViewPreferenceChanged, preference incomingChanges | boolean | Refused when not a boolean | markdownOkfSchemaStudio.viewPreferences, field incomingChanges | Stored |
| Anchor mode | Anchor button | anchorToEditor | previewAnchorModeChanged, anchorToEditor | boolean | Dropped unless the value is a boolean | None: set as scrollPreviewWithEditor in the configuration and the loaded context of that preview only | Applied to that preview |
nominalThe page keeps its saved state
Givena saved state that already holds scroll fields and other view fields
Whenthe writer presses the Theme button, the Edit button, a Zoom button, the Width button, the Table of contents button or the chevron, or the page writes a state snapshot
Thenthe saved state holds the new value (previewThemeMode dark after Current, editMode true then false on two presses, viewZoom 110 from 100, viewWidthMode auto from margin, viewToc true, viewToolbarCollapsed true then false on a second press with a second message of value false) and keeps its other fields; after a patch to a newer revision the message carries the identity the patch moved the page to (untested for this message); the snapshot keeps previewThemeMode (cream in Cream mode), the TOC visibility and the folded sections
nominalThe host stores a preference as one normalized object
Givena workspace storage and a previewViewPreferenceChanged message with preference toc and value true
Whenthe host handles the message
Thenthe session preferences hold toc true and the key markdownOkfSchemaStudio.viewPreferences holds the whole normalized preferences object, not the one field
nominalThe host remembers a valid theme, edit mode or palette mode
Givenan open preview whose workspace holds no stored value
Whenthe page reports previewThemeModeChanged dark, previewEditModeChanged with editMode true, or previewPaletteModeChanged gfm
Thenthe value is held for the session where the row says so, written to the workspace storage, and carried by the boot context of the next page of the workspace (the theme mode dark; the palette mode gfm wins over the setting)
boundaryZoom and own-key rows of a view preference message
| Input | Outcome |
|---|---|
| zoom 70, 130 and 200 | all three are accepted |
| zoom 60, 210, 1.2, the text 100 and NaN | all five are dropped without an answer and the stored zoom is unchanged |
| toc, incomingChanges, comments and toolbarCollapsed with a boolean; widthMode margin, auto or full | each message is accepted |
| toc of the string true, comments of 1, widthMode wide or the number 1 | each message is refused and the host does not change a preference |
| an unknown preference name, or a name that is not an own key of the validators | refused |
boundaryNo change, no message
Givena page at 200 percent zoom, or a page that has just started
WhenZoom in is clicked at 200 percent, or nothing is clicked, or the page calls setMode on the palette
Thenno zoom message and no previewPaletteModeChanged message is posted; a chosen palette mode in the select posts exactly one previewPaletteModeChanged (from the GFM mode choosing MyST: one message with mode myst, saved state paletteMode myst)
refusalThe host refuses a value outside the table
Givenan open preview
Whena message arrives with the width mode wide, a zoom outside 70 to 200, a preference name that is not in the table, a theme mode that is not one of the four, a palette mode that is not strict, gfm, myst or full, or an editMode or anchorToEditor that is not a boolean
Thenthe message is refused or ignored by the validator of its type and the stored value is unchanged
refusalA stale message stores nothing where the row says so
Givena message that names an older render than the page now holds, or an edit mode or palette mode report whose value is invalid
Whenthe host receives it
Thenthe stale message is dropped before its handler (by the page-state gate for previewThemeModeChanged, previewEditModeChanged and previewAnchorModeChanged, by the render gate for previewViewPreferenceChanged and previewPaletteModeChanged), an invalid edit mode or palette mode is not stored, and no preference changes
boundaryThe storage is missing or rejects the write
Givenworkspace storage whose update fails, or choices whose storage is not loaded or was released at deactivation
Whenthe host stores a theme mode or a view preference picked by the reader
Thenthe value is held for the session, a rejected write is logged to the output channel of the extension as "Failed to persist the Markdown preview theme mode." or "Failed to persist the Markdown preview view preferences." and shows the reader one warning, "The Markdown preview could not save your display choice; it holds until VS Code closes.", repeated only after a write succeeded in between, and with no storage nothing is written and nothing is logged
boundaryStored preferences are normalized field by field
| Stored value | Outcome |
|---|---|
| widthMode bad and toc true | widthMode margin, toc stays true (only the bad field is replaced) |
| A list, or missing | Every field has its default: zoom 100, widthMode margin, toc off, incomingChanges on, comments on, toolbarCollapsed on |
| Any applied preference | The whole object is normalized again (applyViewPreference), so the stored object is always valid |
refusalA palette mode or a theme mode outside the four is dropped
Givena workspace whose stored palette mode is gfm and an open preview
Whenthe page posts previewPaletteModeChanged with a mode of the table, or previewThemeModeChanged with a theme mode of the table
Thenthe message is rejected by the protocol validator of its type, nothing is stored, no result is posted to the page, and the next preview still starts in the stored mode
| Message | Field value | Outcome |
|---|---|---|
| previewPaletteModeChanged | html | rejected |
| previewPaletteModeChanged | the empty text | rejected |
| previewPaletteModeChanged | a number or true (not a string) | rejected |
| previewPaletteModeChanged | missing | rejected |
| previewThemeModeChanged | sepia (or neon) | rejected |
| previewThemeModeChanged | missing previewThemeMode | rejected |
nominalAn accepted palette mode or theme mode
Givena palette whose select changes to another of the modes strict, gfm, myst or full, or the Theme button pressed (any of current, dark, white and cream)
Whenthe page posts the message once, with the identity fields documentId, revision and requestId (the envelope is checked first, see SwRS-MDOKFSTUDIO-TRUST-052) and the field mode or previewThemeMode
Thenthe host accepts it through the gate of its type (see SwRS-MDOKFSTUDIO-TRUST-065), stores the mode for the workspace, and the next preview starts in it (see SwRS-MDOKFSTUDIO-LIFE-170)
Implemented in 14
- src/core/protocol/pageToHost.ts
- src/core/state/previewViewPreferences.ts
- src/page/features/anchorMode.ts
- src/page/features/blockSourceEditor.ts
- src/page/features/editMode.ts
- src/page/features/themeMode.ts
- src/page/modules/editPalette.ts
- src/page/modules/tocColumn.ts
- src/page/modules/toolbarCollapse.ts
- src/page/modules/viewControls.ts
- src/page/modules/widthMode.ts
- src/session/features/scrollSync.ts
- src/session/features/viewState.ts
- src/session/workspaceChoices.ts
Tested by 15
- test/core/protocol/pageStateMessages.test.tsunit
- test/core/protocol/pageToHost.test.tsunit
- test/core/state/previewTheme.test.tsunit
- test/core/state/previewViewPreferences.test.tsunit
- test/integration/lifecycle.test.tsintegration
- test/integration/paletteMode.test.tsintegration
- test/integration/previewEditing.test.tsintegration
- test/page/blockReq.requirements.test.tsunit
- test/page/modules/editPalette.test.tsunit
- test/page/modules/tocColumn.test.tsunit
- test/page/runtimeEditPalette.test.tsunit
- test/page/runtimePageControls.test.tsunit
- test/page/runtimeScroll.test.tsunit
- test/session/blockReq.requirements.test.tsunit
- test/session/diagReq.viewState.requirements.test.tsunit
Replaces
SwRS-MDOKFSTUDIO-LAYOUT-021A width mode choice is saved for the workspace superseded superseded by SwRS-MDOKFSTUDIO-LIFE-169 Markdown file
SwRS-MDOKFSTUDIO-PALETTE-010An unknown palette mode is refused and stores nothing superseded superseded by SwRS-MDOKFSTUDIO-LIFE-169 Markdown file
SwRS-MDOKFSTUDIO-THEME-013The host drops a theme-mode message with an unknown mode superseded superseded by SwRS-MDOKFSTUDIO-LIFE-169 Markdown file
SwRS-MDOKFSTUDIO-TOOLBAR-013The host accepts only a known view preference with a valid value superseded superseded by SwRS-MDOKFSTUDIO-LIFE-169 Markdown file