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

View file

@ -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"},

View file

@ -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({

View file

@ -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;
}

View file

@ -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