Skip to content

Commit 6e9320b

Browse files
Fix broken paste command on desktop (#8247)
Do not show in changelog
1 parent 74a8e62 commit 6e9320b

File tree

4 files changed

+60
-46
lines changed

4 files changed

+60
-46
lines changed

.semaphore/semaphore.yml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,15 @@ blocks:
9494
GDJS_KEY="GDJS-node_modules-$SEMAPHORE_GIT_BRANCH-revision-$(checksum GDJS/package-lock.json)"
9595
9696
if can_use_cache; then
97+
echo "Restoring caches..."
9798
cache restore "${NEWIDE_KEY}"
9899
cache restore "${GDJS_KEY}"
99100
else
100101
echo "Fork PR: skipping cache restore"
101-
(cd newIDE/app && npm i)
102-
(cd GDJS && git checkout package-lock.json && npm i)
103102
fi
103+
104+
(cd newIDE/app && npm i)
105+
(cd GDJS && git checkout package-lock.json && npm i)
104106
- cd newIDE/app
105107
- npm run postinstall
106108
- npm run flow
@@ -120,15 +122,17 @@ blocks:
120122
GDJS_TESTS_KEY="GDJS-tests-node_modules-$SEMAPHORE_GIT_BRANCH-revision-$(checksum GDJS/tests/package-lock.json)"
121123
122124
if can_use_cache; then
125+
echo "Restoring caches..."
123126
cache restore "${NEWIDE_KEY}"
124127
cache restore "${GDJS_KEY}"
125128
cache restore "${GDJS_TESTS_KEY}"
126129
else
127130
echo "Fork PR: skipping cache restore"
128-
(cd newIDE/app && npm i)
129-
(cd GDJS && git checkout package-lock.json && npm i)
130-
(cd GDJS/tests && npm i)
131131
fi
132+
133+
(cd newIDE/app && npm i)
134+
(cd GDJS && git checkout package-lock.json && npm i)
135+
(cd GDJS/tests && npm i)
132136
- cd GDJS
133137
- npm run check-types
134138
- npm run generate-doc
@@ -151,13 +155,15 @@ blocks:
151155
GDJS_KEY="GDJS-node_modules-$SEMAPHORE_GIT_BRANCH-revision-$(checksum GDJS/package-lock.json)"
152156
153157
if can_use_cache; then
158+
echo "Restoring caches..."
154159
cache restore "${NEWIDE_KEY}"
155160
cache restore "${GDJS_KEY}"
156161
else
157162
echo "Fork PR: skipping cache restore"
158-
(cd newIDE/app && npm i)
159-
(cd GDJS && git checkout package-lock.json && npm i)
160163
fi
164+
165+
(cd newIDE/app && npm i)
166+
(cd GDJS && git checkout package-lock.json && npm i)
161167
- cd newIDE/app
162168
- npm run postinstall
163169
- npm run check-format
@@ -174,11 +180,13 @@ blocks:
174180
GDJS_KEY="GDJS-node_modules-$SEMAPHORE_GIT_BRANCH-revision-$(checksum GDJS/package-lock.json)"
175181
176182
if can_use_cache; then
183+
echo "Restoring cache..."
177184
cache restore "${GDJS_KEY}"
178185
else
179186
echo "Fork PR: skipping cache restore"
180-
(cd GDJS && git checkout package-lock.json && npm i)
181187
fi
188+
189+
(cd GDJS && git checkout package-lock.json && npm i)
182190
- cd GDJS
183191
- npm run check-format
184192

@@ -200,13 +208,15 @@ blocks:
200208
GDJS_KEY="GDJS-node_modules-$SEMAPHORE_GIT_BRANCH-revision-$(checksum GDJS/package-lock.json)"
201209
202210
if can_use_cache; then
211+
echo "Restoring caches..."
203212
cache restore "${NEWIDE_KEY}"
204213
cache restore "${GDJS_KEY}"
205214
else
206215
echo "Fork PR: skipping cache restore"
207-
(cd newIDE/app && npm i)
208-
(cd GDJS && git checkout package-lock.json && npm i)
209216
fi
217+
218+
(cd newIDE/app && npm i)
219+
(cd GDJS && git checkout package-lock.json && npm i)
210220
- cd newIDE/app
211221
- npm run postinstall
212222
- npm run analyze-test-coverage
@@ -224,13 +234,15 @@ blocks:
224234
GDJS_TESTS_KEY="GDJS-tests-node_modules-$SEMAPHORE_GIT_BRANCH-revision-$(checksum GDJS/tests/package-lock.json)"
225235
226236
if can_use_cache; then
237+
echo "Restoring caches..."
227238
cache restore "${GDJS_KEY}"
228239
cache restore "${GDJS_TESTS_KEY}"
229240
else
230241
echo "Fork PR: skipping cache restore"
231-
(cd GDJS && git checkout package-lock.json && npm i)
232-
(cd GDJS/tests && npm i)
233242
fi
243+
244+
(cd GDJS && git checkout package-lock.json && npm i)
245+
(cd GDJS/tests && npm i)
234246
- cd GDJS
235247
- npm run build
236248
- sudo apt-get install -y libegl1 libgl1-mesa-dri libgbm1 xvfb
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
diff --git a/node_modules/monaco-editor/esm/vs/editor/contrib/clipboard/clipboard.js b/node_modules/monaco-editor/esm/vs/editor/contrib/clipboard/clipboard.js
2+
--- a/node_modules/monaco-editor/esm/vs/editor/contrib/clipboard/clipboard.js
3+
+++ b/node_modules/monaco-editor/esm/vs/editor/contrib/clipboard/clipboard.js
4+
@@ -49,7 +49,20 @@
5+
};
6+
ExecCommandAction.prototype.run = function (accessor, editor) {
7+
editor.focus();
8+
- document.execCommand(this.browserCommand);
9+
+ var result = document.execCommand(this.browserCommand);
10+
+ // Fallback for Electron where document.execCommand('paste') fails
11+
+ // in newer Chromium versions. Use Electron's clipboard API instead.
12+
+ // See https://github.com/microsoft/monaco-editor/issues/4855
13+
+ if (!result && this.browserCommand === 'paste') {
14+
+ try {
15+
+ var text = window.require('electron').clipboard.readText();
16+
+ if (text) {
17+
+ editor.trigger('keyboard', 'type', { text: text });
18+
+ }
19+
+ } catch (e) {
20+
+ // Not in Electron environment, ignore
21+
+ }
22+
+ }
23+
};
24+
return ExecCommandAction;
25+
}(EditorAction));

