提交 3c5d2103 编写于 作者: M Matt Bierner

Extract show source command to commands

上级 73c70588
......@@ -108,4 +108,24 @@ export class ShowPreviewToSideCommand implements Command {
public execute(uri?: vscode.Uri) {
showPreview(this.cspArbiter, this.telemetryReporter, uri, true);
}
}
export class ShowSourceCommand implements Command {
public readonly id = 'markdown.showSource';
public execute(mdUri?: vscode.Uri) {
if (!mdUri) {
return vscode.commands.executeCommand('workbench.action.navigateBack');
}
const docUri = vscode.Uri.parse(mdUri.query);
for (const editor of vscode.window.visibleTextEditors) {
if (editor.document.uri.scheme === docUri.scheme && editor.document.uri.toString() === docUri.toString()) {
return vscode.window.showTextDocument(editor.document, editor.viewColumn);
}
}
return vscode.workspace.openTextDocument(docUri)
.then(vscode.window.showTextDocument);
}
}
\ No newline at end of file
......@@ -106,8 +106,7 @@ export function activate(context: vscode.ExtensionContext) {
commandManager.register(new commands.ShowPreviewCommand(cspArbiter, telemetryReporter));
commandManager.register(new commands.ShowPreviewToSideCommand(cspArbiter, telemetryReporter));
context.subscriptions.push(vscode.commands.registerCommand('markdown.showSource', showSource));
commandManager.register(new commands.ShowSourceCommand());
context.subscriptions.push(vscode.commands.registerCommand('_markdown.moveCursorToPosition', (line: number, character: number) => {
if (!vscode.window.activeTextEditor) {
......@@ -252,22 +251,6 @@ export function activate(context: vscode.ExtensionContext) {
}
function showSource(mdUri: vscode.Uri) {
if (!mdUri) {
return vscode.commands.executeCommand('workbench.action.navigateBack');
}
const docUri = vscode.Uri.parse(mdUri.query);
for (const editor of vscode.window.visibleTextEditors) {
if (editor.document.uri.scheme === docUri.scheme && editor.document.uri.toString() === docUri.toString()) {
return vscode.window.showTextDocument(editor.document, editor.viewColumn);
}
}
return vscode.workspace.openTextDocument(docUri)
.then(vscode.window.showTextDocument);
}
function getPackageInfo(): IPackageInfo | null {
const extention = vscode.extensions.getExtension('Microsoft.vscode-markdown');
if (extention && extention.packageJSON) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册