我创建了一个简单的演示,并使用webview官方实例进行了修改,请帮助查看此问题: https://github.com/roguexiaohuihui/input-focus
演示内容:
1,运行Cat Coding: Start cat coding session
创建Web视图。
第一次创建网络视图时,焦点是正常的
2,再次运行Cat Coding: Start cat coding session
以创建Web视图。
焦点正常
3,在步骤1中切换到网络视图,此焦点无法正常工作
我听了切换事件,并向网络发送了一条消息以使其成为焦点,但是焦点没有起作用
this._panel.onDidChangeViewState(
e => {
if (this._panel.visible) {
this._panel.webview.postMessage({ command: 'showFocus' });
this._update();
}
},null,this._disposables
);
media / main.js:
var input = document.getElementById('input_1')
input.focus()
window.addEventListener('message',event => {
const message = event.data
switch (message.command) {
case 'showFocus':
console.log('showFocus')
console.log('input:',input)
input.focus() //It doesn't work here
break
}
})
vscode社区问题地址:
https://github.com/microsoft/vscode/issues/84216
问题: 当切换Web视图时,插件会通过消息将信号发送到Web视图,并主动要求Web视图的输入再次聚焦。鼠标单击屏幕后,输入不再是焦点