Vanessa 2022-09-02 12:17:10 +08:00
parent bb0995eb6b
commit e1e8eb464b
9 changed files with 77 additions and 49 deletions

View file

@ -118,10 +118,8 @@
"safeQuit": "Quit the application", "safeQuit": "Quit the application",
"anchor": "Anchor", "anchor": "Anchor",
"showMore": "Show More", "showMore": "Show More",
"refPopover": "Open the ref block by popover", "refPopover": "Open in Popover",
"refRight": "Open the ref block on the right", "refTab": "Open in background tab",
"refBottom": "Open the ref block on the bottom",
"refTab": "Open the ref block in a new tab",
"showHideBg": "Show/Hide Background", "showHideBg": "Show/Hide Background",
"directConnection": "Direct connection", "directConnection": "Direct connection",
"networkProxy": "Network Proxy", "networkProxy": "Network Proxy",

View file

@ -118,10 +118,8 @@
"safeQuit": "Salir de la aplicación", "safeQuit": "Salir de la aplicación",
"anchor": "Anclaje", "anchor": "Anclaje",
"showMore": "Mostrar más", "showMore": "Mostrar más",
"refPopover": "Abrir el bloque de ref mediante popover", "refPopover": "Abrir en Popover",
"refRight": "Abrir el bloque de ref a la derecha", "refTab": "Abrir en la pestaña de fondo",
"refBottom": "Abrir el bloque de ref en la parte inferior",
"refTab": "Abrir el bloque de ref en una nueva pestaña",
"showHideBg": "Mostrar/Ocultar fondo", "showHideBg": "Mostrar/Ocultar fondo",
"directConnection": "Conexión directa", "directConnection": "Conexión directa",
"networkProxy": "Proxy de red", "networkProxy": "Proxy de red",

View file

@ -118,10 +118,8 @@
"safeQuit": "Quitter l'application", "safeQuit": "Quitter l'application",
"anchor": "ancre", "anchor": "ancre",
"showMore": "Afficher plus", "showMore": "Afficher plus",
"refPopover": "Utiliser la fenêtre flottante pour ouvrir la référence", "refPopover": "Ouvrir dans Popover",
"refRight": "Ouvrir le bloc de référence à droite", "refTab": "Ouvrir en arrière-plan",
"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",
"showHideBg": "Afficher/Masquer l'arrière-plan", "showHideBg": "Afficher/Masquer l'arrière-plan",
"directConnection": "Connexion directe", "directConnection": "Connexion directe",
"networkProxy": "Proxy réseau", "networkProxy": "Proxy réseau",

View file

@ -118,10 +118,8 @@
"safeQuit": "退出應用", "safeQuit": "退出應用",
"anchor": "錨點", "anchor": "錨點",
"showMore": "顯示更多", "showMore": "顯示更多",
"refPopover": "使用浮窗打開引用塊", "refPopover": "在浮窗中打開",
"refRight": "在右側打開引用塊", "refTab": "在後台頁簽中打開",
"refBottom": "在下側打開引用塊",
"refTab": "在新分頁中打開引用塊",
"showHideBg": "顯示/隱藏背景", "showHideBg": "顯示/隱藏背景",
"directConnection": "直接連接", "directConnection": "直接連接",
"networkProxy": "網路代理", "networkProxy": "網路代理",

View file

@ -118,10 +118,8 @@
"safeQuit": "退出应用", "safeQuit": "退出应用",
"anchor": "锚文本", "anchor": "锚文本",
"showMore": "显示更多", "showMore": "显示更多",
"refPopover": "使用浮窗打开引用块", "refPopover": "在浮窗中打开",
"refRight": "在右侧打开引用块", "refTab": "在后台页签中打开",
"refBottom": "在下侧打开引用块",
"refTab": "在新页签中打开引用块",
"showHideBg": "显示/隐藏背景", "showHideBg": "显示/隐藏背景",
"directConnection": "直接连接", "directConnection": "直接连接",
"networkProxy": "网络代理", "networkProxy": "网络代理",

View file

