Use activePreview when running markdown commands

Fixes #46216
This commit is contained in:
Matt Bierner 2018-03-20 14:30:06 -07:00
parent 27a17935b8
commit 18146e8c71
3 changed files with 7 additions and 23 deletions

View file

@ -14,15 +14,9 @@ export class ShowSourceCommand implements Command {
private readonly previewManager: MarkdownPreviewManager
) { }
public execute(docUri?: vscode.Uri) {
if (!docUri) {
return vscode.commands.executeCommand('workbench.action.navigateBack');
}
const resource = this.previewManager.getResourceForPreview(docUri);
if (resource) {
return vscode.workspace.openTextDocument(resource)
public execute() {
if (this.previewManager.activePreviewResource) {
return vscode.workspace.openTextDocument(this.previewManager.activePreviewResource)
.then(document => vscode.window.showTextDocument(document));
}
return undefined;

View file

@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { Command } from '../commandManager';
import { MarkdownPreviewManager } from '../features/previewManager';
@ -14,7 +13,7 @@ export class ToggleLockCommand implements Command {
private readonly previewManager: MarkdownPreviewManager
) { }
public execute(previewUri?: vscode.Uri) {
this.previewManager.toggleLock(previewUri);
public execute() {
this.previewManager.toggleLock();
}
}

View file

@ -76,13 +76,8 @@ export class MarkdownPreviewManager {
return this.activePreview && this.activePreview.resource;
}
public getResourceForPreview(previewUri: vscode.Uri): vscode.Uri | undefined {
const preview = this.getPreviewWithUri(previewUri);
return preview && preview.resource;
}
public toggleLock(previewUri?: vscode.Uri) {
const preview = previewUri ? this.getPreviewWithUri(previewUri) : this.activePreview;
public toggleLock() {
const preview = this.activePreview;
if (preview) {
preview.toggleLock();
@ -103,10 +98,6 @@ export class MarkdownPreviewManager {
preview.matchesResource(resource, previewSettings.previewColumn, previewSettings.locked));
}
private getPreviewWithUri(previewUri: vscode.Uri): MarkdownPreview | undefined {
return this.previews.find(preview => preview.uri.toString() === previewUri.toString());
}
private createNewPreview(
resource: vscode.Uri,
previewSettings: PreviewSettings