Behaviour SwRS-MDOKFSTUDIO-LIFE-003
Open Preview to Side opens or reveals a side preview
When a reader runs Open Preview to Side on a saved Markdown file, the extension SHALL show that file in the side preview that follows the active editor, by creating that preview beside the active editor when none is open and otherwise revealing it, and offer the command only for a resource whose extension is .md; the extension SHALL preview only a saved file with the extension .md, taken from the active editor (a text editor, a text diff, or the Studio Open With tab) or from a file URI the command receives, ignore an argument that is not a URI of the file scheme, and otherwise show the message Open a Markdown file to use Markdown OKF-Schema Studio. or the error Cannot open {path}: {reason} and open no preview.
Step 1 of path 1 in StRS-MDOKFSTUDIO-LIFE-001: from “A saved Markdown file is the active editor” to “A side preview is open beside the editor”.
Step 1 of path 1 in StRS-MDOKFSTUDIO-LIFE-003: from “A saved Markdown file is the active editor” to “A side preview shows the file”.
Scenarios 16
The situations the tests check; open one to read it.
nominalEntry points of the command
| Entry point | Declaration | ||
|---|---|---|---|
| Command | markdown-okf-schema-studio.openPreview, title Open Preview to Side, category Markdown OKF-Schema Studio, icon $(book), enablement resourceExtname == .md | ||
| Command Palette | Open Preview to Side and Refresh Preview, when resourceExtname == .md | ||
| Explorer context menu | Open Preview to Side, when resourceExtname == .md, group navigation | ||
| Editor title bar | the book button, when resourceExtname == .md && (activeEditor == workbench.editors.files.textFileEditor | activeEditor == workbench.editors.textDiffEditor), group navigation; it runs Open Preview to Side | |
| Keybinding | Ctrl+K Shift+V (Cmd+K Shift+V on macOS), when editorTextFocus && resourceExtname == .md |
boundaryResource that is not offered the command
| Input | Outcome |
|---|---|
| the active resource is a file whose extension is not .md | the command is disabled in the menus (deduced from the when clause, not run) |
| a .ts file in the active editor, the Command Palette opened | neither command is listed (deduced from the when clause, not run) |
| a .json file in the Explorer, right-click | the Explorer entry is absent (deduced from the when clause, not run) |
| a .md file shown in the Studio Open With editor, title bar drawn | the book button is absent, because the when clause requires the text file editor or the text diff editor (deduced from the when clause, not run) |
| focus in the terminal or in a non-Markdown editor, the chord pressed | the Studio does not handle it (deduced from the when clause editorTextFocus && resourceExtname == .md, not run) |
nominalFirst preview
the command completes once the page shows the rendered document, not while it still shows the pending status page (host test test/host/openCompletes.test.ts)
with the active editor alone in the only editor group, the panel is requested with ViewColumn.Beside, so VS Code opens it in a new group to the side (deduced from the code, not run)
nominalThe shown document again
the command completes once the page shows that render (host test test/host/openCompletes.test.ts)
nominalAnother document
refusalNo eligible file
boundaryPreviews that do not follow the active editor
| Input | Outcome |
|---|---|
| an Open With preview tab of a.md, no side preview, a.md chosen in the Explorer, the Explorer entry run | a new side preview panel is created beside the editor and the Open With tab stays |
| a panel restored by VS Code that is no longer the newest and has become a fixed preview, the command run from the Explorer | that panel is not reused |
| an Open With tab and a side preview of the same file, the command run | only the side preview that follows the active editor is reused |
boundaryHidden preview
| Input | Outcome |
|---|---|
| a side preview with a scrolled page, hidden behind another tab of its group, the reader selects the preview tab again | the page is reloaded and restores its scroll position, edit state and comments panel from the saved webview state, because the panel is created without retainContextWhenHidden (deduced from the code, not run) |
| an Open With preview tab hidden behind another tab, selected again | its page is restored the same way, because the custom editor is registered without retainContextWhenHidden |
refusalNot a saved Markdown file
nominalStudio Open With tab active
nominalText diff active
with two .md files compared the side that holds the cursor is the real file (the modified side when none does)
with no side of the file scheme (a staged diff) the working-tree file at the modified side's path stands in when it exists and is .md, and otherwise the refusal message shows
refusalAnother custom editor active
boundaryEligible and ineligible files
| Input | Outcome |
|---|---|
| a file with the scheme file and the extension .md | previewed |
| README.MD | accepted: the extension check is case-insensitive |
| notes.markdown | refused with the message above |
| an untitled document | refused with the message above |
nominalFile passed by a menu
without a side preview the file opens in the active group (by reading openPreview)
boundaryArgument that is not the file to open
| Input | Outcome |
|---|---|
| the URI names the file of the active editor | the file is not opened again and the active editor is previewed |
| the URI names a side of the active diff | the real file of the diff is previewed and no editor opens |
| the URI names a file that is no side of the active diff | the file opens as a text editor and is previewed, as without a diff |
| the argument { not: "a uri" } with a side preview of preview-other.md | ignored; the preview still shows preview-other.md (integration test test/integration/lifecycle.test.ts) |
| a URI whose scheme is not file | ignored the same way, because only the file scheme passes the check (deduced from the code, not run) |
refusalA file that cannot be opened
| Input | Outcome |
|---|---|
| a file URI of a file deleted after the menu was drawn | an error message Cannot open {path}: {reason} names the path and the reason, and no preview opens or changes |
| the failure is not an Error object | the reason is the failure converted to a string |
Implemented in 2
Tested by 8
- test/host/diffPreview.requirements.test.tsunit
- test/host/lifeReq.requirements.test.tsunit
- test/host/openCompletes.test.tsunit
- test/host/pageMessageWaitsForShow.test.tsunit
- test/integration/diffPreview.test.tsintegration
- test/integration/diffPreviewScroll.test.tsintegration
- test/integration/lifecycle.test.tsintegration
- test/security/package-contract.test.tsunit