Skip to content

Commit 5b0c1e5

Browse files
authored
Fix select all, undo, and redo on macOS (platformio#3451)
1 parent 835414c commit 5b0c1e5

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/home.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,23 @@ export default class PIOHome {
127127
const iframeId = `pioHomeIFrame-${vscode.env.sessionId}`;
128128
const iframeScript = `
129129
<script>
130-
for (const command of ['selectAll', 'copy', 'paste', 'cut', 'undo', 'redo']) {
130+
function execCommand(data) {
131+
document.getElementById('${iframeId}').contentWindow.postMessage({'command': 'execCommand', 'data': data}, '*');
132+
}
133+
for (const command of ['copy', 'paste', 'cut']) {
131134
document.addEventListener(command, (e) => {
132-
document.getElementById('${iframeId}').contentWindow.postMessage({'command': 'execCommand', 'data': command}, '*');
135+
execCommand(command);
133136
});
134137
}
138+
document.addEventListener('selectstart', (e) => {
139+
execCommand('selectAll');
140+
e.preventDefault();
141+
});
142+
window.addEventListener('keydown', (e) => {
143+
if (e.key === 'z' && e.metaKey) {
144+
execCommand(e.shiftKey ? 'redo' : 'undo');
145+
}
146+
});
135147
window.addEventListener('message', (e) => {
136148
if (e.data.command === 'kbd-event') {
137149
window.dispatchEvent(new KeyboardEvent('keydown', e.data.data));

0 commit comments

Comments
 (0)