diff --git a/packages/vscode-extension/src/extension.ts b/packages/vscode-extension/src/extension.ts index 02a222dfe..a3f9aefee 100644 --- a/packages/vscode-extension/src/extension.ts +++ b/packages/vscode-extension/src/extension.ts @@ -78,7 +78,7 @@ export async function activate(context: ExtensionContext) { commands.executeCommand("setContext", "RNIDE.sidePanelIsClosed", false); - async function showIDEPanel(fileName?: string, lineNumber?: number) { + async function showIDEPanel() { await commands.executeCommand("setContext", "RNIDE.sidePanelIsClosed", false); const panelLocation = workspace @@ -86,9 +86,9 @@ export async function activate(context: ExtensionContext) { .get("panelLocation"); if (panelLocation !== "tab") { - SidePanelViewProvider.showView(context, fileName, lineNumber); + SidePanelViewProvider.showView(); } else { - TabPanel.render(context, fileName, lineNumber); + TabPanel.render(context); } } @@ -119,6 +119,15 @@ export async function activate(context: ExtensionContext) { Project.currentProject?.showStorybookStory(componentTitle, storyName); } + async function showInlinePreview(fileName: string, lineNumber: number) { + commands.executeCommand("RNIDE.openPanel"); + if (Project.currentProject) { + Project.currentProject.startPreview(`preview:/${fileName}:${lineNumber}`); + } else { + window.showWarningMessage("Wait for app to load before lunching preview. ", "Dismiss"); + } + } + context.subscriptions.push( window.registerWebviewViewProvider( SidePanelViewProvider.viewType, @@ -148,6 +157,9 @@ export async function activate(context: ExtensionContext) { context.subscriptions.push( commands.registerCommand("RNIDE.showStorybookStory", showStorybookStory) ); + context.subscriptions.push( + commands.registerCommand("RNIDE.showInlinePreview", showInlinePreview) + ); async function closeAuxiliaryBar(registeredCommandDisposable: Disposable) { registeredCommandDisposable.dispose(); // must dispose to avoid endless loops diff --git a/packages/vscode-extension/src/panels/SidepanelViewProvider.ts b/packages/vscode-extension/src/panels/SidepanelViewProvider.ts index eaf34fdbf..724ce74b0 100644 --- a/packages/vscode-extension/src/panels/SidepanelViewProvider.ts +++ b/packages/vscode-extension/src/panels/SidepanelViewProvider.ts @@ -37,7 +37,7 @@ export class SidePanelViewProvider implements WebviewViewProvider, Disposable { ); } - public static showView(context: ExtensionContext, fileName?: string, lineNumber?: number) { + public static showView() { if (SidePanelViewProvider.currentProvider) { commands.executeCommand(`${SidePanelViewProvider.viewType}.focus`); if (workspace.getConfiguration("RadonIDE").get("panelLocation") === "secondary-side-panel") { @@ -47,12 +47,6 @@ export class SidePanelViewProvider implements WebviewViewProvider, Disposable { Logger.error("SidepanelViewProvider does not exist."); return; } - - if (fileName !== undefined && lineNumber !== undefined) { - SidePanelViewProvider.currentProvider.webviewController.project.startPreview( - `preview:/${fileName}:${lineNumber}` - ); - } } //called when a view first becomes visible diff --git a/packages/vscode-extension/src/panels/Tabpanel.ts b/packages/vscode-extension/src/panels/Tabpanel.ts index 035302c4d..d260543e5 100644 --- a/packages/vscode-extension/src/panels/Tabpanel.ts +++ b/packages/vscode-extension/src/panels/Tabpanel.ts @@ -57,7 +57,7 @@ export class TabPanel implements Disposable { }); } - public static render(context: ExtensionContext, fileName?: string, lineNumber?: number) { + public static render(context: ExtensionContext) { if (TabPanel.currentPanel) { // If the webview panel already exists reveal it TabPanel.currentPanel._panel.reveal(); @@ -85,12 +85,6 @@ export class TabPanel implements Disposable { commands.executeCommand("workbench.action.lockEditorGroup"); } - - if (fileName !== undefined && lineNumber !== undefined) { - TabPanel.currentPanel.webviewController.project.startPreview( - `preview:/${fileName}:${lineNumber}` - ); - } } public dispose() { diff --git a/packages/vscode-extension/src/providers/PreviewCodeLensProvider.ts b/packages/vscode-extension/src/providers/PreviewCodeLensProvider.ts index 860c4394c..8893dbd64 100644 --- a/packages/vscode-extension/src/providers/PreviewCodeLensProvider.ts +++ b/packages/vscode-extension/src/providers/PreviewCodeLensProvider.ts @@ -91,7 +91,7 @@ export class PreviewCodeLensProvider implements CodeLensProvider { const previewCallRange = this.createRange(document, match.index); const command: Command = { title: "Open preview", - command: "RNIDE.showPanel", + command: "RNIDE.showInlinePreview", arguments: [ document.fileName, jsxOpeningTagLine0Based + 1 /* RNIDE expects 1-based line number */,