@ -125,10 +125,11 @@ export abstract class Constants {
netImg2LocalAsset: {default: "", custom: ""}, netImg2LocalAsset: {default: "", custom: ""},
hLayout: {default: "", custom: ""}, hLayout: {default: "", custom: ""},
vLayout: {default: "", custom: ""}, vLayout: {default: "", custom: ""},
refBottom: {default: "⇧>", custom: "⇧>"}, refPopover: {default: "", custom: ""},
refRight: {default: "⌥.", custom: "⌥."}, insertBottom: {default: "⌥⌘.", custom: "⌥⌘."},
refPopover: {default: "⌥⌘.", custom: "⌥⌘."},
refTab: {default: "⇧⌘.", custom: "⇧⌘."}, refTab: {default: "⇧⌘.", custom: "⇧⌘."},
openBy: {default: "⌘.", custom: "⌘."},
insertRight: {default: "⌥.", custom: "⌥."},
attr: {default: "⌥⌘A", custom: "⌥⌘A"}, attr: {default: "⌥⌘A", custom: "⌥⌘A"},
refresh: {default: "F5", custom: "F5"}, refresh: {default: "F5", custom: "F5"},
copyBlockRef: {default: "⇧⌘C", custom: "⇧⌘C"}, copyBlockRef: {default: "⇧⌘C", custom: "⇧⌘C"},

View file

@ -91,7 +91,20 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
/// #if !MOBILE /// #if !MOBILE
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.openBy, 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() { click() {
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => { fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
openFileById({ openFileById({
@ -106,7 +119,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.insertRight, label: window.siyuan.languages.insertRight,
icon: "iconRight", icon: "iconRight",
accelerator: window.siyuan.config.keymap.editor.general.refBottom.custom + "/⌥Click", accelerator: window.siyuan.config.keymap.editor.general.insertRight.custom + "/⌥Click",
click() { click() {
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => { fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
openFileById({ openFileById({
@ -121,7 +134,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.insertBottom, label: window.siyuan.languages.insertBottom,
icon: "iconDown", icon: "iconDown",
accelerator: "⇧Click", accelerator: window.siyuan.config.keymap.editor.general.insertBottom.custom + (window.siyuan.config.keymap.editor.general.insertBottom.custom ? "/" : "") + "⇧Click",
click() { click() {
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => { fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
openFileById({ openFileById({

View file

@ -69,17 +69,21 @@ export const matchHotKey = (hotKey: string, event: KeyboardEvent) => {
// 是否匹配 ⇧⌘[] / ⌘[] // 是否匹配 ⇧⌘[] / ⌘[]
const hasShift = hotKeys.length > 2 && (hotKeys[0] === "⇧"); const hasShift = hotKeys.length > 2 && (hotKeys[0] === "⇧");
let key = (hasShift ? hotKeys[2] : hotKeys[1]); 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 === "-") { if (key === "-") {
key = "_"; key = "_";
keyCode = 189;
} else if (key === "=") { } else if (key === "=") {
key = "+"; key = "+";
keyCode = 187;
} else if (key === ".") { } else if (key === ".") {
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))) { && ((!hasShift && !event.shiftKey) || (hasShift && event.shiftKey))) {
return true; return true;
} }

View file

@ -1591,40 +1591,60 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
const refElement = hasClosestByAttribute(range.startContainer, "data-type", "block-ref"); const refElement = hasClosestByAttribute(range.startContainer, "data-type", "block-ref");
if (refElement) { if (refElement) {
const id = refElement.getAttribute("data-id"); const id = refElement.getAttribute("data-id");
if (matchHotKey(window.siyuan.config.keymap.editor.general.refPopover.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.editor.general.openBy.custom, event)) {
// open popover fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
window.siyuan.blockPanels.push(new BlockPanel({ openFileById({
targetElement: refElement, id,
nodeIds: [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.preventDefault();
event.stopPropagation(); event.stopPropagation();
return true; return true;
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.refTab.custom, event)) { } else if (matchHotKey(window.siyuan.config.keymap.editor.general.refTab.custom, event)) {
// 打开块引和编辑器中引用、反链、书签中点击事件需保持一致,都加载上下文 // 打开块引和编辑器中引用、反链、书签中点击事件需保持一致,都加载上下文
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openFileById({ openFileById({
id, id,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
keepCursor: true, keepCursor: true,
action: [Constants.CB_GET_CONTEXT] zoomIn: foldResponse.data
});
}); });
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return true; return true;
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.refRight.custom, event)) { } else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertRight.custom, event)) {
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openFileById({ openFileById({
id, id,
position: "right", position: "right",
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT] 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.preventDefault();
event.stopPropagation(); event.stopPropagation();
return true; return true;
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.refBottom.custom, event)) { } else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertBottom.custom, event)) {
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openFileById({ openFileById({
id, id,
position: "bottom", position: "bottom",
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT] 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.preventDefault();
event.stopPropagation(); event.stopPropagation();
return true; return true;