Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Double pasting in webview(using russian keyboard layout) (#161001) #178120

Merged
merged 4 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/vs/workbench/contrib/webview/browser/pre/index-no-csp.html
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
const onControllerChange = () => {
navigator.serviceWorker.removeEventListener('controllerchange', onControllerChange);
if (navigator.serviceWorker.controller) {
postVersionMessage(navigator.serviceWorker.controller);
postVersionMessage(navigator.serviceWorker.controller);
} else {
return reject(new Error('No controller found.'));
}
Expand Down Expand Up @@ -450,11 +450,11 @@
if (!disableServiceWorker) {
hostMessaging.onMessage('did-load-resource', (_event, data) => {
assertIsDefined(navigator.serviceWorker.controller).postMessage({ channel: 'did-load-resource', data }, data.data?.buffer ? [data.data.buffer] : []);
});
});

hostMessaging.onMessage('did-load-localhost', (_event, data) => {
assertIsDefined(navigator.serviceWorker.controller).postMessage({ channel: 'did-load-localhost', data });
});
});

navigator.serviceWorker.addEventListener('message', event => {
switch (event.data.channel) {
Expand Down Expand Up @@ -630,8 +630,10 @@
*/
function isCopyPasteOrCut(e) {
const hasMeta = e.ctrlKey || e.metaKey;
const shiftInsert = e.shiftKey && e.key.toLowerCase() === 'insert';
return (hasMeta && ['c', 'v', 'x'].includes(e.key.toLowerCase())) || shiftInsert;
// 45: keyCode of "Insert"
const shiftInsert = e.shiftKey && e.keyCode === 45;
// 67, 86, 88: keyCode of "C", "V", "X"
return (hasMeta && [67, 86, 88].includes(e.keyCode)) || shiftInsert;
}

/**
Expand All @@ -640,7 +642,8 @@
*/
function isUndoRedo(e) {
const hasMeta = e.ctrlKey || e.metaKey;
return hasMeta && ['z', 'y'].includes(e.key.toLowerCase());
// 90, 89: keyCode of "Z", "Y"
return hasMeta && [90, 89].includes(e.keyCode);
}

/**
Expand All @@ -649,7 +652,8 @@
*/
function isPrint(e) {
const hasMeta = e.ctrlKey || e.metaKey;
return hasMeta && e.key.toLowerCase() === 'p';
// 80: keyCode of "P"
return hasMeta && e.keyCode === 80;
}

/**
Expand All @@ -658,7 +662,8 @@
*/
function isFindEvent(e) {
const hasMeta = e.ctrlKey || e.metaKey;
return hasMeta && e.key.toLowerCase() === 'f';
// 70: keyCode of "F"
return hasMeta && e.keyCode === 70;
}

/**
Expand All @@ -667,7 +672,8 @@
*/
function isSaveEvent(e) {
const hasMeta = e.ctrlKey || e.metaKey;
return hasMeta && e.key.toLowerCase() === 's';
// 83: keyCode of "S"
return hasMeta && e.keyCode === 83;
}

/**
Expand All @@ -676,7 +682,8 @@
*/
function isCloseTab(e) {
const hasMeta = e.ctrlKey || e.metaKey;
return hasMeta && e.key.toLowerCase() === 'w';
// 87: keyCode of "W"
return hasMeta && e.keyCode === 87;
}

/**
Expand All @@ -685,7 +692,8 @@
*/
function isNewWindow(e) {
const hasMeta = e.ctrlKey || e.metaKey;
return hasMeta && e.key.toLowerCase() === 'n';
// 78: keyCode of "N"
return hasMeta && e.keyCode === 78;
}

let isHandlingScroll = false;
Expand Down
26 changes: 17 additions & 9 deletions src/vs/workbench/contrib/webview/browser/pre/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta charset="UTF-8">

<meta http-equiv="Content-Security-Policy"
content="default-src 'none'; script-src 'sha256-7T0Xm7l4AYKDwm8oYNQ65wcQX7K/ndvxH/2ZgHWUE3w=' 'self'; frame-src 'self'; style-src 'unsafe-inline';">
content="default-src 'none'; script-src 'sha256-N4YFn5ze5crjPqMK/opogKs7bSGWtf3lmjV/3LfbSOs=' 'self'; frame-src 'self'; style-src 'unsafe-inline';">

<!-- Disable pinch zooming -->
<meta name="viewport"
Expand Down Expand Up @@ -631,8 +631,10 @@
*/
function isCopyPasteOrCut(e) {
const hasMeta = e.ctrlKey || e.metaKey;
const shiftInsert = e.shiftKey && e.key.toLowerCase() === 'insert';
return (hasMeta && ['c', 'v', 'x'].includes(e.key.toLowerCase())) || shiftInsert;
// 45: keyCode of "Insert"
const shiftInsert = e.shiftKey && e.keyCode === 45;
// 67, 86, 88: keyCode of "C", "V", "X"
return (hasMeta && [67, 86, 88].includes(e.keyCode)) || shiftInsert;
}

/**
Expand All @@ -641,7 +643,8 @@
*/
function isUndoRedo(e) {
const hasMeta = e.ctrlKey || e.metaKey;
return hasMeta && ['z', 'y'].includes(e.key.toLowerCase());
// 90, 89: keyCode of "Z", "Y"
return hasMeta && [90, 89].includes(e.keyCode);
}

/**
Expand All @@ -650,7 +653,8 @@
*/
function isPrint(e) {
const hasMeta = e.ctrlKey || e.metaKey;
return hasMeta && e.key.toLowerCase() === 'p';
// 80: keyCode of "P"
return hasMeta && e.keyCode === 80;
}

/**
Expand All @@ -659,7 +663,8 @@
*/
function isFindEvent(e) {
const hasMeta = e.ctrlKey || e.metaKey;
return hasMeta && e.key.toLowerCase() === 'f';
// 70: keyCode of "F"
return hasMeta && e.keyCode === 70;
}

/**
Expand All @@ -668,7 +673,8 @@
*/
function isSaveEvent(e) {
const hasMeta = e.ctrlKey || e.metaKey;
return hasMeta && e.key.toLowerCase() === 's';
// 83: keyCode of "S"
return hasMeta && e.keyCode === 83;
}

/**
Expand All @@ -677,7 +683,8 @@
*/
function isCloseTab(e) {
const hasMeta = e.ctrlKey || e.metaKey;
return hasMeta && e.key.toLowerCase() === 'w';
// 87: keyCode of "W"
return hasMeta && e.keyCode === 87;
}

/**
Expand All @@ -686,7 +693,8 @@
*/
function isNewWindow(e) {
const hasMeta = e.ctrlKey || e.metaKey;
return hasMeta && e.key.toLowerCase() === 'n';
// 78: keyCode of "N"
return hasMeta && e.keyCode === 78;
}

let isHandlingScroll = false;
Expand Down