Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbab2e54

Browse files
committed
refactor webview render
1 parent229c6b8 commitbab2e54

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

‎src/editor/ReactWebView.ts

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,37 @@ class ReactWebView {
3838
this.panel=this.createWebviewPanel(vscode.ViewColumn.Two)
3939

4040
// Set the webview initial html content
41-
this.getHtmlForWebview()
41+
this.render().then((html:string)=>{
42+
this.panel.webview.html=html
43+
// Listen for when the panel is disposed
44+
// This happens when the user closes the panel or when the panel is closed programmatically
45+
this.panel.onDidDispose(this.dispose,this,this.disposables)
46+
47+
48+
// update panel on changes
49+
constupdateWindows=()=>{
50+
vscode.commands.executeCommand('vscode.setEditorLayout',{
51+
orientation:0,
52+
groups:[{groups:[{}],size:0.6},{groups:[{}],size:0.4}],
53+
})
54+
}
55+
56+
// prevents new panels from going on top of coderoad panel
57+
vscode.window.onDidChangeActiveTextEditor((textEditor?:vscode.TextEditor)=>{
58+
// console.log('onDidChangeActiveTextEditor')
59+
// console.log(textEditor)
60+
if(!textEditor||textEditor.viewColumn!==vscode.ViewColumn.Two){
61+
updateWindows()
62+
}
63+
})
64+
// // prevents moving coderoad panel on top of left panel
65+
vscode.window.onDidChangeVisibleTextEditors((textEditor:vscode.TextEditor[])=>{
66+
// console.log('onDidChangeVisibleTextEditors')
67+
updateWindows()
68+
})
4269

43-
// Listen for when the panel is disposed
44-
// This happens when the user closes the panel or when the panel is closed programmatically
45-
this.panel.onDidDispose(this.dispose,this,this.disposables)
70+
// TODO: prevent window from moving to the left when no windows remain on rights
71+
})
4672

4773
// channel connects webview to the editor
4874
this.channel=newChannel({
@@ -55,31 +81,6 @@ class ReactWebView {
5581
constreceive=this.channel.receive
5682
this.panel.webview.onDidReceiveMessage(receive,null,this.disposables)
5783
this.send=this.channel.send
58-
59-
60-
// update panel on changes
61-
constupdateWindows=()=>{
62-
vscode.commands.executeCommand('vscode.setEditorLayout',{
63-
orientation:0,
64-
groups:[{groups:[{}],size:0.6},{groups:[{}],size:0.4}],
65-
})
66-
}
67-
68-
// prevents new panels from going on top of coderoad panel
69-
vscode.window.onDidChangeActiveTextEditor((textEditor?:vscode.TextEditor)=>{
70-
// console.log('onDidChangeActiveTextEditor')
71-
// console.log(textEditor)
72-
if(!textEditor||textEditor.viewColumn!==vscode.ViewColumn.Two){
73-
updateWindows()
74-
}
75-
})
76-
// // prevents moving coderoad panel on top of left panel
77-
vscode.window.onDidChangeVisibleTextEditors((textEditor:vscode.TextEditor[])=>{
78-
// console.log('onDidChangeVisibleTextEditors')
79-
updateWindows()
80-
})
81-
82-
// TODO: prevent window from moving to the left when no windows remain on rights
8384
}
8485

8586
publiccreateOrShow(column:number):void{
@@ -113,7 +114,7 @@ class ReactWebView {
113114
returnvscode.window.createWebviewPanel(viewType,title,column,config)
114115
}
115116

116-
privategetHtmlForWebview=async():Promise<void>=>{
117+
privaterender=async():Promise<string>=>{
117118

118119
constdom=awaitJSDOM.fromFile('./build/index.html')
119120

@@ -170,7 +171,7 @@ class ReactWebView {
170171

171172
console.log(html)
172173

173-
this.panel.webview.html=html
174+
returnhtml
174175
}
175176

176177
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp