Add markdown preview refresh command

Fixes #32111
This commit is contained in:
Matt Bierner 2017-08-07 20:21:02 -07:00
parent bcf50f5d5e
commit f980319f5c
4 changed files with 30 additions and 3 deletions

View file

@ -14,6 +14,7 @@
],
"activationEvents": [
"onLanguage:markdown",
"onCommand:markdown.refreshPreview",
"onCommand:markdown.showPreview",
"onCommand:markdown.showPreviewToSide",
"onCommand:markdown.showSource",
@ -71,6 +72,11 @@
"dark": "./media/ViewSource_inverse.svg"
}
},
{
"command": "markdown.refreshPreview",
"title": "%markdown.refreshPreview.title%",
"category": "Markdown"
},
{
"command": "markdown.showPreviewSecuritySelector",
"title": "%markdown.showPreviewSecuritySelector.title%",
@ -90,6 +96,10 @@
"when": "resourceScheme == markdown",
"group": "navigation"
},
{
"command": "markdown.refreshPreview",
"when": "resourceScheme == markdown"
},
{
"command": "markdown.showPreviewSecuritySelector",
"when": "resourceScheme == markdown"

View file

@ -14,5 +14,6 @@
"markdown.showSource.title" : "Show Source",
"markdown.styles.dec": "A list of URLs or local paths to CSS style sheets to use from the markdown preview. Relative paths are interpreted relative to the folder open in the explorer. If there is no open folder, they are interpreted relative to the location of the markdown file. All '\\' need to be written as '\\\\'.",
"markdown.showPreviewSecuritySelector.title": "Change Preview Security Settings",
"markdown.trace.desc": "Enable debug logging for the markdown extension."
"markdown.trace.desc": "Enable debug logging for the markdown extension.",
"markdown.refreshPreview.title": "Refresh Preview"
}

View file

@ -168,6 +168,22 @@ export function activate(context: vscode.ExtensionContext) {
}
}));
context.subscriptions.push(vscode.commands.registerCommand('markdown.refreshPreview', (resource: string | undefined) => {
if (resource) {
const source = vscode.Uri.parse(resource);
contentProvider.update(source);
} else if (vscode.window.activeTextEditor && isMarkdownFile(vscode.window.activeTextEditor.document)) {
contentProvider.update(getMarkdownUri(vscode.window.activeTextEditor.document.uri));
} else if (!vscode.window.activeTextEditor) {
// update all generated md documents
for (const document of vscode.workspace.textDocuments) {
if (document.uri.scheme === 'markdown') {
contentProvider.update(document.uri);
}
}
}
}));
context.subscriptions.push(vscode.commands.registerCommand('_markdown.onPreviewStyleLoadError', (resources: string[]) => {
vscode.window.showWarningMessage(localize('onPreviewStyleLoadError', "Could not load 'markdown.styles': {0}", resources.join(', ')));
}));

View file

@ -252,11 +252,11 @@ export class MDDocumentContentProvider implements vscode.TextDocumentContentProv
if (!this.config.isEqualTo(newConfig)) {
this.config = newConfig;
// update all generated md documents
vscode.workspace.textDocuments.forEach(document => {
for (const document of vscode.workspace.textDocuments) {
if (document.uri.scheme === 'markdown') {
this.update(document.uri);
}
});
}
}
}