diff --git a/electron/config.js b/electron/config.js index 05b411c..ae60a9f 100644 --- a/electron/config.js +++ b/electron/config.js @@ -16,6 +16,7 @@ const schema = { additionalProperties: false, }, keymap: { "enum": ["default", "emacs"] }, + emacsMetaKey: { "enum": [null, "alt", "meta"] }, } export default new Store({schema}) diff --git a/electron/keymap.js b/electron/keymap.js index 89269e4..0351a51 100644 --- a/electron/keymap.js +++ b/electron/keymap.js @@ -1,3 +1,4 @@ +import CONFIG from "./config" import { isMac } from "./detect-platform" @@ -5,7 +6,7 @@ export function onBeforeInputEvent({win, event, input, currentKeymap}) { //console.log("keyboard event", input) let metaKey = "alt" if (isMac) { - metaKey = "meta" + metaKey = CONFIG.get("emacsMetaKey", "meta") } if (currentKeymap === "emacs") { /** @@ -13,13 +14,13 @@ export function onBeforeInputEvent({win, event, input, currentKeymap}) { * using Codemirror's bind function. Therefore we have to bind them in electron land, and send * cut, paste and copy to window.webContents */ - if (input.key === "y" && input.control) { + if (input.code === "KeyY" && input.control) { event.preventDefault() win.webContents.paste() - } else if (input.key === "w" && input.control) { + } else if (input.code === "KeyW" && input.control) { event.preventDefault() win.webContents.cut() - } else if (input.key === "w" && input[metaKey]) { + } else if (input.code === "KeyW" && input[metaKey]) { event.preventDefault() win.webContents.copy() } diff --git a/electron/preload/index.ts b/electron/preload/index.ts index 70be236..42535ba 100644 --- a/electron/preload/index.ts +++ b/electron/preload/index.ts @@ -5,14 +5,16 @@ import { ipcRenderer } from "electron" import { WINDOW_CLOSE_EVENT, KEYMAP_CHANGE_EVENT, OPEN_SETTINGS_EVENT } from "../constants" import CONFIG from "../config" -contextBridge.exposeInMainWorld("platform", { - isMac, - isWindows, - isLinux, -}) +//contextBridge.exposeInMainWorld("platform", ) contextBridge.exposeInMainWorld('darkMode', darkMode) contextBridge.exposeInMainWorld("heynote", { + platform: { + isMac, + isWindows, + isLinux, + }, + quit() { console.log("quitting") //ipcRenderer.invoke("app_quit") @@ -30,7 +32,7 @@ contextBridge.exposeInMainWorld("heynote", { async load() { return await ipcRenderer.invoke("buffer-content:load") }, - + async save(content) { return await ipcRenderer.invoke("buffer-content:save", content) }, @@ -44,7 +46,11 @@ contextBridge.exposeInMainWorld("heynote", { set(keymap) { ipcRenderer.invoke("keymap:set", keymap); }, + setEmacsMetaKey(key) { + CONFIG.set("emacsMetaKey", key) + }, initial: CONFIG.get("keymap", "default"), + getEmacsMetaKey: () => CONFIG.get("emacsMetaKey", isMac ? "meta" : "alt"), onKeymapChange(callback) { ipcRenderer.on(KEYMAP_CHANGE_EVENT, (event, keymap) => callback(keymap)) }, diff --git a/src/components/App.vue b/src/components/App.vue index 940faa4..45c8845 100644 --- a/src/components/App.vue +++ b/src/components/App.vue @@ -127,7 +127,7 @@ /> diff --git a/src/components/settings/Settings.vue b/src/components/settings/Settings.vue index f428e41..f21cfc7 100644 --- a/src/components/settings/Settings.vue +++ b/src/components/settings/Settings.vue @@ -1,7 +1,19 @@