通过阅读代码,我发现这里的command+s功能应该是和编辑器页面的保存按钮的功能(console/src/modules/contents/pages/SinglePageEditor.vue)是一致的,于是我想在SinglePageEditor.vue添加一个监听快捷键command+s的功能,但是我发无法触发该监听功能。
const isMac = /macintosh|mac os x/i.test(navigator.userAgent);
const handleSaveKeybinding = (e: KeyboardEvent) => {
const { key, ctrlKey, metaKey } = e;
if (key === "j" && ((ctrlKey && !isMac) || metaKey)) {
e.preventDefault();
handleSave();
}
};
onMounted(() => {
document.addEventListener("keydown", handleSaveKeybinding);
});
onUnmounted(() => {
document.removeEventListener("keydown", handleSaveKeybinding);
});