Microsoft/vscode

Dispatching KeyboardEvent on Webview fails to work only on Windows.

Open

#109.147 aperta il 22 ott 2020

Vedi su GitHub
 (5 commenti) (3 reazioni) (1 assegnatario)TypeScript (10.221 fork)batch import
bughelp wantedwebviewwindows

Metriche repository

Star
 (74.848 star)
Metriche merge PR
 (Merge medio 11h 43m) (1000 PR mergiate in 30 g)

Descrizione

Dispatching KeyboardEvents on Webview fails to work only on Windows.

Version: 1.51.0-insider (user setup) Commit: 9f7a586124ca121bba906b44eb8356691617957e Date: 2020-10-22T00:49:16.002Z Electron: 9.3.2 Chrome: 83.0.4103.122 Node.js: 12.14.1 V8: 8.3.110.13-electron.0 OS: Windows_NT x64 10.0.18363

Steps to Reproduce:

  1. Execute the following sample on Windows.
  2. Execute the command Hello World
  3. A webview panel is opened, and a new document is not opened.
  4. A new document should be opened.

Does this issue occur when all extensions are disabled?: Yes

Related to James-Yu/LaTeX-Workshop/issues/2334 and #108797.

We are dispatching KeyboardEvents on our extension's internal PDF viewer to enable shortcuts on the viewer, which is recommended by @mjbvz. It had been working fine. However, we find that it fails to work only on Windows now. On macOS, it still works fine.

import * as vscode from 'vscode';

const htmlString = `
<script>
// Should work on macOS.
const ev0 = {"altKey":false,"code":"KeyN","ctrlKey":false,"isComposing":false,"key":"n","location":0,"metaKey":true,"repeat":false,"shiftKey":false};
setTimeout(() => window.dispatchEvent(new KeyboardEvent('keydown', ev0)), 2000);

// Should work on windows.
const ev1 = {"altKey":false,"code":"KeyN","ctrlKey":true,"isComposing":false,"key":"n","location":0,"metaKey":false,"repeat":false,"shiftKey":false};
setTimeout(() => window.dispatchEvent(new KeyboardEvent('keydown', ev1)), 3000);
</script>
`

export function activate(context: vscode.ExtensionContext) {
	console.log('Congratulations, your extension "helloworld-sample" is now active!');

	const disposable = vscode.commands.registerCommand('extension.helloWorld', () => {
		const panel = vscode.window.createWebviewPanel(
			'aaa',
			'Cat Coding',
			vscode.ViewColumn.One,
			{
					enableScripts: true,
			}
		)
		panel.webview.html = htmlString
	})
	context.subscriptions.push(disposable);
}

Guida contributor