I created a simple demo, modified with webview official instance, please help to look at this problem: https://github.com/roguexiaohuihui/input-focus
the demo content:
1、Run the Cat Coding: Start cat coding session
to create the webview.
the first time you create a webview, the focus is normal
2、Run again Cat Coding: Start cat coding session
to create the webview.
the focus is normal
3、Switching to the webview in step 1, this focus is not working
I listened for the toggle event and sent a message to the web to make it focus, but the focus didn't work
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()
// Handle messages sent from the extension to the webview
window.addEventListener('message', event => {
const message = event.data // The json data that the extension sent
switch (message.command) {
case 'showFocus':
console.log('showFocus')
console.log('input:', input)
input.focus()
break
}
})
vscode community problem address:
https://github.com/microsoft/vscode/issues/84216
the problem: when switching webview, the plug-in transmits a signal to webview through message and actively asks the input of webview to focus again. Instead of the input being focused after the mouse click on the screen