From 1aab49cdfeda767ad23e208820529d068d2fe259 Mon Sep 17 00:00:00 2001 From: shmck Date: Sun, 29 Sep 2019 18:51:02 -0700 Subject: [PATCH 1/3] saner launching of editor windows --- src/actions/setupActions.ts | 2 +- src/editor/ReactWebView.ts | 42 +++++++++++++++++++++---------------- src/editor/commands.ts | 11 ++-------- 3 files changed, 27 insertions(+), 28 deletions(-) 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..c6b01d2a 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,22 +46,23 @@ 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 + // // 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() - } + console.log('onDidChangeActiveTextEditor') + console.log(textEditor) + // if (!textEditor || textEditor.viewColumn !== vscode.ViewColumn.Two) { + // updateWindows() + // } }) - // // prevents moving coderoad panel on top of left panel + // // // prevents moving coderoad panel on top of left panel vscode.window.onDidChangeVisibleTextEditors((textEditor: vscode.TextEditor[]) => { - // console.log('onDidChangeVisibleTextEditors') - updateWindows() + console.log('onDidChangeVisibleTextEditors') + console.log(textEditor) + // updateWindows() }) // TODO: prevent window from moving to the left when no windows remain on rights @@ -81,13 +82,18 @@ class ReactWebView { this.send = this.channel.send } - public createOrShow(column: number): void { + public createOrShow(): void { + // reset layout + 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) + this.panel.reveal(vscode.ViewColumn.Two) } else { - this.panel = this.createWebviewPanel(column) + this.panel = this.createWebviewPanel() } } @@ -98,7 +104,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 +115,7 @@ class ReactWebView { // prevents destroying the window when it is in the background retainContextWhenHidden: true, } - return vscode.window.createWebviewPanel(viewType, title, column, config) + 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 From 3a154817cccf0ea8e2ab63a3847d8334495ef2c3 Mon Sep 17 00:00:00 2001 From: shmck Date: Sun, 29 Sep 2019 19:01:59 -0700 Subject: [PATCH 2/3] improve editor layout --- src/editor/ReactWebView.ts | 19 +++++-------------- src/editor/index.ts | 6 ++++++ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/editor/ReactWebView.ts b/src/editor/ReactWebView.ts index c6b01d2a..6bcb4d72 100644 --- a/src/editor/ReactWebView.ts +++ b/src/editor/ReactWebView.ts @@ -50,20 +50,12 @@ class ReactWebView { // 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') - console.log(textEditor) - // updateWindows() - }) + // 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 @@ -83,7 +75,6 @@ class ReactWebView { } public createOrShow(): void { - // reset layout vscode.commands.executeCommand('vscode.setEditorLayout', { orientation: 0, groups: [{groups: [{}], size: 0.6}, {groups: [{}], size: 0.4}], 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() From 8f91d7f51c9d5a3f2cb69766de56d8b5c359b627 Mon Sep 17 00:00:00 2001 From: shmck Date: Sun, 29 Sep 2019 19:11:39 -0700 Subject: [PATCH 3/3] prevent multiple versions of cr open --- src/editor/ReactWebView.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/editor/ReactWebView.ts b/src/editor/ReactWebView.ts index 6bcb4d72..64d1f948 100644 --- a/src/editor/ReactWebView.ts +++ b/src/editor/ReactWebView.ts @@ -81,8 +81,12 @@ class ReactWebView { }) // If we already have a panel, show it. // Otherwise, create a new panel. + if (this.panel && this.panel.webview) { - this.panel.reveal(vscode.ViewColumn.Two) + if (!this.loaded) { + this.panel.reveal(vscode.ViewColumn.Two) + this.loaded = true + } } else { this.panel = this.createWebviewPanel() } @@ -106,6 +110,7 @@ class ReactWebView { // prevents destroying the window when it is in the background retainContextWhenHidden: true, } + this.loaded = true return vscode.window.createWebviewPanel(viewType, title, vscode.ViewColumn.Two, config) }