newIDE/electron-app/app/main.js

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,6 @@ const {
4646
} = require('./LocalGDJSDevelopmentWatcher');
4747
const { setupWatcher, disableWatcher } = require('./LocalFilesystemWatcher');
4848

49-
const isMac = process.platform === 'darwin';
50-
51-
/**
52-
* Ensures paste operations work in all web content (notably Monaco editor)
53-
* by intercepting Cmd/Ctrl+V before Electron's menu accelerators consume the
54-
* event, and explicitly calling webContents.paste().
55-
* See https://github.com/microsoft/monaco-editor/issues/4855
56-
*
57-
* This may be fixed in future monaco-editor versions, starting from 0.56.0 when it's released.
58-
*/
59-
const setupPasteHandler = window => {
60-
window.webContents.on('before-input-event', (event, input) => {
61-
const isCmdOrCtrl = isMac ? input.meta === true : input.control === true;
62-
const hasShift = input.shift === true;
63-
const hasAlt = input.alt === true;
64-
const isV = input.code === 'KeyV' || input.key === 'v';
65-
const shouldPaste =
66-
input.type === 'keyDown' && isCmdOrCtrl && !hasShift && !hasAlt && isV;
67-
68-
if (shouldPaste) {
69-
window.webContents.paste();
70-
event.preventDefault();
71-
}
72-
});
73-
};
74-
7549
// Initialize `@electron/remote` module
7650
require('@electron/remote/main').initialize();
7751

@@ -234,9 +208,6 @@ function createNewWindow(windowArgs = args) {
234208
// Enable `@electron/remote` module for renderer process
235209
require('@electron/remote/main').enable(newWindow.webContents);
236210

237-
// Ensure paste works in web content (e.g., Monaco editor).
238-
setupPasteHandler(newWindow);
239-
240211
// Log process ID to verify separate renderer processes
241212
newWindow.webContents.once('did-finish-load', () => {
242213
newWindow.webContents
@@ -615,19 +586,25 @@ app.on('ready', function() {
615586
// app quits.
616587
log.info('Starting check for updates (with auto-download if any)');
617588
autoUpdater.autoDownload = true;
618-
autoUpdater.checkForUpdatesAndNotify();
589+
autoUpdater.checkForUpdatesAndNotify().catch(err => {
590+
log.error('Error checking for updates:', err);
591+
});
619592
});
620593

621594
ipcMain.on('updates-check', event => {
622595
log.info('Starting check for updates (without auto-download)');
623596
autoUpdater.autoDownload = false;
624-
autoUpdater.checkForUpdates();
597+
autoUpdater.checkForUpdates().catch(err => {
598+
log.error('Error checking for updates:', err);
599+
});
625600
});
626601

627602
function sendUpdateStatus(status) {
628603
log.info(status);
629604
mainWindows.forEach(window => {
630-
window.webContents.send('update-status', status);
605+
if (!window.isDestroyed()) {
606+
window.webContents.send('update-status', status);
607+
}
631608
});
632609
}
633610
autoUpdater.on('checking-for-update', () => {

newIDE/electron-app/app/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)