mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-23 15:34:06 +01:00
This commit is contained in:
parent
2c71478d83
commit
4f263b31cc
19 changed files with 110 additions and 88 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import {isCtrl} from "./compatibility";
|
||||
import {isNotCtrl, isOnlyMeta} from "./compatibility";
|
||||
import {Constants} from "../../constants";
|
||||
|
||||
// 是否匹配 ⇧⌘[] / ⌘[] / ⌥[] / ⌥⌘[] / ⌥⇧[] / ⌥⇧⌘[] / ⇧[] / []
|
||||
|
|
@ -9,7 +9,7 @@ export const matchHotKey = (hotKey: string, event: KeyboardEvent) => {
|
|||
|
||||
// []
|
||||
if (hotKey.indexOf("⇧") === -1 && hotKey.indexOf("⌘") === -1 && hotKey.indexOf("⌥") === -1 && hotKey.indexOf("⌃") === -1) {
|
||||
if (!event.ctrlKey && !isCtrl(event) && !event.altKey && !event.shiftKey && hotKey === Constants.KEYCODELIST[event.keyCode]) {
|
||||
if (isNotCtrl(event) && !event.altKey && !event.shiftKey && hotKey === Constants.KEYCODELIST[event.keyCode]) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -30,7 +30,7 @@ export const matchHotKey = (hotKey: string, event: KeyboardEvent) => {
|
|||
|
||||
// 是否匹配 ⇧[]
|
||||
if (hotKey.startsWith("⇧") && hotKeys.length === 2) {
|
||||
if (!event.ctrlKey && !isCtrl(event) && !event.altKey && event.shiftKey && hotKeys[1] === Constants.KEYCODELIST[event.keyCode]) {
|
||||
if (isNotCtrl(event) && !event.altKey && event.shiftKey && hotKeys[1] === Constants.KEYCODELIST[event.keyCode]) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -45,33 +45,35 @@ export const matchHotKey = (hotKey: string, event: KeyboardEvent) => {
|
|||
const isMatchKey = keyCode === Constants.KEYCODELIST[event.keyCode];
|
||||
// 是否匹配 ⌥[] / ⌥⌘[]
|
||||
if (isMatchKey && event.altKey && !event.shiftKey &&
|
||||
(hotKeys.length === 3 ? (isCtrl(event) && hotKey.startsWith("⌥⌘")) : !isCtrl(event))) {
|
||||
(hotKeys.length === 3 ? (isOnlyMeta(event) && hotKey.startsWith("⌥⌘")) : isNotCtrl(event))) {
|
||||
return true;
|
||||
}
|
||||
// ⌥⇧⌘[]
|
||||
if (isMatchKey && hotKey.startsWith("⌥⇧⌘") && hotKeys.length === 4 &&
|
||||
event.altKey && event.shiftKey && isCtrl(event)) {
|
||||
event.altKey && event.shiftKey && isOnlyMeta(event)) {
|
||||
return true;
|
||||
}
|
||||
// ⌥⇧[]
|
||||
if (isMatchKey && hotKey.startsWith("⌥⇧") && hotKeys.length === 3 &&
|
||||
event.altKey && event.shiftKey && !isCtrl(event)) {
|
||||
event.altKey && event.shiftKey && isNotCtrl(event)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 是否匹配 ⌃[] / ⌃⌥[] / ⌃⇧[]/ ⌃⌥⇧[]
|
||||
// 是否匹配 ⌃[] / ⌃⌘[] / ⌃⌥[] / ⌃⇧[]/ ⌃⌥⇧[]
|
||||
if (hotKey.startsWith("⌃")) {
|
||||
let keyCode = hotKeys.length === 3 ? hotKeys[2] : hotKeys[1];
|
||||
if (hotKeys.length === 4) {
|
||||
keyCode = hotKeys[3];
|
||||
} else if (hotKeys.length === 5) {
|
||||
keyCode = hotKeys[4];
|
||||
}
|
||||
|
||||
const isMatchKey = keyCode === Constants.KEYCODELIST[event.keyCode];
|
||||
// 是否匹配 ⌃[]
|
||||
if (isMatchKey && hotKeys.length === 2 &&
|
||||
event.ctrlKey && !event.altKey && !event.shiftKey && !event.metaKey) {
|
||||
// 是否匹配 ⌃[] / ⌃⌘[]
|
||||
if (isMatchKey && event.ctrlKey && !event.altKey && !event.shiftKey && hotKeys.length < 4 &&
|
||||
(hotKeys.length === 3 ? (event.metaKey && hotKey.startsWith("⌃⌘")) : !event.metaKey)) {
|
||||
return true;
|
||||
}
|
||||
// ⌃⇧[]
|
||||
|
|
@ -84,9 +86,19 @@ export const matchHotKey = (hotKey: string, event: KeyboardEvent) => {
|
|||
event.ctrlKey && event.altKey && !event.shiftKey && !event.metaKey) {
|
||||
return true;
|
||||
}
|
||||
// ⌃⌥⇧[]
|
||||
if (isMatchKey && hotKey.startsWith("⌃⌥⇧") && hotKeys.length === 4 &&
|
||||
event.ctrlKey && event.altKey && event.shiftKey && !event.metaKey) {
|
||||
// ⌃⌥⇧[] / ⌃⌥⌘[] / ⌃⇧⌘[]
|
||||
if (isMatchKey && hotKeys.length === 4 && event.ctrlKey &&
|
||||
(
|
||||
(hotKey.startsWith("⌃⌥⇧") && event.shiftKey && !event.metaKey && event.altKey) ||
|
||||
(hotKey.startsWith("⌃⌥⌘") && !event.shiftKey && event.metaKey && event.altKey) ||
|
||||
(hotKey.startsWith("⌃⇧⌘") && event.shiftKey && event.metaKey && !event.altKey)
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// ⌃⌥⇧⌘[]
|
||||
if (isMatchKey && hotKeys.length === 5 && event.ctrlKey && event.shiftKey && event.metaKey && event.altKey) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -94,7 +106,7 @@ export const matchHotKey = (hotKey: string, event: KeyboardEvent) => {
|
|||
|
||||
// 是否匹配 ⇧⌘[] / ⌘[]
|
||||
const hasShift = hotKeys.length > 2 && (hotKeys[0] === "⇧");
|
||||
if (isCtrl(event) && !event.altKey && ((!hasShift && !event.shiftKey) || (hasShift && event.shiftKey))) {
|
||||
if (isOnlyMeta(event) && !event.altKey && ((!hasShift && !event.shiftKey) || (hasShift && event.shiftKey))) {
|
||||
return (hasShift ? hotKeys[2] : hotKeys[1]) === Constants.KEYCODELIST[event.keyCode];
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue