Skip to content

Commit 89f98d6

Browse files
authored
Merge pull request #39 from ShMcK/fix/editor-windows
Fix/editor windows
2 parents f17682a + 8f91d7f commit 89f98d6

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

src/actions/setupActions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, {commands, co
5858
// await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
5959
// // there are times when initialization leave the panel behind any files opened
6060
// // ensure the panel is redrawn on the right side first
61-
// // webview.createOrShow(vscode.ViewColumn.Two)
61+
// // webview.createOrShow()
6262
// } catch (error) {
6363
// console.log(`Failed to open file ${filePath}`, error)
6464
// }

src/editor/ReactWebView.ts

+24-22
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ReactWebView {
3535
this.extensionPath = extensionPath
3636

3737
// Create and show a new webview panel
38-
this.panel = this.createWebviewPanel(vscode.ViewColumn.Two)
38+
this.panel = this.createWebviewPanel()
3939

4040
// Set the webview initial html content
4141
this.render()
@@ -46,23 +46,16 @@ class ReactWebView {
4646

4747

4848
// update panel on changes
49-
const updateWindows = () => {
50-
vscode.commands.executeCommand('coderoad.open_webview')
51-
}
49+
// const updateWindows = () => {
50+
// vscode.commands.executeCommand('coderoad.open_webview')
51+
// }
5252

53-
// prevents new panels from going on top of coderoad panel
54-
vscode.window.onDidChangeActiveTextEditor((textEditor?: vscode.TextEditor) => {
55-
// console.log('onDidChangeActiveTextEditor')
56-
// console.log(textEditor)
57-
if (!textEditor || textEditor.viewColumn !== vscode.ViewColumn.Two) {
58-
updateWindows()
59-
}
60-
})
61-
// // prevents moving coderoad panel on top of left panel
62-
vscode.window.onDidChangeVisibleTextEditors((textEditor: vscode.TextEditor[]) => {
63-
// console.log('onDidChangeVisibleTextEditors')
64-
updateWindows()
65-
})
53+
// // // prevents moving coderoad panel on top of left panel
54+
// vscode.window.onDidChangeVisibleTextEditors((textEditors: vscode.TextEditor[]) => {
55+
// console.log('onDidChangeVisibleTextEditors')
56+
// console.log(textEditors)
57+
// // updateWindows()
58+
// })
6659

6760
// TODO: prevent window from moving to the left when no windows remain on rights
6861

@@ -81,13 +74,21 @@ class ReactWebView {
8174
this.send = this.channel.send
8275
}
8376

84-
public createOrShow(column: number): void {
77+
public createOrShow(): void {
78+
vscode.commands.executeCommand('vscode.setEditorLayout', {
79+
orientation: 0,
80+
groups: [{groups: [{}], size: 0.6}, {groups: [{}], size: 0.4}],
81+
})
8582
// If we already have a panel, show it.
8683
// Otherwise, create a new panel.
84+
8785
if (this.panel && this.panel.webview) {
88-
this.panel.reveal(column)
86+
if (!this.loaded) {
87+
this.panel.reveal(vscode.ViewColumn.Two)
88+
this.loaded = true
89+
}
8990
} else {
90-
this.panel = this.createWebviewPanel(column)
91+
this.panel = this.createWebviewPanel()
9192
}
9293
}
9394

@@ -98,7 +99,7 @@ class ReactWebView {
9899
Promise.all(this.disposables.map((x) => x.dispose()))
99100
}
100101

101-
private createWebviewPanel = (column: number): vscode.WebviewPanel => {
102+
private createWebviewPanel = (): vscode.WebviewPanel => {
102103
const viewType = 'CodeRoad'
103104
const title = 'CodeRoad'
104105
const config = {
@@ -109,7 +110,8 @@ class ReactWebView {
109110
// prevents destroying the window when it is in the background
110111
retainContextWhenHidden: true,
111112
}
112-
return vscode.window.createWebviewPanel(viewType, title, column, config)
113+
this.loaded = true
114+
return vscode.window.createWebviewPanel(viewType, title, vscode.ViewColumn.Two, config)
113115
}
114116

115117
private render = async (): Promise<void> => {

src/editor/commands.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,9 @@ export const createCommands = ({extensionPath, workspaceState, workspaceRoot}: C
4747
})
4848
},
4949
// open React webview
50-
[COMMANDS.OPEN_WEBVIEW]: (column: number = vscode.ViewColumn.Two) => {
50+
[COMMANDS.OPEN_WEBVIEW]: () => {
5151
// setup 1x1 horizontal layout
52-
53-
// reset layout
54-
vscode.commands.executeCommand('vscode.setEditorLayout', {
55-
orientation: 0,
56-
groups: [{groups: [{}], size: 0.6}, {groups: [{}], size: 0.4}],
57-
})
58-
59-
webview.createOrShow(column)
52+
webview.createOrShow()
6053
},
6154
[COMMANDS.SET_CURRENT_STEP]: ({stepId}: {stepId: string}) => {
6255
// NOTE: as async, may sometimes be inaccurate

src/editor/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ class Editor {
1111
console.log('ACTIVATE!')
1212
this.vscodeExt = vscodeExt
1313

14+
// set out 60/40 layout
15+
vscode.commands.executeCommand('vscode.setEditorLayout', {
16+
orientation: 0,
17+
groups: [{groups: [{}], size: 0.6}, {groups: [{}], size: 0.4}],
18+
})
19+
1420
// commands
1521
this.activateCommands()
1622

0 commit comments

Comments
 (0)