mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-12 10:14:21 +01:00
This commit is contained in:
parent
2c71478d83
commit
4f263b31cc
19 changed files with 110 additions and 88 deletions
|
|
@ -73,8 +73,7 @@ export const getEventName = () => {
|
|||
}
|
||||
};
|
||||
|
||||
// 区别 mac 上的 ctrl 和 meta
|
||||
export const isCtrl = (event: KeyboardEvent | MouseEvent) => {
|
||||
export const isOnlyMeta = (event: KeyboardEvent | MouseEvent) => {
|
||||
if (isMac()) {
|
||||
// mac
|
||||
if (event.metaKey && !event.ctrlKey) {
|
||||
|
|
@ -89,6 +88,13 @@ export const isCtrl = (event: KeyboardEvent | MouseEvent) => {
|
|||
}
|
||||
};
|
||||
|
||||
export const isNotCtrl = (event: KeyboardEvent | MouseEvent) => {
|
||||
if (!event.metaKey && !event.ctrlKey) {
|
||||
return true;
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export const isHuawei = () => {
|
||||
return window.siyuan.config.system.osPlatform.toLowerCase().indexOf("huawei") > -1;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -914,6 +914,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
if (targetElement.parentElement.getAttribute("data-type") === "NodeSuperBlock" &&
|
||||
targetElement.parentElement.getAttribute("data-sb-layout") === "col") {
|
||||
if (targetClass.includes("dragover__left") || targetClass.includes("dragover__right")) {
|
||||
// Mac 上 ⌘ 无法进行拖拽
|
||||
dragSame(protyle, sourceElements, targetElement, targetClass.includes("dragover__right"), event.ctrlKey);
|
||||
} else {
|
||||
dragSb(protyle, sourceElements, targetElement, targetClass.includes("dragover__bottom"), "row", event.ctrlKey);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import {updateTransaction} from "../wysiwyg/transaction";
|
|||
import {getSelectionOffset, focusByWbr, focusByRange, focusBlock} from "./selection";
|
||||
import {hasClosestBlock, hasClosestByMatchTag} from "./hasClosest";
|
||||
import {matchHotKey} from "./hotKey";
|
||||
import {isCtrl} from "./compatibility";
|
||||
import {isNotCtrl} from "./compatibility";
|
||||
import {scrollCenter} from "../../util/highlightById";
|
||||
import {insertEmptyBlock} from "../../block/util";
|
||||
|
||||
|
|
@ -369,7 +369,7 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
|
|||
}
|
||||
|
||||
// shift+enter 软换行
|
||||
if (event.key === "Enter" && event.shiftKey && !isCtrl(event) && !event.altKey) {
|
||||
if (event.key === "Enter" && event.shiftKey && isNotCtrl(event) && !event.altKey) {
|
||||
const wbrElement = document.createElement("wbr");
|
||||
range.insertNode(wbrElement);
|
||||
const oldHTML = nodeElement.outerHTML;
|
||||
|
|
@ -394,7 +394,7 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
|
|||
return true;
|
||||
}
|
||||
// enter 光标跳转到下一行同列
|
||||
if (!isCtrl(event) && !event.shiftKey && !event.altKey && event.key === "Enter") {
|
||||
if (isNotCtrl(event) && !event.shiftKey && !event.altKey && event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
const trElement = cellElement.parentElement as HTMLTableRowElement;
|
||||
if ((!trElement.nextElementSibling && trElement.parentElement.tagName === "TBODY") ||
|
||||
|
|
@ -423,7 +423,7 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
|
|||
return true;
|
||||
}
|
||||
// tab:光标移向下一个 cell
|
||||
if (event.key === "Tab" && !event.ctrlKey) {
|
||||
if (event.key === "Tab" && isNotCtrl(event)) {
|
||||
if (event.shiftKey) {
|
||||
// shift + tab 光标移动到前一个 cell
|
||||
goPreviousCell(cellElement, range);
|
||||
|
|
@ -453,7 +453,7 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
|
|||
return true;
|
||||
}
|
||||
|
||||
if (event.key === "ArrowUp" && !isCtrl(event) && !event.shiftKey && !event.altKey) {
|
||||
if (event.key === "ArrowUp" && isNotCtrl(event) && !event.shiftKey && !event.altKey) {
|
||||
const startContainer = range.startContainer as HTMLElement;
|
||||
let previousBrElement;
|
||||
if (startContainer.nodeType !== 3 && (startContainer.tagName === "TH" || startContainer.tagName === "TD")) {
|
||||
|
|
@ -484,7 +484,7 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
|
|||
return true;
|
||||
}
|
||||
|
||||
if (event.key === "ArrowDown" && !isCtrl(event) && !event.shiftKey && !event.altKey) {
|
||||
if (event.key === "ArrowDown" && isNotCtrl(event) && !event.shiftKey && !event.altKey) {
|
||||
const endContainer = range.endContainer as HTMLElement;
|
||||
let nextBrElement;
|
||||
if (endContainer.nodeType !== 3 && (endContainer.tagName === "TH" || endContainer.tagName === "TD")) {
|
||||
|
|
@ -520,7 +520,7 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
|
|||
}
|
||||
|
||||
// Backspace:光标移动到前一个 cell
|
||||
if (!isCtrl(event) && !event.shiftKey && !event.altKey && event.key === "Backspace"
|
||||
if (isNotCtrl(event) && !event.shiftKey && !event.altKey && event.key === "Backspace"
|
||||
&& getSelectionOffset(cellElement, protyle.wysiwyg.element, range).start === 0 && range.toString() === "" &&
|
||||
// 空换行无法删除 https://github.com/siyuan-note/siyuan/issues/2732
|
||||
(range.startOffset === 0 || (range.startOffset === 1 && cellElement.querySelectorAll("br").length === 1))) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue