Skip to content

Commit 25eef88

Browse files
authored
Merge pull request #2815 from UltimateHackingKeyboard/fix-paste-workaround
fix: paste of macro-command editor
2 parents 37078e3 + f79ec41 commit 25eef88

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

packages/uhk-agent/src/electron-main.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ if (options.help) {
4242
process.exit(0);
4343
}
4444

45+
const isMac = process.platform === "darwin";
4546
const logger = new ElectronLogService();
4647
logger.setLogOptions(getLogOptions(options));
4748
logger.misc('[Electron Main] command line arguments', options);
@@ -163,6 +164,35 @@ async function createWindow() {
163164
win.webContents.on('did-finish-load', () => {
164165
});
165166

167+
// monaco-editor electron 34+ paste workaround https://github.com/microsoft/monaco-editor/issues/4855#issuecomment-3184259279
168+
win.webContents.on("before-input-event", (event, input) => {
169+
const isCmdOrCtrl = isMac ? input.meta === true : input.control === true;
170+
171+
const hasShift =
172+
input.shift === true ||
173+
input.modifiers.includes("shift");
174+
175+
const hasAlt =
176+
input.alt === true ||
177+
input.modifiers.includes("alt");
178+
179+
// Prefer code (layout-agnostic)
180+
const isV = input.code === "KeyV" || input.key === "v";
181+
182+
const shouldPaste =
183+
input.type === 'keyDown' &&
184+
isCmdOrCtrl &&
185+
!hasShift &&
186+
!hasAlt &&
187+
isV;
188+
189+
if (shouldPaste) {
190+
// Native paste path (works with Monaco)
191+
win.webContents.paste();
192+
event.preventDefault();
193+
}
194+
})
195+
166196
win.webContents.on('render-process-gone', (event, details) => {
167197
logger.misc(`[Electron Main] render-process-gone, reason: ${details.reason} exitCode: ${details.exitCode}`);
168198
});

0 commit comments

Comments
 (0)