Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static Markdown Preview - Toggle Between Text Editor and Static Preview [WIP] #123924

Closed

Conversation

andreamah
Copy link
Contributor

@andreamah andreamah commented May 14, 2021

UPDATE: put on hold until #124211 is resolved, as toggleEditorType may satisfy this use case.

Please merge #123727 first (that PR ensures scrolling keeps state for static preview).

This PR creates commands to switch to the static preview and text editor, in addition to a command to toggle between the two.

You can set the keybindings by opening the command palette and selecting Preferences: Open Keyboard Shortcuts. Then, the command should the listed as follows:
image

Examples:
Using direct commands to go between the two:
Image from Gyazo

Using toggling comands:
Image from Gyazo

This PR relates to #113298

@andreamah andreamah requested a review from mjbvz May 14, 2021 23:30
@andreamah andreamah changed the title Static Markdown Toggle Between Text Editor and Static Preview [WIP] Static Markdown Preview - Toggle Between Text Editor and Static Preview [WIP] May 14, 2021
}

public openTextEditor(): void {
vscode.commands.executeCommand('workbench.action.closeActiveEditor');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be unnecessary - vscode.openWith should reopen the file using the right editor type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really weird in that opening the 'default' viewtype seems to open in a new tab. You can also try commenting/uncommenting this line to double check this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openWith doesn't perform a reopen, but instead opens a new pinned editor. This behavior recently changed as prior to that they were preview editors, you can read more here #123360

},
{
"command": "markdown.showTextEditor",
"when": "!notebookEditorFocused",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there is a context key for which editor type is active, text editor vs markdown preview vs some other type of editor, so these commands can be enabled for exactly the right situation. Do you know @lramos15?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might work #113511

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that these conditions don't appear in the keyboard shortcuts menu under when, and same applies for other options without a default keybinding like markdown.preview.refresh. Are they still being applied?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that, when assigning a keybinding to markdown.showSource or markdown.preview.refresh, they seem to trigger regardless of the conditions set within the extension code? Is there something extra that these commands need in order to follow their respective conditions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update: the when fields should now have the commands appear when appropriate

@roblourens
Copy link
Member

Regarding the name of these commands, I don't think we show the term "static preview" to the user before this, and it's not really clear what "Show static preview in custom editor" means. I think that's basically exposing internal implementation details. It's also still not quite clear how this command is different from the "Open Preview" command

@andreamah
Copy link
Contributor Author

Regarding the name of these commands, I don't think we show the term "static preview" to the user before this, and it's not really clear what "Show static preview in custom editor" means. I think that's basically exposing internal implementation details. It's also still not quite clear how this command is different from the "Open Preview" command

That's true. I think it is referred to as Markdown Preview in the custom editors selection, but that can be mistaken with the dynamic preview. I guess that this would be better for people who prefer to stay within the custom editor and stay in the same tab compared to using the dynamic editor with "Open Preview".

@andreamah andreamah changed the title Static Markdown Preview - Toggle Between Text Editor and Static Preview [WIP] Static Markdown Preview - Toggle Between Text Editor and Static Preview May 17, 2021
@roblourens
Copy link
Member

What are the other differences between the two types of previews besides opening in the same tab?

@andreamah
Copy link
Contributor Author

What are the other differences between the two types of previews besides opening in the same tab?

They should generally look the same, but I believe that static preview was created in order to allow people to automatically open markdown files in the preview mode in order to navigate around their directory more like it's a wiki than a collection of markdown files.


public openTextEditor(): void {
const preview = this._activePreview;
if (preview) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to check here for the active editor's viewtype? Ideally, would like to only run this when the editor is not a text editor, since doing so just closes the editor.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the markdown extension knows about the custom editors it creates. There's no general vscode api for accessing them

Checking the _activePreview seems correct

@@ -23,6 +23,9 @@
"onCommand:markdown.showPreview",
"onCommand:markdown.showPreviewToSide",
"onCommand:markdown.showLockedPreviewToSide",
"onCommand:markdown.showStaticPreview",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we reuse the existing workbench.action.toggleEditorType commands here?

@@ -14,6 +14,9 @@
"markdown.preview.title": "Open Preview",
"markdown.previewSide.title": "Open Preview to the Side",
"markdown.showLockedPreviewToSide.title": "Open Locked Preview to the Side",
"markdown.showStaticPreview.title": "Show Static Preview in Custom Editor",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom editor is more of an implementation detail that may not mean much to users. I think static vs dynamic is probably better for user facing messages


public openTextEditor(): void {
const preview = this._activePreview;
if (preview) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the markdown extension knows about the custom editors it creates. There's no general vscode api for accessing them

Checking the _activePreview seems correct

@andreamah andreamah changed the title Static Markdown Preview - Toggle Between Text Editor and Static Preview Static Markdown Preview - Toggle Between Text Editor and Static Preview [WIP] May 20, 2021
@andreamah
Copy link
Contributor Author

Closed with #124211

@andreamah andreamah closed this Jul 23, 2021
@andreamah andreamah deleted the dev/t-andreamah/markdown-static-preview-toggle-modes branch July 23, 2021 19:22
@github-actions github-actions bot locked and limited conversation to collaborators Sep 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants