diff --git a/src/actions/setupActions.ts b/src/actions/setupActions.ts index 50322e17..99dd045c 100644 --- a/src/actions/setupActions.ts +++ b/src/actions/setupActions.ts @@ -58,7 +58,7 @@ const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, {commands, co // await vscode.window.showTextDocument(doc, vscode.ViewColumn.One) // // there are times when initialization leave the panel behind any files opened // // ensure the panel is redrawn on the right side first - // // webview.createOrShow(vscode.ViewColumn.Two) + // // webview.createOrShow() // } catch (error) { // console.log(`Failed to open file ${filePath}`, error) // } diff --git a/src/editor/ReactWebView.ts b/src/editor/ReactWebView.ts index 933ded92..64d1f948 100644 --- a/src/editor/ReactWebView.ts +++ b/src/editor/ReactWebView.ts @@ -35,7 +35,7 @@ class ReactWebView { this.extensionPath = extensionPath // Create and show a new webview panel - this.panel = this.createWebviewPanel(vscode.ViewColumn.Two) + this.panel = this.createWebviewPanel() // Set the webview initial html content this.render() @@ -46,23 +46,16 @@ class ReactWebView { // update panel on changes - const updateWindows = () => { - vscode.commands.executeCommand('coderoad.open_webview') - } + // const updateWindows = () => { + // vscode.commands.executeCommand('coderoad.open_webview') + // } - // prevents new panels from going on top of coderoad panel - vscode.window.onDidChangeActiveTextEditor((textEditor?: vscode.TextEditor) => { - // console.log('onDidChangeActiveTextEditor') - // console.log(textEditor) - if (!textEditor || textEditor.viewColumn !== vscode.ViewColumn.Two) { - updateWindows() - } - }) - // // prevents moving coderoad panel on top of left panel - vscode.window.onDidChangeVisibleTextEditors((textEditor: vscode.TextEditor[]) => { - // console.log('onDidChangeVisibleTextEditors') - updateWindows() - }) + // // // prevents moving coderoad panel on top of left panel + // vscode.window.onDidChangeVisibleTextEditors((textEditors: vscode.TextEditor[]) => { + // console.log('onDidChangeVisibleTextEditors') + // console.log(textEditors) + // // updateWindows() + // }) // TODO: prevent window from moving to the left when no windows remain on rights @@ -81,13 +74,21 @@ class ReactWebView { this.send = this.channel.send } - public createOrShow(column: number): void { + public createOrShow(): void { + vscode.commands.executeCommand('vscode.setEditorLayout', { + orientation: 0, + groups: [{groups: [{}], size: 0.6}, {groups: [{}], size: 0.4}], + }) // If we already have a panel, show it. // Otherwise, create a new panel. + if (this.panel && this.panel.webview) { - this.panel.reveal(column) + if (!this.loaded) { + this.panel.reveal(vscode.ViewColumn.Two) + this.loaded = true + } } else { - this.panel = this.createWebviewPanel(column) + this.panel = this.createWebviewPanel() } } @@ -98,7 +99,7 @@ class ReactWebView { Promise.all(this.disposables.map((x) => x.dispose())) } - private createWebviewPanel = (column: number): vscode.WebviewPanel => { + private createWebviewPanel = (): vscode.WebviewPanel => { const viewType = 'CodeRoad' const title = 'CodeRoad' const config = { @@ -109,7 +110,8 @@ class ReactWebView { // prevents destroying the window when it is in the background retainContextWhenHidden: true, } - return vscode.window.createWebviewPanel(viewType, title, column, config) + this.loaded = true + return vscode.window.createWebviewPanel(viewType, title, vscode.ViewColumn.Two, config) } private render = async (): Promise => { diff --git a/src/editor/commands.ts b/src/editor/commands.ts index 4102743a..2d13b4be 100644 --- a/src/editor/commands.ts +++ b/src/editor/commands.ts @@ -47,16 +47,9 @@ export const createCommands = ({extensionPath, workspaceState, workspaceRoot}: C }) }, // open React webview - [COMMANDS.OPEN_WEBVIEW]: (column: number = vscode.ViewColumn.Two) => { + [COMMANDS.OPEN_WEBVIEW]: () => { // setup 1x1 horizontal layout - - // reset layout - vscode.commands.executeCommand('vscode.setEditorLayout', { - orientation: 0, - groups: [{groups: [{}], size: 0.6}, {groups: [{}], size: 0.4}], - }) - - webview.createOrShow(column) + webview.createOrShow() }, [COMMANDS.SET_CURRENT_STEP]: ({stepId}: {stepId: string}) => { // NOTE: as async, may sometimes be inaccurate diff --git a/src/editor/index.ts b/src/editor/index.ts index 0b0c507d..14742014 100644 --- a/src/editor/index.ts +++ b/src/editor/index.ts @@ -11,6 +11,12 @@ class Editor { console.log('ACTIVATE!') this.vscodeExt = vscodeExt + // set out 60/40 layout + vscode.commands.executeCommand('vscode.setEditorLayout', { + orientation: 0, + groups: [{groups: [{}], size: 0.6}, {groups: [{}], size: 0.4}], + }) + // commands this.activateCommands()