2023-01-25 10:11:51 +01:00
|
|
|
import CONFIG from "./config"
|
2023-01-20 15:33:26 +01:00
|
|
|
import { isMac } from "./detect-platform"
|
|
|
|
|
|
|
|
|
|
|
|
export function onBeforeInputEvent({win, event, input, currentKeymap}) {
|
|
|
|
//console.log("keyboard event", input)
|
|
|
|
let metaKey = "alt"
|
|
|
|
if (isMac) {
|
2023-01-27 17:18:31 +01:00
|
|
|
metaKey = CONFIG.get("settings.emacsMetaKey", "meta")
|
2023-01-20 15:33:26 +01:00
|
|
|
}
|
|
|
|
if (currentKeymap === "emacs") {
|
|
|
|
/**
|
|
|
|
* When using Emacs keymap, we can't bind shortcuts for copy, cut and paste in the the renderer process
|
|
|
|
* using Codemirror's bind function. Therefore we have to bind them in electron land, and send
|
|
|
|
* cut, paste and copy to window.webContents
|
|
|
|
*/
|
2023-01-25 10:11:51 +01:00
|
|
|
if (input.code === "KeyY" && input.control) {
|
2023-01-20 15:33:26 +01:00
|
|
|
event.preventDefault()
|
|
|
|
win.webContents.paste()
|
2023-01-25 10:11:51 +01:00
|
|
|
} else if (input.code === "KeyW" && input.control) {
|
2023-01-20 15:33:26 +01:00
|
|
|
event.preventDefault()
|
|
|
|
win.webContents.cut()
|
2023-01-25 10:11:51 +01:00
|
|
|
} else if (input.code === "KeyW" && input[metaKey]) {
|
2023-01-20 15:33:26 +01:00
|
|
|
event.preventDefault()
|
|
|
|
win.webContents.copy()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|