Behaviour SwRS-MDOKFSTUDIO-LIFE-173
Save key saves the previewed document
When the writer presses the VS Code save key binding with the focus in the side preview, the extension SHALL write the text typed in an open block or table-cell editor to the document and keep that editor open with its caret, write the value typed in an open frontmatter field of the properties table to the document and close that field, then save the document the preview shows.
Part of StRS-MDOKFSTUDIO-BLOCK-008, outside the paths drawn on its map.
Scenarios 2
The situations the tests check; open one to read it.
nominalThe save key saves what the preview shows
| Input | Outcome |
|---|---|
| No editor open in the focused side preview, the writer presses Cmd+S (Ctrl+S off macOS) | The key reaches VS Code, its binding runs `markdown-okf-schema-studio.saveDocument`, the page posts a save request and the host saves the document the preview shows; the dirty mark goes |
| A block editor is open and the writer typed text less than the autosave delay ago | The page writes that text to the document first (an autosave, not a final save), then the host saves; the saved file holds the text, the editor stays open, its text box keeps the focus, its value, its selection and its undo history |
| A table-cell editor is open, same case | The typed cell text is written to the document first, then the document is saved; the cell editor stays open with its caret |
| A frontmatter field of the properties table is open with a typed value | The page writes the value to the document and closes the field, as a navigation does, then the host saves; the saved file holds the value |
| The writer rebinds or unbinds the command in Keyboard Shortcuts | The new key runs the command; the page does not take the key itself |
boundaryWhere the key applies
| Input | Outcome |
|---|---|
| No preview has the focus | The `when` clause is false and VS Code handles the key as before; the command does nothing |
| The page is not ready, or does not answer | When the page cannot be asked, the host saves the document at once; when it does not answer, the host saves after `FLUSH_WAIT_MS` |
| The host still applies an autosave or a frontmatter save | The host waits, bounded by `FLUSH_WAIT_MS`, until the active block edit has no pending text and the tracked saves are done, then saves, so the saved file holds the typed text and the dirty mark does not come back |
| The document is untitled | `save` opens VS Code's Save As dialog; a cancelled dialog or a refused save is silent |
| Format on save or another save participant changes the text | They run as with any save; the preview shows their result as an external change |
| The command is looked for in the Command Palette | It is hidden (`"when": "false"`); the key binding is its only entry |
| The preview is the custom editor | The binding covers it too (`activeCustomEditorId`): the key runs the same command, because the native save of the custom editor did not save the typed text inside the autosave delay |