|
40 | 40 | return; |
41 | 41 | } |
42 | 42 |
|
43 | | - // filter to events that either have modifiers or do not have a character representation. |
44 | | - if (!(event.ctrlKey || event.altKey || event.metaKey) && event.key.length === 1) { |
| 43 | + const isNonEditingKey = |
| 44 | + event.key === 'Escape' || |
| 45 | + /^F\d+$/.test(event.key) || |
| 46 | + event.key.startsWith('Audio') || event.key.startsWith('Media') || event.key.startsWith('Browser'); |
| 47 | + |
| 48 | + // Only forward if there's a command modifier or it's a non-editing key |
| 49 | + // (most plain key events should just be handled natively by the browser and not forwarded) |
| 50 | + if (!(event.ctrlKey || event.altKey || event.metaKey) && !isNonEditingKey) { |
45 | 51 | return; |
46 | 52 | } |
47 | 53 |
|
| 54 | + const isMac = navigator.platform.indexOf('Mac') >= 0; |
| 55 | + |
| 56 | + // Alt+Key special character handling (Alt + Numpad keys on Windows/Linux, Alt + any key on Mac) |
| 57 | + if (event.altKey && !event.ctrlKey && !event.metaKey) { |
| 58 | + if (isMac || /^Numpad\d+$/.test(event.code)) { |
| 59 | + return; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + // Allow native shortcuts (copy, paste, cut, undo, redo, select all) to be handled by the browser |
| 64 | + const ctrlCmd = isMac ? event.metaKey : event.ctrlKey; |
| 65 | + if (ctrlCmd && !event.altKey) { |
| 66 | + const key = event.key.toLowerCase(); |
| 67 | + if (!event.shiftKey && (key === 'a' || key === 'c' || key === 'v' || key === 'x' || key === 'z')) { |
| 68 | + return; |
| 69 | + } |
| 70 | + if (event.shiftKey && (key === 'v' || key === 'z')) { |
| 71 | + return; |
| 72 | + } |
| 73 | + // Ctrl+Y is redo on Windows/Linux |
| 74 | + if (!event.shiftKey && key === 'y' && !isMac) { |
| 75 | + return; |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + // Everything else should be forwarded to the workbench for potential shortcut handling. |
| 80 | + event.preventDefault(); |
| 81 | + event.stopPropagation(); |
48 | 82 | ipcRenderer.send('vscode:browserView:keydown', { |
49 | 83 | key: event.key, |
50 | 84 | keyCode: event.keyCode, |
|
0 commit comments