-
Notifications
You must be signed in to change notification settings - Fork 29k
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
Static Markdown Preview - Toggle Between Text Editor and Static Preview [WIP] #123924
Conversation
} | ||
|
||
public openTextEditor(): void { | ||
vscode.commands.executeCommand('workbench.action.closeActiveEditor'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might work #113511
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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 |
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
Closed with #124211 |
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:Examples:
Using direct commands to go between the two:
Using toggling comands:
This PR relates to #113298