From e1e8eb464b8e1e09f9946ae6a299665afaa7df32 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 2 Sep 2022 12:17:10 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/5788 --- app/appearance/langs/en_US.json | 6 +-- app/appearance/langs/es_ES.json | 6 +-- app/appearance/langs/fr_FR.json | 6 +-- app/appearance/langs/zh_CHT.json | 6 +-- app/appearance/langs/zh_CN.json | 6 +-- app/src/constants.ts | 7 ++-- app/src/menus/protyle.ts | 19 ++++++++-- app/src/protyle/util/hotKey.ts | 10 +++-- app/src/protyle/wysiwyg/keydown.ts | 60 ++++++++++++++++++++---------- 9 files changed, 77 insertions(+), 49 deletions(-) diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index af752b16a..25e5282d1 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -118,10 +118,8 @@ "safeQuit": "Quit the application", "anchor": "Anchor", "showMore": "Show More", - "refPopover": "Open the ref block by popover", - "refRight": "Open the ref block on the right", - "refBottom": "Open the ref block on the bottom", - "refTab": "Open the ref block in a new tab", + "refPopover": "Open in Popover", + "refTab": "Open in background tab", "showHideBg": "Show/Hide Background", "directConnection": "Direct connection", "networkProxy": "Network Proxy", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index 66ccbeb54..0e84c0bd4 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -118,10 +118,8 @@ "safeQuit": "Salir de la aplicación", "anchor": "Anclaje", "showMore": "Mostrar más", - "refPopover": "Abrir el bloque de ref mediante popover", - "refRight": "Abrir el bloque de ref a la derecha", - "refBottom": "Abrir el bloque de ref en la parte inferior", - "refTab": "Abrir el bloque de ref en una nueva pestaña", + "refPopover": "Abrir en Popover", + "refTab": "Abrir en la pestaña de fondo", "showHideBg": "Mostrar/Ocultar fondo", "directConnection": "Conexión directa", "networkProxy": "Proxy de red", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index 3d3511959..6835f4df8 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -118,10 +118,8 @@ "safeQuit": "Quitter l'application", "anchor": "ancre", "showMore": "Afficher plus", - "refPopover": "Utiliser la fenêtre flottante pour ouvrir la référence", - "refRight": "Ouvrir le bloc de référence à droite", - "refBottom": "Ouvrir le bloc de référence dans la goutte inférieure", - "refTab": "Ouvrir le bloc de référence dans un nouvel onglet", + "refPopover": "Ouvrir dans Popover", + "refTab": "Ouvrir en arrière-plan", "showHideBg": "Afficher/Masquer l'arrière-plan", "directConnection": "Connexion directe", "networkProxy": "Proxy réseau", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index ae62f01e1..99e28f305 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -118,10 +118,8 @@ "safeQuit": "退出應用", "anchor": "錨點", "showMore": "顯示更多", - "refPopover": "使用浮窗打開引用塊", - "refRight": "在右側打開引用塊", - "refBottom": "在下側打開引用塊", - "refTab": "在新分頁中打開引用塊", + "refPopover": "在浮窗中打開", + "refTab": "在後台頁簽中打開", "showHideBg": "顯示/隱藏背景", "directConnection": "直接連接", "networkProxy": "網路代理", diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index f47fa3f73..b8f679ab5 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -118,10 +118,8 @@ "safeQuit": "退出应用", "anchor": "锚文本", "showMore": "显示更多", - "refPopover": "使用浮窗打开引用块", - "refRight": "在右侧打开引用块", - "refBottom": "在下侧打开引用块", - "refTab": "在新页签中打开引用块", + "refPopover": "在浮窗中打开", + "refTab": "在后台页签中打开", "showHideBg": "显示/隐藏背景", "directConnection": "直接连接", "networkProxy": "网络代理", diff --git a/app/src/constants.ts b/app/src/constants.ts index e4e4b458c..dcd7de432 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -125,10 +125,11 @@ export abstract class Constants { netImg2LocalAsset: {default: "", custom: ""}, hLayout: {default: "", custom: ""}, vLayout: {default: "", custom: ""}, - refBottom: {default: "⇧>", custom: "⇧>"}, - refRight: {default: "⌥.", custom: "⌥."}, - refPopover: {default: "⌥⌘.", custom: "⌥⌘."}, + refPopover: {default: "", custom: ""}, + insertBottom: {default: "⌥⌘.", custom: "⌥⌘."}, refTab: {default: "⇧⌘.", custom: "⇧⌘."}, + openBy: {default: "⌘.", custom: "⌘."}, + insertRight: {default: "⌥.", custom: "⌥."}, attr: {default: "⌥⌘A", custom: "⌥⌘A"}, refresh: {default: "F5", custom: "F5"}, copyBlockRef: {default: "⇧⌘C", custom: "⇧⌘C"}, diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index ff4b3609f..693b03741 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -91,7 +91,20 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => { /// #if !MOBILE window.siyuan.menus.menu.append(new MenuItem({ label: window.siyuan.languages.openBy, - accelerator: "⌘Click", + accelerator: window.siyuan.config.keymap.editor.general.openBy.custom + "/Click", + click() { + fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => { + openFileById({ + id: refBlockId, + action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT], + zoomIn: foldResponse.data + }); + }); + } + }).element); + window.siyuan.menus.menu.append(new MenuItem({ + label: window.siyuan.languages.refTab, + accelerator: window.siyuan.config.keymap.editor.general.refTab.custom + "/⌘Click", click() { fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => { openFileById({ @@ -106,7 +119,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => { window.siyuan.menus.menu.append(new MenuItem({ label: window.siyuan.languages.insertRight, icon: "iconRight", - accelerator: window.siyuan.config.keymap.editor.general.refBottom.custom + "/⌥Click", + accelerator: window.siyuan.config.keymap.editor.general.insertRight.custom + "/⌥Click", click() { fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => { openFileById({ @@ -121,7 +134,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => { window.siyuan.menus.menu.append(new MenuItem({ label: window.siyuan.languages.insertBottom, icon: "iconDown", - accelerator: "⇧Click", + accelerator: window.siyuan.config.keymap.editor.general.insertBottom.custom + (window.siyuan.config.keymap.editor.general.insertBottom.custom ? "/" : "") + "⇧Click", click() { fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => { openFileById({ diff --git a/app/src/protyle/util/hotKey.ts b/app/src/protyle/util/hotKey.ts index 9408cd7f0..54f62d657 100644 --- a/app/src/protyle/util/hotKey.ts +++ b/app/src/protyle/util/hotKey.ts @@ -69,17 +69,21 @@ export const matchHotKey = (hotKey: string, event: KeyboardEvent) => { // 是否匹配 ⇧⌘[] / ⌘[] const hasShift = hotKeys.length > 2 && (hotKeys[0] === "⇧"); let key = (hasShift ? hotKeys[2] : hotKeys[1]); - if (hasShift // 更新 electron 后不需要判断 mac && !/Mac/.test(navigator.platform) - ) { + let keyCode + // 更新 electron 后不需要判断 Mac,但 Mac 下中英文有区别,需使用 keyCode 辅助 + if (hasShift) { if (key === "-") { key = "_"; + keyCode = 189; } else if (key === "=") { key = "+"; + keyCode = 187; } else if (key === ".") { key = ">"; + keyCode = 190; } } - if (isCtrl(event) && event.key.toLowerCase() === key.toLowerCase() && !event.altKey + if (isCtrl(event) && (event.key.toLowerCase() === key.toLowerCase() || event.keyCode === keyCode) && !event.altKey && ((!hasShift && !event.shiftKey) || (hasShift && event.shiftKey))) { return true; } diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 7bd583bcc..0adc67703 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -1591,43 +1591,63 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { const refElement = hasClosestByAttribute(range.startContainer, "data-type", "block-ref"); if (refElement) { const id = refElement.getAttribute("data-id"); - if (matchHotKey(window.siyuan.config.keymap.editor.general.refPopover.custom, event)) { - // open popover - window.siyuan.blockPanels.push(new BlockPanel({ - targetElement: refElement, - nodeIds: [id], - })); + if (matchHotKey(window.siyuan.config.keymap.editor.general.openBy.custom, event)) { + fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { + openFileById({ + id, + action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT], + zoomIn: foldResponse.data + }); + }); event.preventDefault(); event.stopPropagation(); return true; } else if (matchHotKey(window.siyuan.config.keymap.editor.general.refTab.custom, event)) { // 打开块引和编辑器中引用、反链、书签中点击事件需保持一致,都加载上下文 - openFileById({ - id, - keepCursor: true, - action: [Constants.CB_GET_CONTEXT] + fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { + openFileById({ + id, + action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT], + keepCursor: true, + zoomIn: foldResponse.data + }); }); event.preventDefault(); event.stopPropagation(); return true; - } else if (matchHotKey(window.siyuan.config.keymap.editor.general.refRight.custom, event)) { - openFileById({ - id, - position: "right", - action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT] + } else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertRight.custom, event)) { + fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { + openFileById({ + id, + position: "right", + action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT], + zoomIn: foldResponse.data + }); }); event.preventDefault(); event.stopPropagation(); return true; - } else if (matchHotKey(window.siyuan.config.keymap.editor.general.refBottom.custom, event)) { - openFileById({ - id, - position: "bottom", - action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT] + } else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertBottom.custom, event)) { + fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { + openFileById({ + id, + position: "bottom", + action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT], + zoomIn: foldResponse.data + }); }); event.preventDefault(); event.stopPropagation(); return true; + }else if (matchHotKey(window.siyuan.config.keymap.editor.general.refPopover.custom, event)) { + // open popover + window.siyuan.blockPanels.push(new BlockPanel({ + targetElement: refElement, + nodeIds: [id], + })); + event.preventDefault(); + event.stopPropagation(); + return true; } } /// #endif