mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-02 19:00:15 +01:00
This commit is contained in:
parent
bb0995eb6b
commit
e1e8eb464b
9 changed files with 77 additions and 49 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue