2023-05-11 09:55:33 +08:00
|
|
|
|
import {isCtrl, isMac, updateHotkeyTip, writeText} from "../protyle/util/compatibility";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {matchHotKey} from "../protyle/util/hotKey";
|
|
|
|
|
|
import {openSearch} from "../search/spread";
|
|
|
|
|
|
import {
|
|
|
|
|
|
hasClosestBlock,
|
|
|
|
|
|
hasClosestByAttribute,
|
|
|
|
|
|
hasClosestByClassName, hasClosestByMatchTag,
|
|
|
|
|
|
hasTopClosestByClassName,
|
|
|
|
|
|
hasTopClosestByTag,
|
|
|
|
|
|
} from "../protyle/util/hasClosest";
|
2023-04-06 22:25:50 +08:00
|
|
|
|
import {newFile} from "../util/newFile";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {Constants} from "../constants";
|
|
|
|
|
|
import {openSetting} from "../config";
|
2023-01-12 17:36:19 +08:00
|
|
|
|
import {getDockByType, getInstanceById} from "../layout/util";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {Tab} from "../layout/Tab";
|
|
|
|
|
|
import {Editor} from "../editor";
|
|
|
|
|
|
import {setEditMode} from "../protyle/util/setEditMode";
|
|
|
|
|
|
import {rename} from "../editor/rename";
|
|
|
|
|
|
import {Files} from "../layout/dock/Files";
|
2023-04-06 22:25:50 +08:00
|
|
|
|
import {newDailyNote} from "../util/mount";
|
2023-02-22 10:54:46 +08:00
|
|
|
|
import {hideAllElements, hideElements} from "../protyle/ui/hideElements";
|
2023-04-06 22:25:50 +08:00
|
|
|
|
import {fetchPost} from "../util/fetch";
|
|
|
|
|
|
import {goBack, goForward} from "../util/backForward";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {onGet} from "../protyle/util/onGet";
|
2023-04-06 22:25:50 +08:00
|
|
|
|
import {getDisplayName, getNotebookName, getTopPaths, movePathTo, moveToPath} from "../util/pathName";
|
2022-06-29 15:36:44 +08:00
|
|
|
|
import {openFileById} from "../editor/util";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {getAllDocks, getAllModels, getAllTabs} from "../layout/getAll";
|
|
|
|
|
|
import {openGlobalSearch} from "../search/util";
|
|
|
|
|
|
import {getColIndex} from "../protyle/util/table";
|
|
|
|
|
|
import {focusBlock, focusByRange} from "../protyle/util/selection";
|
|
|
|
|
|
import {initFileMenu, initNavigationMenu} from "../menus/navigation";
|
|
|
|
|
|
import {bindMenuKeydown} from "../menus/Menu";
|
|
|
|
|
|
import {showMessage} from "../dialog/message";
|
2022-06-28 23:20:12 +08:00
|
|
|
|
import {Dialog} from "../dialog";
|
|
|
|
|
|
import {unicode2Emoji} from "../emoji";
|
2022-11-04 21:48:50 +08:00
|
|
|
|
import {deleteFiles} from "../editor/deleteFile";
|
2023-04-06 22:25:50 +08:00
|
|
|
|
import {escapeHtml} from "../util/escape";
|
2022-08-21 14:15:13 +08:00
|
|
|
|
import {syncGuide} from "../sync/syncGuide";
|
2022-10-28 23:29:07 +08:00
|
|
|
|
import {showPopover} from "../block/popover";
|
2022-11-03 00:09:44 +08:00
|
|
|
|
import {getStartEndElement} from "../protyle/wysiwyg/commonHotkey";
|
|
|
|
|
|
import {getNextFileLi, getPreviousFileLi} from "../protyle/wysiwyg/getBlock";
|
2022-11-24 12:15:15 +08:00
|
|
|
|
import {editor} from "../config/editor";
|
2022-11-25 23:06:03 +08:00
|
|
|
|
import {hintMoveBlock} from "../protyle/hint/extend";
|
2022-12-07 18:27:24 +08:00
|
|
|
|
import {Backlink} from "../layout/dock/Backlink";
|
2023-01-06 20:26:14 +08:00
|
|
|
|
/// #if !BROWSER
|
2023-05-11 09:55:33 +08:00
|
|
|
|
import {setZoom} from "../layout/topBar";
|
2023-01-06 20:26:14 +08:00
|
|
|
|
/// #endif
|
2022-12-15 16:12:52 +08:00
|
|
|
|
import {openHistory} from "../history/history";
|
2023-04-23 11:16:57 +08:00
|
|
|
|
import {openCard, openCardByData} from "../card/openCard";
|
2023-01-12 15:53:57 +08:00
|
|
|
|
import {lockScreen} from "../dialog/processSystem";
|
2023-04-06 22:25:50 +08:00
|
|
|
|
import {isWindow} from "../util/functions";
|
2023-03-07 11:37:28 +08:00
|
|
|
|
import {reloadProtyle} from "../protyle/util/reload";
|
|
|
|
|
|
import {fullscreen} from "../protyle/breadcrumb/action";
|
|
|
|
|
|
import {setPadding} from "../protyle/ui/initUI";
|
2023-04-28 16:50:10 +08:00
|
|
|
|
import {openRecentDocs} from "../business/openRecentDocs";
|
2023-05-08 21:00:41 +08:00
|
|
|
|
import {App} from "../index";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
|
|
|
|
|
const getRightBlock = (element: HTMLElement, x: number, y: number) => {
|
|
|
|
|
|
let index = 1;
|
|
|
|
|
|
let nodeElement = element;
|
|
|
|
|
|
while (nodeElement && (nodeElement.classList.contains("list") || nodeElement.classList.contains("li"))) {
|
|
|
|
|
|
nodeElement = document.elementFromPoint(x + 73 * index, y) as HTMLElement;
|
|
|
|
|
|
nodeElement = hasClosestBlock(nodeElement) as HTMLElement;
|
|
|
|
|
|
index++;
|
|
|
|
|
|
}
|
|
|
|
|
|
return nodeElement;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-05-18 19:27:21 +08:00
|
|
|
|
const switchDialogEvent = (app: App, event: MouseEvent, switchDialog: Dialog) => {
|
2022-06-29 09:52:50 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
let target = event.target as HTMLElement;
|
|
|
|
|
|
while (!target.isSameNode(switchDialog.element)) {
|
|
|
|
|
|
if (target.classList.contains("b3-list-item")) {
|
2023-04-04 19:52:00 +08:00
|
|
|
|
const currentType = target.getAttribute("data-type");
|
2022-06-29 09:52:50 +08:00
|
|
|
|
if (currentType) {
|
2023-04-04 19:52:00 +08:00
|
|
|
|
if (currentType === "riffCard") {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openCard(app);
|
2023-04-04 19:52:00 +08:00
|
|
|
|
} else {
|
2023-05-12 17:11:43 +08:00
|
|
|
|
getDockByType(currentType).toggleModel(currentType, true);
|
2023-04-04 19:52:00 +08:00
|
|
|
|
}
|
2022-06-29 09:52:50 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
const currentId = target.getAttribute("data-id");
|
|
|
|
|
|
getAllTabs().find(item => {
|
|
|
|
|
|
if (item.id === currentId) {
|
|
|
|
|
|
item.parent.switchTab(item.headElement);
|
2022-12-08 22:41:55 +08:00
|
|
|
|
item.parent.showHeading();
|
2022-06-29 09:52:50 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
switchDialog.destroy();
|
|
|
|
|
|
switchDialog = undefined;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
target = target.parentElement;
|
|
|
|
|
|
}
|
2022-06-29 17:52:37 +08:00
|
|
|
|
};
|
2022-06-29 09:52:50 +08:00
|
|
|
|
|
2023-05-08 21:00:41 +08:00
|
|
|
|
export const globalShortcut = (app: App) => {
|
2023-02-26 11:45:50 +08:00
|
|
|
|
document.body.addEventListener("mouseleave", () => {
|
2023-02-27 10:58:07 +08:00
|
|
|
|
if (window.siyuan.layout.leftDock) {
|
|
|
|
|
|
window.siyuan.layout.leftDock.hideDock();
|
|
|
|
|
|
window.siyuan.layout.rightDock.hideDock();
|
|
|
|
|
|
window.siyuan.layout.bottomDock.hideDock();
|
|
|
|
|
|
}
|
2023-02-24 20:02:45 +08:00
|
|
|
|
});
|
2023-02-13 11:11:56 +08:00
|
|
|
|
window.addEventListener("mousemove", (event: MouseEvent & { target: HTMLElement }) => {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (window.siyuan.hideBreadcrumb) {
|
2022-12-24 22:04:01 +08:00
|
|
|
|
document.querySelectorAll(".protyle-breadcrumb__bar--hide").forEach(item => {
|
2022-12-25 10:31:01 +08:00
|
|
|
|
item.classList.remove("protyle-breadcrumb__bar--hide");
|
|
|
|
|
|
});
|
2022-12-24 22:04:01 +08:00
|
|
|
|
window.siyuan.hideBreadcrumb = false;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2023-02-22 09:45:07 +08:00
|
|
|
|
if (event.buttons === 0 && // 鼠标按键被按下时不触发
|
2023-03-07 11:21:22 +08:00
|
|
|
|
window.siyuan.layout.bottomDock &&
|
2023-02-22 09:45:07 +08:00
|
|
|
|
!isWindow() && !hasClosestByClassName(event.target, "b3-dialog") && !hasClosestByClassName(event.target, "b3-menu")) {
|
2023-02-13 15:47:06 +08:00
|
|
|
|
if (event.clientX < 43) {
|
2023-02-14 10:53:54 +08:00
|
|
|
|
if (!window.siyuan.layout.leftDock.pin && window.siyuan.layout.leftDock.layout.element.clientWidth > 0 &&
|
|
|
|
|
|
// 隐藏停靠栏会导致点击两侧内容触发浮动面板弹出,因此需减小鼠标范围
|
|
|
|
|
|
(window.siyuan.layout.leftDock.element.clientWidth > 0 || (window.siyuan.layout.leftDock.element.clientWidth === 0 && event.clientX < 8))) {
|
2023-02-22 17:38:13 +08:00
|
|
|
|
if (event.clientY > document.getElementById("toolbar").clientHeight &&
|
2023-02-13 15:47:06 +08:00
|
|
|
|
event.clientY < window.innerHeight - document.getElementById("status").clientHeight - document.getElementById("dockBottom").clientHeight) {
|
|
|
|
|
|
if (!hasClosestByClassName(event.target, "b3-menu") &&
|
|
|
|
|
|
!hasClosestByClassName(event.target, "layout--float")) {
|
|
|
|
|
|
window.siyuan.layout.leftDock.showDock();
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
window.siyuan.layout.leftDock.hideDock();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (event.clientX > window.innerWidth - 41) {
|
2023-02-14 10:53:54 +08:00
|
|
|
|
if (!window.siyuan.layout.rightDock.pin && window.siyuan.layout.rightDock.layout.element.clientWidth > 0 &&
|
|
|
|
|
|
(window.siyuan.layout.rightDock.element.clientWidth > 0 || (window.siyuan.layout.rightDock.element.clientWidth === 0 && event.clientX > window.innerWidth - 8))) {
|
2023-02-22 17:38:13 +08:00
|
|
|
|
if (event.clientY > document.getElementById("toolbar").clientHeight &&
|
2023-02-13 15:47:06 +08:00
|
|
|
|
event.clientY < window.innerHeight - document.getElementById("status").clientHeight - document.getElementById("dockBottom").clientHeight) {
|
|
|
|
|
|
if (!hasClosestByClassName(event.target, "layout--float")) {
|
|
|
|
|
|
window.siyuan.layout.rightDock.showDock();
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
window.siyuan.layout.rightDock.hideDock();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
2023-02-22 17:38:13 +08:00
|
|
|
|
if (event.clientY > window.innerHeight - 73) {
|
2023-02-13 15:47:06 +08:00
|
|
|
|
window.siyuan.layout.bottomDock.showDock();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const eventPath0 = event.composedPath()[0] as HTMLElement;
|
2022-08-31 01:14:45 +08:00
|
|
|
|
if (eventPath0 && eventPath0.nodeType !== 3 && eventPath0.classList.contains("protyle-wysiwyg") && eventPath0.style.paddingLeft) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
// 光标在编辑器右边也需要进行显示
|
|
|
|
|
|
const mouseElement = document.elementFromPoint(eventPath0.getBoundingClientRect().left + parseInt(eventPath0.style.paddingLeft) + 13, event.clientY);
|
|
|
|
|
|
const blockElement = hasClosestBlock(mouseElement);
|
|
|
|
|
|
if (blockElement) {
|
|
|
|
|
|
const targetBlockElement = getRightBlock(blockElement, blockElement.getBoundingClientRect().left + 1, event.clientY);
|
|
|
|
|
|
if (!targetBlockElement) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-10-09 21:46:22 +08:00
|
|
|
|
const allModels = getAllModels();
|
|
|
|
|
|
let findNode = false;
|
2022-10-09 19:02:52 +08:00
|
|
|
|
allModels.editor.find(item => {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (item.editor.protyle.wysiwyg.element.isSameNode(eventPath0)) {
|
2022-10-25 00:23:42 +08:00
|
|
|
|
item.editor.protyle.gutter.render(item.editor.protyle, targetBlockElement, item.editor.protyle.wysiwyg.element);
|
2022-10-09 21:46:22 +08:00
|
|
|
|
findNode = true;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2022-10-09 19:02:52 +08:00
|
|
|
|
if (!findNode) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.blockPanels.find(item => {
|
2022-10-09 19:02:52 +08:00
|
|
|
|
item.editors.find(eItem => {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (eItem.protyle.wysiwyg.element.contains(eventPath0)) {
|
2022-10-25 00:23:42 +08:00
|
|
|
|
eItem.protyle.gutter.render(eItem.protyle, targetBlockElement, eItem.protyle.wysiwyg.element);
|
2022-10-09 19:02:52 +08:00
|
|
|
|
findNode = true;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2022-10-09 19:02:52 +08:00
|
|
|
|
if (findNode) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!findNode) {
|
|
|
|
|
|
allModels.backlink.find(item => {
|
|
|
|
|
|
item.editors.find(eItem => {
|
|
|
|
|
|
if (eItem.protyle.wysiwyg.element.isSameNode(eventPath0)) {
|
2022-10-25 00:23:42 +08:00
|
|
|
|
eItem.protyle.gutter.render(eItem.protyle, targetBlockElement, eItem.protyle.wysiwyg.element);
|
2022-10-09 21:46:22 +08:00
|
|
|
|
findNode = true;
|
2022-10-09 19:02:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (findNode) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (eventPath0 && eventPath0.nodeType !== 3 && (eventPath0.classList.contains("li") || eventPath0.classList.contains("list"))) {
|
|
|
|
|
|
// 光标在列表下部应显示右侧的元素,而不是列表本身
|
|
|
|
|
|
const targetBlockElement = getRightBlock(eventPath0, eventPath0.getBoundingClientRect().left + 1, event.clientY);
|
|
|
|
|
|
if (!targetBlockElement) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-10-09 19:02:52 +08:00
|
|
|
|
const allModels = getAllModels();
|
|
|
|
|
|
let findNode = false;
|
|
|
|
|
|
allModels.editor.find(item => {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (item.editor.protyle.wysiwyg.element.contains(eventPath0)) {
|
2022-10-25 00:23:42 +08:00
|
|
|
|
item.editor.protyle.gutter.render(item.editor.protyle, targetBlockElement, item.editor.protyle.wysiwyg.element);
|
2022-10-09 21:46:22 +08:00
|
|
|
|
findNode = true;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2022-10-09 19:02:52 +08:00
|
|
|
|
if (!findNode) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.siyuan.blockPanels.find(item => {
|
2022-10-09 19:02:52 +08:00
|
|
|
|
item.editors.find(eItem => {
|
|
|
|
|
|
if (eItem.protyle.wysiwyg.element.contains(eventPath0)) {
|
2022-10-25 00:23:42 +08:00
|
|
|
|
eItem.protyle.gutter.render(eItem.protyle, targetBlockElement, eItem.protyle.wysiwyg.element);
|
2022-10-09 19:02:52 +08:00
|
|
|
|
findNode = true;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (findNode) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!findNode) {
|
|
|
|
|
|
allModels.backlink.find(item => {
|
|
|
|
|
|
item.editors.find(eItem => {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (eItem.protyle.wysiwyg.element.contains(eventPath0)) {
|
2022-10-25 00:23:42 +08:00
|
|
|
|
eItem.protyle.gutter.render(eItem.protyle, targetBlockElement, eItem.protyle.wysiwyg.element);
|
2022-10-09 21:46:22 +08:00
|
|
|
|
findNode = true;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2022-10-09 19:02:52 +08:00
|
|
|
|
if (findNode) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const target = event.target as Element;
|
2023-03-02 18:37:55 +08:00
|
|
|
|
const blockElement = hasClosestByClassName(target, "table");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (blockElement && blockElement.style.cursor !== "col-resize" && !hasClosestByClassName(blockElement, "protyle-wysiwyg__embed")) {
|
|
|
|
|
|
const cellElement = (hasClosestByMatchTag(target, "TH") || hasClosestByMatchTag(target, "TD")) as HTMLTableCellElement;
|
|
|
|
|
|
if (cellElement) {
|
|
|
|
|
|
const tableElement = blockElement.querySelector("table");
|
|
|
|
|
|
const tableHeight = blockElement.querySelector("table").clientHeight;
|
|
|
|
|
|
const resizeElement = blockElement.querySelector(".table__resize");
|
|
|
|
|
|
if (blockElement.style.textAlign === "center" || blockElement.style.textAlign === "right") {
|
|
|
|
|
|
resizeElement.parentElement.style.left = tableElement.offsetLeft + "px";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
resizeElement.parentElement.style.left = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
const rect = cellElement.getBoundingClientRect();
|
|
|
|
|
|
if (rect.right - event.clientX < 3 && rect.right - event.clientX > 0) {
|
|
|
|
|
|
resizeElement.setAttribute("data-col-index", (getColIndex(cellElement) + cellElement.colSpan - 1).toString());
|
|
|
|
|
|
resizeElement.setAttribute("style", `height:${tableHeight}px;left: ${Math.round(cellElement.offsetWidth + cellElement.offsetLeft - blockElement.firstElementChild.scrollLeft - 3)}px;display:block`);
|
|
|
|
|
|
} else if (event.clientX - rect.left < 3 && event.clientX - rect.left > 0 && cellElement.previousElementSibling) {
|
|
|
|
|
|
resizeElement.setAttribute("data-col-index", (getColIndex(cellElement) - 1).toString());
|
|
|
|
|
|
resizeElement.setAttribute("style", `height:${tableHeight}px;left: ${Math.round(cellElement.offsetLeft - blockElement.firstElementChild.scrollLeft - 3)}px;display:block`);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener("mouseup", (event) => {
|
|
|
|
|
|
if (event.button === 3) {
|
|
|
|
|
|
event.preventDefault();
|
2023-05-18 19:27:21 +08:00
|
|
|
|
goBack(app);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else if (event.button === 4) {
|
|
|
|
|
|
event.preventDefault();
|
2023-05-18 19:27:21 +08:00
|
|
|
|
goForward(app);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2022-06-29 09:10:03 +08:00
|
|
|
|
let switchDialog: Dialog;
|
2022-06-29 09:52:50 +08:00
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.addEventListener("keyup", (event) => {
|
|
|
|
|
|
window.siyuan.ctrlIsPressed = false;
|
|
|
|
|
|
window.siyuan.shiftIsPressed = false;
|
|
|
|
|
|
window.siyuan.altIsPressed = false;
|
2022-06-28 23:20:12 +08:00
|
|
|
|
if (switchDialog && switchDialog.element.parentElement) {
|
|
|
|
|
|
if (event.key === "Tab") {
|
2022-07-13 23:08:27 +08:00
|
|
|
|
let currentLiElement = switchDialog.element.querySelector(".b3-list-item--focus");
|
2022-06-29 09:10:03 +08:00
|
|
|
|
currentLiElement.classList.remove("b3-list-item--focus");
|
2022-06-28 23:20:12 +08:00
|
|
|
|
if (event.shiftKey) {
|
|
|
|
|
|
if (currentLiElement.previousElementSibling) {
|
2022-06-29 09:10:03 +08:00
|
|
|
|
currentLiElement.previousElementSibling.classList.add("b3-list-item--focus");
|
2022-06-28 23:20:12 +08:00
|
|
|
|
} else if (currentLiElement.getAttribute("data-original")) {
|
2022-06-29 09:10:03 +08:00
|
|
|
|
currentLiElement.parentElement.lastElementChild.classList.add("b3-list-item--focus");
|
|
|
|
|
|
currentLiElement.removeAttribute("data-original");
|
2022-06-28 23:20:12 +08:00
|
|
|
|
} else if (currentLiElement.parentElement.nextElementSibling) {
|
2022-07-13 23:08:27 +08:00
|
|
|
|
if (currentLiElement.parentElement.nextElementSibling.lastElementChild) {
|
|
|
|
|
|
currentLiElement.parentElement.nextElementSibling.lastElementChild.classList.add("b3-list-item--focus");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentLiElement.parentElement.lastElementChild.classList.add("b3-list-item--focus");
|
|
|
|
|
|
}
|
2022-06-28 23:20:12 +08:00
|
|
|
|
} else if (currentLiElement.parentElement.previousElementSibling) {
|
2022-06-29 09:10:03 +08:00
|
|
|
|
currentLiElement.parentElement.previousElementSibling.lastElementChild.classList.add("b3-list-item--focus");
|
2022-06-28 23:20:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (currentLiElement.nextElementSibling) {
|
2022-06-29 09:10:03 +08:00
|
|
|
|
currentLiElement.nextElementSibling.classList.add("b3-list-item--focus");
|
2022-06-28 23:20:12 +08:00
|
|
|
|
} else if (currentLiElement.getAttribute("data-original")) {
|
2022-06-29 09:10:03 +08:00
|
|
|
|
currentLiElement.parentElement.firstElementChild.classList.add("b3-list-item--focus");
|
|
|
|
|
|
currentLiElement.removeAttribute("data-original");
|
2022-06-28 23:20:12 +08:00
|
|
|
|
} else if (currentLiElement.parentElement.nextElementSibling) {
|
2022-07-13 23:08:27 +08:00
|
|
|
|
if (currentLiElement.parentElement.nextElementSibling.firstElementChild) {
|
|
|
|
|
|
currentLiElement.parentElement.nextElementSibling.firstElementChild.classList.add("b3-list-item--focus");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentLiElement.parentElement.firstElementChild.classList.add("b3-list-item--focus");
|
|
|
|
|
|
}
|
2022-06-28 23:20:12 +08:00
|
|
|
|
} else if (currentLiElement.parentElement.previousElementSibling) {
|
2022-06-29 09:10:03 +08:00
|
|
|
|
currentLiElement.parentElement.previousElementSibling.firstElementChild.classList.add("b3-list-item--focus");
|
2022-06-28 23:20:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-07-13 23:08:27 +08:00
|
|
|
|
currentLiElement = switchDialog.element.querySelector(".b3-list-item--focus");
|
|
|
|
|
|
if (currentLiElement) {
|
|
|
|
|
|
const rootId = currentLiElement.getAttribute("data-node-id");
|
|
|
|
|
|
if (rootId) {
|
|
|
|
|
|
fetchPost("/api/filetree/getFullHPathByID", {
|
|
|
|
|
|
id: rootId
|
|
|
|
|
|
}, (response) => {
|
|
|
|
|
|
currentLiElement.parentElement.parentElement.nextElementSibling.innerHTML = escapeHtml(response.data);
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentLiElement.parentElement.parentElement.nextElementSibling.innerHTML = currentLiElement.querySelector(".b3-list-item__text").innerHTML;
|
|
|
|
|
|
}
|
2022-11-27 22:18:39 +08:00
|
|
|
|
const currentRect = currentLiElement.getBoundingClientRect();
|
|
|
|
|
|
const currentParentRect = currentLiElement.parentElement.getBoundingClientRect();
|
|
|
|
|
|
if (currentRect.top < currentParentRect.top) {
|
|
|
|
|
|
currentLiElement.scrollIntoView(true);
|
|
|
|
|
|
} else if (currentRect.bottom > currentParentRect.bottom) {
|
|
|
|
|
|
currentLiElement.scrollIntoView(false);
|
|
|
|
|
|
}
|
2022-07-13 23:08:27 +08:00
|
|
|
|
}
|
2022-11-27 17:46:36 +08:00
|
|
|
|
const originalElement = switchDialog.element.querySelector('[data-original="true"]');
|
|
|
|
|
|
if (originalElement) {
|
2022-11-28 00:39:51 +08:00
|
|
|
|
originalElement.removeAttribute("data-original");
|
2022-11-27 17:46:36 +08:00
|
|
|
|
}
|
2022-06-28 23:20:12 +08:00
|
|
|
|
} else if (event.key === "Control") {
|
2022-06-29 18:47:02 +08:00
|
|
|
|
let currentLiElement = switchDialog.element.querySelector(".b3-list-item--focus");
|
|
|
|
|
|
// 快速切换时,不触发 Tab
|
|
|
|
|
|
if (currentLiElement.getAttribute("data-original")) {
|
|
|
|
|
|
currentLiElement.classList.remove("b3-list-item--focus");
|
|
|
|
|
|
if (event.shiftKey) {
|
|
|
|
|
|
if (currentLiElement.previousElementSibling) {
|
|
|
|
|
|
currentLiElement.previousElementSibling.classList.add("b3-list-item--focus");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentLiElement.parentElement.lastElementChild.classList.add("b3-list-item--focus");
|
|
|
|
|
|
currentLiElement.removeAttribute("data-original");
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (currentLiElement.nextElementSibling) {
|
|
|
|
|
|
currentLiElement.nextElementSibling.classList.add("b3-list-item--focus");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentLiElement.parentElement.firstElementChild.classList.add("b3-list-item--focus");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
currentLiElement.removeAttribute("data-original");
|
|
|
|
|
|
currentLiElement = switchDialog.element.querySelector(".b3-list-item--focus");
|
|
|
|
|
|
}
|
2023-04-04 19:52:00 +08:00
|
|
|
|
const currentType = currentLiElement.getAttribute("data-type");
|
2022-06-28 23:20:12 +08:00
|
|
|
|
if (currentType) {
|
2023-04-04 19:52:00 +08:00
|
|
|
|
if (currentType === "riffCard") {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openCard(app);
|
2023-04-04 19:52:00 +08:00
|
|
|
|
} else {
|
2023-05-12 17:11:43 +08:00
|
|
|
|
getDockByType(currentType).toggleModel(currentType, true);
|
2023-04-04 19:52:00 +08:00
|
|
|
|
}
|
2023-03-27 11:42:39 +08:00
|
|
|
|
if (document.activeElement) {
|
|
|
|
|
|
(document.activeElement as HTMLElement).blur();
|
2022-06-28 23:20:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2022-06-29 09:10:03 +08:00
|
|
|
|
const currentId = currentLiElement.getAttribute("data-id");
|
2022-06-28 23:20:12 +08:00
|
|
|
|
getAllTabs().find(item => {
|
|
|
|
|
|
if (item.id === currentId) {
|
|
|
|
|
|
item.parent.switchTab(item.headElement);
|
2022-12-08 22:41:55 +08:00
|
|
|
|
item.parent.showHeading();
|
2022-06-28 23:20:12 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2022-06-29 09:10:03 +08:00
|
|
|
|
});
|
2022-06-28 23:20:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
switchDialog.destroy();
|
|
|
|
|
|
switchDialog = undefined;
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener("keydown", (event) => {
|
|
|
|
|
|
if (document.getElementById("errorLog") || event.isComposing) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-03-16 18:21:25 +08:00
|
|
|
|
const target = event.target as HTMLElement;
|
2022-12-30 00:53:00 +08:00
|
|
|
|
if (!event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey &&
|
2023-03-16 18:21:25 +08:00
|
|
|
|
!["INPUT", "TEXTAREA"].includes(target.tagName) &&
|
2023-03-27 10:42:38 +08:00
|
|
|
|
["0", "1", "2", "3", "4", "j", "k", "l", ";", "s", " ", "p"].includes(event.key.toLowerCase())) {
|
2023-05-10 15:35:47 +08:00
|
|
|
|
let cardElement: Element;
|
|
|
|
|
|
window.siyuan.dialogs.find(item => {
|
2022-12-22 14:52:43 +08:00
|
|
|
|
if (item.element.getAttribute("data-key") === window.siyuan.config.keymap.general.riffCard.custom) {
|
2023-05-10 15:35:47 +08:00
|
|
|
|
cardElement = item.element;
|
2022-12-22 14:52:43 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2023-05-10 15:35:47 +08:00
|
|
|
|
if (!cardElement) {
|
2023-05-10 16:11:51 +08:00
|
|
|
|
cardElement = document.querySelector(`.layout__wnd--active div[data-key="${window.siyuan.config.keymap.general.riffCard.custom}"]:not(.fn__none)`);
|
2023-05-10 15:35:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (cardElement) {
|
2022-12-22 14:52:43 +08:00
|
|
|
|
event.preventDefault();
|
2023-05-10 15:35:47 +08:00
|
|
|
|
cardElement.dispatchEvent(new CustomEvent("click", {detail: event.key.toLowerCase()}));
|
2022-12-22 14:52:43 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
// 仅处理以下快捷键操作
|
|
|
|
|
|
if (!event.ctrlKey && !isCtrl(event) && event.key !== "Escape" && !event.shiftKey && !event.altKey &&
|
|
|
|
|
|
!/^F\d{1,2}$/.test(event.key) && event.key.indexOf("Arrow") === -1 && event.key !== "Enter" && event.key !== "Backspace" && event.key !== "Delete") {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!event.altKey && !event.shiftKey && isCtrl(event)) {
|
|
|
|
|
|
if (event.key === "Meta" || event.key === "Control" || event.ctrlKey || event.metaKey) {
|
|
|
|
|
|
window.siyuan.ctrlIsPressed = true;
|
2022-10-28 23:41:11 +08:00
|
|
|
|
if (window.siyuan.config.editor.floatWindowMode === 1 && !event.repeat) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
showPopover(app);
|
2022-10-28 23:29:07 +08:00
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
window.siyuan.ctrlIsPressed = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-04-13 08:56:22 +08:00
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (!event.altKey && event.shiftKey && !isCtrl(event)) {
|
|
|
|
|
|
if (event.key === "Shift") {
|
|
|
|
|
|
window.siyuan.shiftIsPressed = true;
|
2023-05-17 18:48:42 +08:00
|
|
|
|
if (!event.repeat) {
|
2023-05-24 19:20:24 +08:00
|
|
|
|
showPopover(app, true);
|
2023-05-17 18:48:42 +08:00
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
window.siyuan.shiftIsPressed = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-04-13 08:56:22 +08:00
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (event.altKey && !event.shiftKey && !isCtrl(event)) {
|
|
|
|
|
|
if (event.key === "Alt") {
|
|
|
|
|
|
window.siyuan.altIsPressed = true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
window.siyuan.altIsPressed = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-08 20:37:47 +08:00
|
|
|
|
if (switchDialog && event.ctrlKey && !event.metaKey && event.key.startsWith("Arrow")) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
dialogArrow(app, switchDialog.element, event);
|
2022-12-08 20:37:47 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-04-13 08:56:22 +08:00
|
|
|
|
|
2023-01-27 17:15:59 +08:00
|
|
|
|
const isTabWindow = isWindow();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (event.ctrlKey && !event.metaKey && event.key === "Tab") {
|
2022-06-28 23:20:12 +08:00
|
|
|
|
if (switchDialog && switchDialog.element.parentElement) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-06-29 09:10:03 +08:00
|
|
|
|
let tabHtml = "";
|
|
|
|
|
|
let currentTabElement = document.querySelector(".layout__wnd--active .layout-tab-bar > .item--focus");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (!currentTabElement) {
|
2022-06-29 09:10:03 +08:00
|
|
|
|
currentTabElement = document.querySelector(".layout-tab-bar > .item--focus");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2022-06-28 23:20:12 +08:00
|
|
|
|
if (currentTabElement) {
|
2022-06-29 09:10:03 +08:00
|
|
|
|
const currentId = currentTabElement.getAttribute("data-id");
|
2022-06-29 09:09:18 +08:00
|
|
|
|
getAllTabs().sort((itemA, itemB) => {
|
2022-06-29 09:10:03 +08:00
|
|
|
|
return itemA.headElement.getAttribute("data-activetime") > itemB.headElement.getAttribute("data-activetime") ? -1 : 1;
|
2022-12-08 20:37:47 +08:00
|
|
|
|
}).forEach((item, index) => {
|
2022-06-29 09:10:03 +08:00
|
|
|
|
let icon = `<svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg>`;
|
2022-07-13 23:08:27 +08:00
|
|
|
|
let rootId = "";
|
2022-11-28 00:39:51 +08:00
|
|
|
|
const initData = item.headElement.getAttribute("data-initdata");
|
2022-06-28 23:20:12 +08:00
|
|
|
|
if (item.model instanceof Editor) {
|
2022-07-15 09:56:52 +08:00
|
|
|
|
rootId = ` data-node-id="${item.model.editor.protyle.block.rootID}"`;
|
2022-11-27 16:48:43 +08:00
|
|
|
|
icon = unicode2Emoji(item.docIcon || Constants.SIYUAN_IMAGE_FILE, false, "b3-list-item__graphic", true);
|
2022-11-27 17:44:51 +08:00
|
|
|
|
} else if (initData) {
|
2023-05-24 20:06:32 +08:00
|
|
|
|
const initDataObj = JSON.parse(initData);
|
2023-05-24 19:20:24 +08:00
|
|
|
|
if (initDataObj.instance === "Editor") {
|
|
|
|
|
|
rootId = ` data-node-id="${initDataObj.rootId}"`;
|
|
|
|
|
|
icon = unicode2Emoji(item.docIcon || Constants.SIYUAN_IMAGE_FILE, false, "b3-list-item__graphic", true);
|
|
|
|
|
|
}
|
2022-06-28 23:20:12 +08:00
|
|
|
|
}
|
2022-12-08 20:37:47 +08:00
|
|
|
|
tabHtml += `<li data-index="${index}" data-id="${item.id}"${rootId} class="b3-list-item${currentId === item.id ? " b3-list-item--focus" : ""}"${currentId === item.id ? ' data-original="true"' : ""}>${icon}<span class="b3-list-item__text">${escapeHtml(item.title)}</span></li>`;
|
2022-06-29 09:09:18 +08:00
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2022-07-13 23:08:27 +08:00
|
|
|
|
let dockHtml = "";
|
2023-01-27 17:15:59 +08:00
|
|
|
|
if (!isTabWindow) {
|
2023-05-22 22:08:01 +08:00
|
|
|
|
dockHtml = `<ul class="b3-list b3-list--background" style="overflow: auto;width: 200px;">
|
2023-04-04 19:52:00 +08:00
|
|
|
|
<li data-type="riffCard" data-index="0" class="b3-list-item${!tabHtml ? " b3-list-item--focus" : ""}">
|
|
|
|
|
|
<svg class="b3-list-item__graphic"><use xlink:href="#iconRiffCard"></use></svg>
|
|
|
|
|
|
<span class="b3-list-item__text">${window.siyuan.languages.riffCard}</span>
|
|
|
|
|
|
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.riffCard.custom)}</span>
|
|
|
|
|
|
</li>`;
|
2023-01-27 17:15:59 +08:00
|
|
|
|
getAllDocks().forEach((item, index) => {
|
2023-04-04 19:52:00 +08:00
|
|
|
|
dockHtml += `<li data-type="${item.type}" data-index="${index + 1}" class="b3-list-item">
|
2022-07-13 23:08:27 +08:00
|
|
|
|
<svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg>
|
2023-05-12 17:11:43 +08:00
|
|
|
|
<span class="b3-list-item__text">${item.title}</span>
|
|
|
|
|
|
<span class="b3-list-item__meta">${updateHotkeyTip(item.hotkey || "")}</span>
|
2022-07-13 23:08:27 +08:00
|
|
|
|
</li>`;
|
2023-01-27 17:15:59 +08:00
|
|
|
|
});
|
|
|
|
|
|
dockHtml = dockHtml + "</ul>";
|
|
|
|
|
|
}
|
2022-12-08 21:53:07 +08:00
|
|
|
|
let range: Range;
|
2022-12-08 21:40:29 +08:00
|
|
|
|
if (getSelection().rangeCount > 0) {
|
|
|
|
|
|
range = getSelection().getRangeAt(0).cloneRange();
|
|
|
|
|
|
}
|
2022-12-12 22:35:14 +08:00
|
|
|
|
hideElements(["dialog"]);
|
2022-06-28 23:20:12 +08:00
|
|
|
|
switchDialog = new Dialog({
|
2022-12-11 23:44:40 +08:00
|
|
|
|
title: window.siyuan.languages.switchTab,
|
2023-02-24 10:01:40 +08:00
|
|
|
|
content: `<div class="fn__flex-column switch-doc">
|
2022-12-08 22:27:18 +08:00
|
|
|
|
<div class="fn__hr"><input style="opacity: 0;height: 1px;box-sizing: border-box"></div>
|
2023-05-22 22:08:01 +08:00
|
|
|
|
<div class="fn__flex" style="overflow:auto;">${dockHtml}
|
2023-01-27 17:15:59 +08:00
|
|
|
|
<ul${!isTabWindow ? "" : ' style="border-left:0"'} class="b3-list b3-list--background fn__flex-1">${tabHtml}</ul>
|
2022-06-28 23:20:12 +08:00
|
|
|
|
</div>
|
2023-02-24 10:01:40 +08:00
|
|
|
|
<div class="switch-doc__path"></div>
|
2022-06-29 09:21:08 +08:00
|
|
|
|
</div>`,
|
2022-12-08 21:40:29 +08:00
|
|
|
|
destroyCallback: () => {
|
|
|
|
|
|
if (range && range.getBoundingClientRect().height !== 0) {
|
2022-12-08 21:53:07 +08:00
|
|
|
|
focusByRange(range);
|
2022-12-08 21:40:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-06-28 23:20:12 +08:00
|
|
|
|
});
|
2022-12-08 22:27:18 +08:00
|
|
|
|
// 需移走光标,否则编辑器会继续监听并执行按键操作
|
|
|
|
|
|
switchDialog.element.querySelector("input").focus();
|
2022-06-29 09:52:50 +08:00
|
|
|
|
if (isMac()) {
|
|
|
|
|
|
switchDialog.element.addEventListener("contextmenu", (event) => {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
switchDialogEvent(app, event, switchDialog);
|
2022-06-29 09:52:50 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
switchDialog.element.addEventListener("click", (event) => {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
switchDialogEvent(app, event, switchDialog);
|
2022-06-29 09:10:03 +08:00
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-12-10 22:13:40 +08:00
|
|
|
|
|
2022-12-11 00:20:46 +08:00
|
|
|
|
if (!event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey &&
|
|
|
|
|
|
(event.key.startsWith("Arrow") || event.key === "Enter")) {
|
|
|
|
|
|
const openRecentDocsDialog = window.siyuan.dialogs.find(item => {
|
|
|
|
|
|
if (item.element.getAttribute("data-key") === window.siyuan.config.keymap.general.recentDocs.custom) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2022-12-11 00:32:40 +08:00
|
|
|
|
});
|
2022-12-11 00:20:46 +08:00
|
|
|
|
if (openRecentDocsDialog) {
|
|
|
|
|
|
event.preventDefault();
|
2023-05-18 19:27:21 +08:00
|
|
|
|
dialogArrow(app, openRecentDocsDialog.element, event);
|
2022-12-11 00:20:46 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-12-22 14:52:43 +08:00
|
|
|
|
|
2022-12-10 22:13:40 +08:00
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.recentDocs.custom, event)) {
|
2022-12-11 00:20:46 +08:00
|
|
|
|
const openRecentDocsDialog = window.siyuan.dialogs.find(item => {
|
|
|
|
|
|
if (item.element.getAttribute("data-key") === window.siyuan.config.keymap.general.recentDocs.custom) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2022-12-11 00:32:40 +08:00
|
|
|
|
});
|
2022-12-11 00:20:46 +08:00
|
|
|
|
if (openRecentDocsDialog) {
|
2022-12-10 22:13:40 +08:00
|
|
|
|
hideElements(["dialog"]);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-12-11 00:20:46 +08:00
|
|
|
|
openRecentDocs();
|
|
|
|
|
|
event.preventDefault();
|
2022-12-10 22:13:40 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-04-13 08:56:22 +08:00
|
|
|
|
|
2023-04-23 11:16:57 +08:00
|
|
|
|
if (event.key === "ArrowUp" || event.key === "ArrowDown") {
|
2023-04-13 08:56:22 +08:00
|
|
|
|
const viewCardsDialog = window.siyuan.dialogs.find(item => {
|
|
|
|
|
|
if (item.element.getAttribute("data-key") === "viewCards") {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (viewCardsDialog) {
|
|
|
|
|
|
viewCardsDialog.element.dispatchEvent(new CustomEvent("click", {detail: event.key.toLowerCase()}));
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-06 20:26:14 +08:00
|
|
|
|
/// #if !BROWSER
|
2023-03-16 18:21:25 +08:00
|
|
|
|
if (matchHotKey("⌘=", event) && !hasClosestByClassName(target, "pdf__outer")) {
|
2023-05-11 09:56:17 +08:00
|
|
|
|
setZoom("zoomIn");
|
2023-01-06 20:26:14 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (matchHotKey("⌘0", event)) {
|
2023-05-11 09:56:17 +08:00
|
|
|
|
setZoom("restore");
|
2023-01-06 20:26:14 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-03-16 18:21:25 +08:00
|
|
|
|
if (matchHotKey("⌘-", event) && !hasClosestByClassName(target, "pdf__outer")) {
|
2023-05-11 09:56:17 +08:00
|
|
|
|
setZoom("zoomOut");
|
2023-01-06 20:26:14 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// #endif
|
2022-12-10 22:13:40 +08:00
|
|
|
|
|
2023-01-27 17:15:59 +08:00
|
|
|
|
if (!isTabWindow && matchHotKey(window.siyuan.config.keymap.general.syncNow.custom, event)) {
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.preventDefault();
|
2023-05-15 13:54:30 +08:00
|
|
|
|
syncGuide(app);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-11-24 12:15:15 +08:00
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.editMode.custom, event)) {
|
|
|
|
|
|
event.preventDefault();
|
2023-02-27 11:37:54 +08:00
|
|
|
|
editor.setReadonly();
|
2022-11-24 12:15:15 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.lockScreen.custom, event)) {
|
2023-01-12 17:36:19 +08:00
|
|
|
|
lockScreen();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-01-27 17:15:59 +08:00
|
|
|
|
if (!isTabWindow && matchHotKey(window.siyuan.config.keymap.general.dataHistory.custom, event)) {
|
2023-03-10 10:00:03 +08:00
|
|
|
|
if (!window.siyuan.config.readonly) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openHistory(app);
|
2023-03-10 10:00:03 +08:00
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-01-27 17:15:59 +08:00
|
|
|
|
if (!isTabWindow && !window.siyuan.config.readonly && matchHotKey(window.siyuan.config.keymap.general.config.custom, event)) {
|
2023-05-08 21:00:41 +08:00
|
|
|
|
openSetting(app);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
return;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (matchHotKey("⌘A", event) && target.tagName !== "INPUT" && target.tagName !== "TEXTAREA") {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const matchDock = getAllDocks().find(item => {
|
2023-05-12 17:11:43 +08:00
|
|
|
|
if (matchHotKey(item.hotkey, event)) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
getDockByType(item.type).toggleModel(item.type);
|
2023-03-27 11:42:39 +08:00
|
|
|
|
if (document.activeElement) {
|
|
|
|
|
|
(document.activeElement as HTMLElement).blur();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (matchDock) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-04-03 19:50:25 +08:00
|
|
|
|
if (!isTabWindow && matchHotKey(window.siyuan.config.keymap.general.riffCard.custom, event)) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openCard(app);
|
2023-03-27 11:42:39 +08:00
|
|
|
|
if (document.activeElement) {
|
|
|
|
|
|
(document.activeElement as HTMLElement).blur();
|
2022-12-24 22:04:01 +08:00
|
|
|
|
}
|
2022-12-22 11:08:25 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-01-27 17:15:59 +08:00
|
|
|
|
if (!isTabWindow && matchHotKey(window.siyuan.config.keymap.general.dailyNote.custom, event)) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
newDailyNote();
|
2023-03-27 11:42:39 +08:00
|
|
|
|
event.stopPropagation();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.newFile.custom, event)) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
newFile(app, undefined, undefined, undefined, true);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (event.key === "Escape" && !event.isComposing) {
|
|
|
|
|
|
const imgPreviewElement = document.querySelector(".protyle-img");
|
|
|
|
|
|
if (imgPreviewElement) {
|
|
|
|
|
|
imgPreviewElement.remove();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!window.siyuan.menus.menu.element.classList.contains("fn__none")) {
|
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (window.siyuan.dialogs.length > 0) {
|
|
|
|
|
|
hideElements(["dialog"]);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// remove blockpopover
|
|
|
|
|
|
const maxEditLevels: { [key: string]: number } = {oid: 0};
|
|
|
|
|
|
window.siyuan.blockPanels.forEach((item) => {
|
|
|
|
|
|
if (item.targetElement && item.element.getAttribute("data-pin") === "true") {
|
|
|
|
|
|
const level = parseInt(item.element.getAttribute("data-level"));
|
|
|
|
|
|
const oid = item.element.getAttribute("data-oid");
|
|
|
|
|
|
if (maxEditLevels[oid]) {
|
|
|
|
|
|
if (level > maxEditLevels[oid]) {
|
|
|
|
|
|
maxEditLevels[oid] = level;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
maxEditLevels[oid] = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
let destroyBlock = false;
|
|
|
|
|
|
for (let i = 0; i < window.siyuan.blockPanels.length; i++) {
|
|
|
|
|
|
const item = window.siyuan.blockPanels[i];
|
|
|
|
|
|
if (item.targetElement && item.element.getAttribute("data-pin") === "false" &&
|
|
|
|
|
|
parseInt(item.element.getAttribute("data-level")) > (maxEditLevels[item.element.getAttribute("data-oid")] || 0)) {
|
|
|
|
|
|
item.destroy();
|
|
|
|
|
|
destroyBlock = true;
|
|
|
|
|
|
i--;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (destroyBlock) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 光标在文档树等面板中,按 Esc 回到编辑器中 https://github.com/siyuan-note/siyuan/issues/4289
|
|
|
|
|
|
let range;
|
|
|
|
|
|
if (getSelection().rangeCount > 0) {
|
|
|
|
|
|
range = getSelection().getRangeAt(0);
|
|
|
|
|
|
const protypleElement = hasClosestByClassName(range.startContainer, "protyle-content", true);
|
|
|
|
|
|
if (protypleElement) {
|
|
|
|
|
|
focusByRange(range);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
range = document.createRange();
|
|
|
|
|
|
}
|
|
|
|
|
|
const lastBackStack = window.siyuan.backStack[window.siyuan.backStack.length - 1];
|
|
|
|
|
|
if (lastBackStack && lastBackStack.protyle.toolbar.range) {
|
|
|
|
|
|
focusByRange(lastBackStack.protyle.toolbar.range);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const editor = getAllModels().editor[0];
|
|
|
|
|
|
if (editor) {
|
|
|
|
|
|
focusBlock(editor.editor.protyle.wysiwyg.element.firstElementChild);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.goForward.custom, event)) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
goForward(app);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.goBack.custom, event)) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
goBack(app);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const confirmElement = document.querySelector("#confirmDialogConfirmBtn");
|
|
|
|
|
|
if (confirmElement && event.key === "Enter") {
|
|
|
|
|
|
confirmElement.dispatchEvent(new CustomEvent("click"));
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// close tab
|
2022-09-16 21:43:22 +08:00
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.closeTab.custom, event) && !event.repeat) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
event.preventDefault();
|
2022-10-14 22:29:40 +08:00
|
|
|
|
let activeTabElement = document.querySelector(".layout__tab--active");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (activeTabElement && activeTabElement.getBoundingClientRect().width > 0) {
|
2023-05-12 17:11:43 +08:00
|
|
|
|
let type = "";
|
2022-10-14 22:29:40 +08:00
|
|
|
|
Array.from(activeTabElement.classList).find(item => {
|
2022-07-09 10:03:46 +08:00
|
|
|
|
if (item.startsWith("sy__")) {
|
2023-05-12 17:11:43 +08:00
|
|
|
|
type = item.replace("sy__", "");
|
2022-07-09 10:03:46 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (type) {
|
2023-05-12 17:11:43 +08:00
|
|
|
|
getDockByType(type)?.toggleModel(type, false, true);
|
2022-07-09 10:03:46 +08:00
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
activeTabElement = document.querySelector(".layout__wnd--active .item--focus");
|
|
|
|
|
|
if (activeTabElement) {
|
|
|
|
|
|
const tab = getInstanceById(activeTabElement.getAttribute("data-id")) as Tab;
|
|
|
|
|
|
tab.parent.removeTab(tab.id);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
getAllTabs().find(item => {
|
|
|
|
|
|
if (item.headElement?.classList.contains("item--focus")) {
|
|
|
|
|
|
item.parent.removeTab(item.id);
|
2022-08-24 13:31:04 +08:00
|
|
|
|
return true;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.stickSearch.custom, event)) {
|
|
|
|
|
|
if (getSelection().rangeCount > 0) {
|
|
|
|
|
|
const range = getSelection().getRangeAt(0);
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openGlobalSearch(app, range.toString(), false);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openGlobalSearch(app, "", false);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-18 19:27:21 +08:00
|
|
|
|
if (editKeydown(app, event)) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 文件树的操作
|
2023-05-18 19:27:21 +08:00
|
|
|
|
if (!isTabWindow && fileTreeKeydown(app, event)) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-07 18:27:24 +08:00
|
|
|
|
// 面板的操作
|
2023-05-30 00:27:47 +08:00
|
|
|
|
if (!isTabWindow && panelTreeKeydown(app, event)) {
|
2022-12-07 18:27:24 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-30 00:27:47 +08:00
|
|
|
|
let matchCommand = false;
|
|
|
|
|
|
app.plugins.find(item => {
|
|
|
|
|
|
item.commands.find(command => {
|
|
|
|
|
|
if (command.callback &&
|
2023-06-01 14:56:21 +08:00
|
|
|
|
!command.fileTreeCallback && !command.editorCallback && !command.dockCallback
|
2023-05-30 00:27:47 +08:00
|
|
|
|
&& matchHotKey(command.customHotkey, event)) {
|
|
|
|
|
|
matchCommand = true;
|
|
|
|
|
|
command.callback();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (matchCommand) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (matchCommand) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
let searchKey = "";
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.replace.custom, event)) {
|
|
|
|
|
|
searchKey = window.siyuan.config.keymap.general.replace.custom;
|
|
|
|
|
|
} else if (!hasClosestByClassName(target, "pdf__outer") && matchHotKey(window.siyuan.config.keymap.general.search.custom, event)) {
|
|
|
|
|
|
searchKey = window.siyuan.config.keymap.general.search.custom;
|
|
|
|
|
|
} else if (matchHotKey(window.siyuan.config.keymap.general.globalSearch.custom, event)) {
|
|
|
|
|
|
searchKey = window.siyuan.config.keymap.general.globalSearch.custom;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (searchKey) {
|
|
|
|
|
|
if (getSelection().rangeCount > 0) {
|
|
|
|
|
|
const range = getSelection().getRangeAt(0);
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openSearch({
|
|
|
|
|
|
app,
|
|
|
|
|
|
hotkey: searchKey,
|
|
|
|
|
|
key: range.toString(),
|
|
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openSearch({
|
|
|
|
|
|
app,
|
|
|
|
|
|
hotkey: searchKey,
|
|
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-07-09 15:53:52 +08:00
|
|
|
|
|
|
|
|
|
|
// https://github.com/siyuan-note/insider/issues/445
|
|
|
|
|
|
if (matchHotKey("⌘S", event)) {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener("blur", () => {
|
|
|
|
|
|
window.siyuan.ctrlIsPressed = false;
|
|
|
|
|
|
window.siyuan.shiftIsPressed = false;
|
|
|
|
|
|
window.siyuan.altIsPressed = false;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
|
|
|
|
|
|
if (!window.siyuan.menus.menu.element.contains(event.target) && !hasClosestByAttribute(event.target, "data-menu", "true")) {
|
2022-06-07 20:23:04 +08:00
|
|
|
|
if (getSelection().rangeCount > 0 && window.siyuan.menus.menu.element.contains(getSelection().getRangeAt(0).startContainer)) {
|
|
|
|
|
|
// https://ld246.com/article/1654567749834/comment/1654589171218#comments
|
|
|
|
|
|
} else {
|
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2023-02-22 10:54:46 +08:00
|
|
|
|
// protyle.toolbar 点击空白处时进行隐藏
|
|
|
|
|
|
if (!hasClosestByClassName(event.target, "protyle-toolbar")) {
|
2023-02-23 13:26:34 +08:00
|
|
|
|
hideAllElements(["toolbar"]);
|
2023-02-22 10:54:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (!hasClosestByClassName(event.target, "pdf__outer")) {
|
2023-02-23 13:26:34 +08:00
|
|
|
|
hideAllElements(["pdfutil"]);
|
2023-02-22 10:54:46 +08:00
|
|
|
|
}
|
2023-02-12 17:24:53 +08:00
|
|
|
|
// dock float 时,点击空白处,隐藏 dock
|
2023-02-15 14:07:51 +08:00
|
|
|
|
const floatDockLayoutElement = hasClosestByClassName(event.target, "layout--float", true);
|
2023-02-27 10:58:07 +08:00
|
|
|
|
if (floatDockLayoutElement && window.siyuan.layout.leftDock) {
|
2023-02-12 17:24:53 +08:00
|
|
|
|
if (!floatDockLayoutElement.isSameNode(window.siyuan.layout.bottomDock.layout.element)) {
|
|
|
|
|
|
window.siyuan.layout.bottomDock.hideDock();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!floatDockLayoutElement.isSameNode(window.siyuan.layout.leftDock.layout.element)) {
|
|
|
|
|
|
window.siyuan.layout.leftDock.hideDock();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!floatDockLayoutElement.isSameNode(window.siyuan.layout.rightDock.layout.element)) {
|
|
|
|
|
|
window.siyuan.layout.rightDock.hideDock();
|
|
|
|
|
|
}
|
2023-02-27 10:58:07 +08:00
|
|
|
|
} else if (!hasClosestByClassName(event.target, "dock") && !isWindow() && window.siyuan.layout.leftDock) {
|
2023-02-12 17:24:53 +08:00
|
|
|
|
window.siyuan.layout.bottomDock.hideDock();
|
|
|
|
|
|
window.siyuan.layout.leftDock.hideDock();
|
|
|
|
|
|
window.siyuan.layout.rightDock.hideDock();
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const copyElement = hasTopClosestByClassName(event.target, "protyle-action__copy");
|
|
|
|
|
|
if (copyElement) {
|
|
|
|
|
|
writeText(copyElement.parentElement.nextElementSibling.textContent.trimEnd());
|
|
|
|
|
|
showMessage(window.siyuan.languages.copied, 2000);
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 点击空白,pdf 搜索、更多消失
|
|
|
|
|
|
if (hasClosestByAttribute(event.target, "id", "secondaryToolbarToggle") ||
|
|
|
|
|
|
hasClosestByAttribute(event.target, "id", "viewFind") ||
|
|
|
|
|
|
hasClosestByAttribute(event.target, "id", "findbar")) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let currentPDFViewerObject: any;
|
|
|
|
|
|
getAllModels().asset.find(item => {
|
|
|
|
|
|
if (item.pdfObject &&
|
|
|
|
|
|
!item.pdfObject.appConfig.appContainer.classList.contains("fn__none")) {
|
|
|
|
|
|
currentPDFViewerObject = item.pdfObject;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (!currentPDFViewerObject) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (currentPDFViewerObject.secondaryToolbar.isOpen) {
|
|
|
|
|
|
currentPDFViewerObject.secondaryToolbar.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (
|
|
|
|
|
|
!currentPDFViewerObject.supportsIntegratedFind &&
|
|
|
|
|
|
currentPDFViewerObject.findBar.opened
|
|
|
|
|
|
) {
|
|
|
|
|
|
currentPDFViewerObject.findBar.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-05-18 19:27:21 +08:00
|
|
|
|
const dialogArrow = (app: App, element: HTMLElement, event: KeyboardEvent) => {
|
2022-12-11 00:20:46 +08:00
|
|
|
|
let currentLiElement = element.querySelector(".b3-list-item--focus");
|
|
|
|
|
|
if (currentLiElement) {
|
|
|
|
|
|
currentLiElement.classList.remove("b3-list-item--focus");
|
|
|
|
|
|
if (event.key === "ArrowUp") {
|
|
|
|
|
|
if (currentLiElement.previousElementSibling) {
|
|
|
|
|
|
currentLiElement.previousElementSibling.classList.add("b3-list-item--focus");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentLiElement.parentElement.lastElementChild.classList.add("b3-list-item--focus");
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (event.key === "ArrowDown") {
|
|
|
|
|
|
if (currentLiElement.nextElementSibling) {
|
|
|
|
|
|
currentLiElement.nextElementSibling.classList.add("b3-list-item--focus");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentLiElement.parentElement.firstElementChild.classList.add("b3-list-item--focus");
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
2023-01-27 17:15:59 +08:00
|
|
|
|
if (isWindow()) {
|
|
|
|
|
|
currentLiElement.classList.add("b3-list-item--focus");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const sideElement = currentLiElement.parentElement.previousElementSibling || currentLiElement.parentElement.nextElementSibling;
|
|
|
|
|
|
(sideElement.querySelector(`[data-index="${currentLiElement.getAttribute("data-index")}"]`) || sideElement.lastElementChild).classList.add("b3-list-item--focus");
|
|
|
|
|
|
}
|
2022-12-11 00:20:46 +08:00
|
|
|
|
} else if (event.key === "Enter") {
|
2023-04-04 19:52:00 +08:00
|
|
|
|
const currentType = currentLiElement.getAttribute("data-type");
|
2022-12-11 00:20:46 +08:00
|
|
|
|
if (currentType) {
|
2023-04-04 19:52:00 +08:00
|
|
|
|
if (currentType === "riffCard") {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openCard(app);
|
2023-04-04 19:52:00 +08:00
|
|
|
|
} else {
|
2023-05-12 17:11:43 +08:00
|
|
|
|
getDockByType(currentType).toggleModel(currentType, true);
|
2023-04-04 19:52:00 +08:00
|
|
|
|
}
|
2022-12-11 00:20:46 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
openFileById({
|
2023-05-18 19:27:21 +08:00
|
|
|
|
app,
|
2022-12-11 11:57:52 +08:00
|
|
|
|
id: currentLiElement.getAttribute("data-node-id"),
|
|
|
|
|
|
action: [Constants.CB_GET_SCROLL]
|
2022-12-11 00:32:40 +08:00
|
|
|
|
});
|
2022-12-11 00:20:46 +08:00
|
|
|
|
}
|
2022-12-11 00:32:40 +08:00
|
|
|
|
hideElements(["dialog"]);
|
2022-12-11 00:20:46 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-12-11 00:32:40 +08:00
|
|
|
|
currentLiElement = element.querySelector(".b3-list-item--focus");
|
2022-12-11 00:20:46 +08:00
|
|
|
|
const rootId = currentLiElement.getAttribute("data-node-id");
|
|
|
|
|
|
if (rootId) {
|
|
|
|
|
|
fetchPost("/api/filetree/getFullHPathByID", {
|
|
|
|
|
|
id: rootId
|
|
|
|
|
|
}, (response) => {
|
|
|
|
|
|
currentLiElement.parentElement.parentElement.nextElementSibling.innerHTML = escapeHtml(response.data);
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentLiElement.parentElement.parentElement.nextElementSibling.innerHTML = currentLiElement.querySelector(".b3-list-item__text").innerHTML;
|
|
|
|
|
|
}
|
|
|
|
|
|
const currentRect = currentLiElement.getBoundingClientRect();
|
|
|
|
|
|
const currentParentRect = currentLiElement.parentElement.getBoundingClientRect();
|
|
|
|
|
|
if (currentRect.top < currentParentRect.top) {
|
|
|
|
|
|
currentLiElement.scrollIntoView(true);
|
|
|
|
|
|
} else if (currentRect.bottom > currentParentRect.bottom) {
|
|
|
|
|
|
currentLiElement.scrollIntoView(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-12-11 00:32:40 +08:00
|
|
|
|
};
|
2022-12-11 00:20:46 +08:00
|
|
|
|
|
2023-05-18 19:27:21 +08:00
|
|
|
|
const editKeydown = (app: App, event: KeyboardEvent) => {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const activeTabElement = document.querySelector(".layout__wnd--active .item--focus");
|
|
|
|
|
|
let protyle: IProtyle;
|
|
|
|
|
|
if (activeTabElement) {
|
|
|
|
|
|
const tab = getInstanceById(activeTabElement.getAttribute("data-id")) as Tab;
|
|
|
|
|
|
if (!(tab.model instanceof Editor)) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
protyle = tab.model.editor.protyle;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const editor = getAllModels().editor.find(item => {
|
|
|
|
|
|
if (item.parent.headElement.classList.contains("item--focus")) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (!editor) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
protyle = editor.editor.protyle;
|
|
|
|
|
|
}
|
2022-10-14 22:29:40 +08:00
|
|
|
|
const activePanelElement = document.querySelector(".layout__tab--active");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
let isFileFocus = false;
|
2022-10-14 22:29:40 +08:00
|
|
|
|
if (activePanelElement && activePanelElement.classList.contains("sy__file")) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
isFileFocus = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
let searchKey = "";
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.replace.custom, event)) {
|
|
|
|
|
|
searchKey = window.siyuan.config.keymap.general.replace.custom;
|
|
|
|
|
|
} else if (matchHotKey(window.siyuan.config.keymap.general.search.custom, event)) {
|
|
|
|
|
|
searchKey = window.siyuan.config.keymap.general.search.custom;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!isFileFocus && searchKey) {
|
|
|
|
|
|
let range: Range;
|
|
|
|
|
|
if (getSelection().rangeCount > 0) {
|
|
|
|
|
|
range = getSelection().getRangeAt(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (range && protyle.element.contains(range.startContainer)) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openSearch({
|
|
|
|
|
|
app,
|
|
|
|
|
|
hotkey: searchKey,
|
|
|
|
|
|
key: range.toString(),
|
|
|
|
|
|
notebookId: protyle.notebookId,
|
|
|
|
|
|
searchPath: protyle.path
|
|
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openSearch({
|
|
|
|
|
|
app,
|
|
|
|
|
|
hotkey: searchKey,
|
|
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2023-04-23 11:16:57 +08:00
|
|
|
|
if (!isFileFocus && matchHotKey(window.siyuan.config.keymap.editor.general.spaceRepetition.custom, event)) {
|
|
|
|
|
|
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: protyle.block.rootID}, (response) => {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openCardByData(app, response.data, "doc", protyle.block.rootID, protyle.title.editElement.textContent || "Untitled");
|
2023-04-23 11:16:57 +08:00
|
|
|
|
});
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (!isFileFocus && matchHotKey(window.siyuan.config.keymap.general.move.custom, event)) {
|
|
|
|
|
|
let range: Range;
|
|
|
|
|
|
let nodeElement: false | HTMLElement;
|
|
|
|
|
|
if (getSelection().rangeCount > 0) {
|
|
|
|
|
|
range = getSelection().getRangeAt(0);
|
|
|
|
|
|
nodeElement = hasClosestBlock(range.startContainer);
|
|
|
|
|
|
}
|
2022-11-25 23:06:03 +08:00
|
|
|
|
if (protyle.title?.editElement.contains(range.startContainer)) {
|
2022-11-29 22:04:19 +08:00
|
|
|
|
movePathTo((toPath, toNotebook) => {
|
|
|
|
|
|
moveToPath([protyle.path], toNotebook[0], toPath[0]);
|
|
|
|
|
|
}, [protyle.path], range);
|
2022-11-25 23:06:03 +08:00
|
|
|
|
} else if (nodeElement && range && protyle.element.contains(range.startContainer)) {
|
2022-11-25 23:09:16 +08:00
|
|
|
|
let selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
|
2022-11-25 23:06:03 +08:00
|
|
|
|
if (selectElements.length === 0) {
|
2022-11-25 23:09:16 +08:00
|
|
|
|
selectElements = [nodeElement];
|
2022-11-25 23:06:03 +08:00
|
|
|
|
}
|
2022-11-29 22:04:19 +08:00
|
|
|
|
movePathTo((toPath) => {
|
2023-06-01 14:56:21 +08:00
|
|
|
|
hintMoveBlock(toPath[0], selectElements, protyle, app);
|
2022-11-25 23:06:03 +08:00
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
const target = event.target as HTMLElement;
|
2023-05-25 23:51:18 +08:00
|
|
|
|
if (target.tagName !== "TABLE" && (
|
|
|
|
|
|
target.tagName === "INPUT" || target.tagName === "TEXTAREA" || hasClosestByAttribute(target, "contenteditable", null)
|
|
|
|
|
|
)) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2023-03-07 11:37:28 +08:00
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.refresh.custom, event)) {
|
2023-06-01 14:56:21 +08:00
|
|
|
|
reloadProtyle(protyle, app, true);
|
2023-03-07 11:37:28 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.fullscreen.custom, event)) {
|
|
|
|
|
|
fullscreen(protyle.element);
|
|
|
|
|
|
setPadding(protyle);
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.preview.custom, event)) {
|
|
|
|
|
|
setEditMode(protyle, "preview");
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2022-10-02 20:56:48 +08:00
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.wysiwyg.custom, event) && !protyle.options.backlinkData) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
setEditMode(protyle, "wysiwyg");
|
|
|
|
|
|
protyle.scroll.lastScrollTop = 0;
|
|
|
|
|
|
fetchPost("/api/filetree/getDoc", {
|
|
|
|
|
|
id: protyle.block.parentID,
|
2022-10-30 23:13:41 +08:00
|
|
|
|
size: window.siyuan.config.editor.dynamicLoadBlocks,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}, getResponse => {
|
2023-06-01 14:56:21 +08:00
|
|
|
|
onGet({data: getResponse, protyle, app});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 没有光标时,无法撤销 https://ld246.com/article/1624021111567
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.undo.custom, event)) {
|
2023-06-01 14:56:21 +08:00
|
|
|
|
protyle.undo.undo(app, protyle);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.redo.custom, event)) {
|
2023-06-01 14:56:21 +08:00
|
|
|
|
protyle.undo.redo(app, protyle);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-05-18 19:27:21 +08:00
|
|
|
|
const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const dockFile = getDockByType("file");
|
|
|
|
|
|
if (!dockFile) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
const files = dockFile.data.file as Files;
|
2023-05-30 00:27:47 +08:00
|
|
|
|
|
|
|
|
|
|
let matchCommand = false;
|
|
|
|
|
|
app.plugins.find(item => {
|
|
|
|
|
|
item.commands.find(command => {
|
|
|
|
|
|
if (command.fileTreeCallback && matchHotKey(command.customHotkey, event)) {
|
|
|
|
|
|
matchCommand = true;
|
|
|
|
|
|
command.fileTreeCallback(files);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (matchCommand) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (matchCommand) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-07 21:20:02 +08:00
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.selectOpen1.custom, event)) {
|
|
|
|
|
|
event.preventDefault();
|
2022-09-08 22:04:57 +08:00
|
|
|
|
const element = document.querySelector(".layout__wnd--active > .fn__flex > .layout-tab-bar > .item--focus") ||
|
2022-06-07 21:20:02 +08:00
|
|
|
|
document.querySelector(".layout-tab-bar > .item--focus");
|
|
|
|
|
|
if (element) {
|
|
|
|
|
|
const tab = getInstanceById(element.getAttribute("data-id")) as Tab;
|
|
|
|
|
|
if (tab && tab.model instanceof Editor) {
|
2022-07-19 11:45:10 +08:00
|
|
|
|
tab.model.editor.protyle.wysiwyg.element.blur();
|
2022-07-21 20:21:45 +08:00
|
|
|
|
tab.model.editor.protyle.title.editElement.blur();
|
2022-06-07 21:20:02 +08:00
|
|
|
|
files.selectItem(tab.model.editor.protyle.notebookId, tab.model.editor.protyle.path);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-07-10 17:40:46 +08:00
|
|
|
|
dockFile.toggleModel("file", true);
|
2022-06-07 21:20:02 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-10-14 22:29:40 +08:00
|
|
|
|
if (!files.element.parentElement.classList.contains("layout__tab--active")) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2022-11-04 21:50:03 +08:00
|
|
|
|
const liElements = Array.from(files.element.querySelectorAll(".b3-list-item--focus"));
|
2022-11-02 22:48:40 +08:00
|
|
|
|
if (liElements.length === 0) {
|
2023-04-08 22:34:15 +08:00
|
|
|
|
if (event.key.startsWith("Arrow") && !isCtrl(event)) {
|
2022-11-02 22:48:40 +08:00
|
|
|
|
const liElement = files.element.querySelector(".b3-list-item");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (liElement) {
|
|
|
|
|
|
liElement.classList.add("b3-list-item--focus");
|
|
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2022-11-02 22:48:40 +08:00
|
|
|
|
const topULElement = hasTopClosestByTag(liElements[0], "UL");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (!topULElement) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
const notebookId = topULElement.getAttribute("data-url");
|
2022-11-02 22:48:40 +08:00
|
|
|
|
const pathString = liElements[0].getAttribute("data-path");
|
|
|
|
|
|
const isFile = liElements[0].getAttribute("data-type") === "navigation-file";
|
2023-04-23 11:16:57 +08:00
|
|
|
|
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.spaceRepetition.custom, event)) {
|
|
|
|
|
|
if (isFile) {
|
|
|
|
|
|
const id = liElements[0].getAttribute("data-node-id");
|
|
|
|
|
|
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: id}, (response) => {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openCardByData(app, response.data, "doc", id, getDisplayName(liElements[0].getAttribute("data-name"), false, true));
|
2023-04-23 11:16:57 +08:00
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
fetchPost("/api/riff/getNotebookRiffDueCards", {notebook: notebookId}, (response) => {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openCardByData(app, response.data, "notebook", notebookId, getNotebookName(notebookId));
|
2023-04-23 11:16:57 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.rename.custom, event)) {
|
2022-11-02 22:48:40 +08:00
|
|
|
|
window.siyuan.menus.menu.remove();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
rename({
|
|
|
|
|
|
notebookId,
|
|
|
|
|
|
path: pathString,
|
2022-11-02 22:48:40 +08:00
|
|
|
|
name: isFile ? getDisplayName(liElements[0].getAttribute("data-name"), false, true) : getNotebookName(notebookId),
|
2022-05-26 15:18:53 +08:00
|
|
|
|
type: isFile ? "file" : "notebook",
|
|
|
|
|
|
});
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.preventDefault();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (matchHotKey("⌘/", event)) {
|
2022-11-02 22:48:40 +08:00
|
|
|
|
const liRect = liElements[0].getBoundingClientRect();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (isFile) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
initFileMenu(app, notebookId, pathString, liElements[0]).popup({
|
2022-05-26 15:18:53 +08:00
|
|
|
|
x: liRect.right - 15,
|
|
|
|
|
|
y: liRect.top + 15
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
initNavigationMenu(app, liElements[0] as HTMLElement).popup({x: liRect.right - 15, y: liRect.top + 15});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (isFile && matchHotKey(window.siyuan.config.keymap.general.move.custom, event)) {
|
2022-11-02 22:48:40 +08:00
|
|
|
|
window.siyuan.menus.menu.remove();
|
2022-11-30 10:36:03 +08:00
|
|
|
|
const pathes = getTopPaths(liElements);
|
2022-11-29 22:04:19 +08:00
|
|
|
|
movePathTo((toPath, toNotebook) => {
|
|
|
|
|
|
moveToPath(pathes, toNotebook[0], toPath[0]);
|
|
|
|
|
|
}, pathes);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
let searchKey = "";
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.replace.custom, event)) {
|
|
|
|
|
|
searchKey = window.siyuan.config.keymap.general.replace.custom;
|
|
|
|
|
|
} else if (matchHotKey(window.siyuan.config.keymap.general.search.custom, event)) {
|
|
|
|
|
|
searchKey = window.siyuan.config.keymap.general.search.custom;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (searchKey) {
|
2022-11-02 22:48:40 +08:00
|
|
|
|
window.siyuan.menus.menu.remove();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (isFile) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openSearch({
|
|
|
|
|
|
app,
|
|
|
|
|
|
hotkey: searchKey,
|
|
|
|
|
|
notebookId: notebookId,
|
|
|
|
|
|
searchPath: getDisplayName(pathString, false, true)
|
|
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openSearch({
|
|
|
|
|
|
app,
|
|
|
|
|
|
hotkey: searchKey,
|
|
|
|
|
|
notebookId: notebookId,
|
|
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
const target = event.target as HTMLElement;
|
2023-04-03 18:30:58 +08:00
|
|
|
|
if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" ||
|
|
|
|
|
|
hasClosestByAttribute(target, "contenteditable", null) ||
|
|
|
|
|
|
hasClosestByClassName(target, "protyle", true)) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (bindMenuKeydown(event)) {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2022-11-03 00:09:44 +08:00
|
|
|
|
if (event.shiftKey) {
|
|
|
|
|
|
if (event.key === "ArrowUp") {
|
|
|
|
|
|
const startEndElement = getStartEndElement(liElements);
|
2022-11-03 10:32:59 +08:00
|
|
|
|
let previousElement: Element;
|
2022-11-03 00:09:44 +08:00
|
|
|
|
if (startEndElement.startElement.getBoundingClientRect().top >= startEndElement.endElement.getBoundingClientRect().top) {
|
2022-11-03 10:32:59 +08:00
|
|
|
|
previousElement = getPreviousFileLi(startEndElement.endElement) as Element;
|
2022-11-03 00:09:44 +08:00
|
|
|
|
if (previousElement) {
|
|
|
|
|
|
previousElement.classList.add("b3-list-item--focus");
|
|
|
|
|
|
previousElement.setAttribute("select-end", "true");
|
|
|
|
|
|
startEndElement.endElement.removeAttribute("select-end");
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
startEndElement.endElement.classList.remove("b3-list-item--focus");
|
|
|
|
|
|
startEndElement.endElement.removeAttribute("select-end");
|
2022-11-03 10:32:59 +08:00
|
|
|
|
previousElement = getPreviousFileLi(startEndElement.endElement) as Element;
|
2022-11-03 00:09:44 +08:00
|
|
|
|
if (previousElement) {
|
|
|
|
|
|
previousElement.setAttribute("select-end", "true");
|
|
|
|
|
|
}
|
2022-06-07 18:19:22 +08:00
|
|
|
|
}
|
2022-11-03 10:32:59 +08:00
|
|
|
|
if (previousElement) {
|
|
|
|
|
|
const previousRect = previousElement.getBoundingClientRect();
|
|
|
|
|
|
const fileRect = files.element.getBoundingClientRect();
|
|
|
|
|
|
if (previousRect.top < fileRect.top || previousRect.bottom > fileRect.bottom) {
|
|
|
|
|
|
previousElement.scrollIntoView(previousRect.top < fileRect.top);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-11-03 00:09:44 +08:00
|
|
|
|
} else if (event.key === "ArrowDown") {
|
|
|
|
|
|
const startEndElement = getStartEndElement(liElements);
|
2022-11-03 10:32:59 +08:00
|
|
|
|
let nextElement: Element;
|
2022-11-03 00:09:44 +08:00
|
|
|
|
if (startEndElement.startElement.getBoundingClientRect().top <= startEndElement.endElement.getBoundingClientRect().top) {
|
2022-11-03 10:32:59 +08:00
|
|
|
|
nextElement = getNextFileLi(startEndElement.endElement) as Element;
|
2022-11-03 00:09:44 +08:00
|
|
|
|
if (nextElement) {
|
|
|
|
|
|
nextElement.classList.add("b3-list-item--focus");
|
|
|
|
|
|
nextElement.setAttribute("select-end", "true");
|
|
|
|
|
|
startEndElement.endElement.removeAttribute("select-end");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2022-11-03 00:09:44 +08:00
|
|
|
|
startEndElement.endElement.classList.remove("b3-list-item--focus");
|
|
|
|
|
|
startEndElement.endElement.removeAttribute("select-end");
|
2022-11-03 10:32:59 +08:00
|
|
|
|
nextElement = getNextFileLi(startEndElement.endElement) as Element;
|
2022-11-03 00:09:44 +08:00
|
|
|
|
if (nextElement) {
|
|
|
|
|
|
nextElement.setAttribute("select-end", "true");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-11-03 10:32:59 +08:00
|
|
|
|
if (nextElement) {
|
|
|
|
|
|
const nextRect = nextElement.getBoundingClientRect();
|
|
|
|
|
|
const fileRect = files.element.getBoundingClientRect();
|
|
|
|
|
|
if (nextRect.top < fileRect.top || nextRect.bottom > fileRect.bottom) {
|
|
|
|
|
|
nextElement.scrollIntoView(nextRect.top < fileRect.top);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2022-11-03 00:09:44 +08:00
|
|
|
|
return;
|
2023-04-08 22:34:15 +08:00
|
|
|
|
} else if (!isCtrl(event)) {
|
2022-11-03 00:09:44 +08:00
|
|
|
|
files.element.querySelector('[select-end="true"]')?.removeAttribute("select-end");
|
|
|
|
|
|
files.element.querySelector('[select-start="true"]')?.removeAttribute("select-start");
|
|
|
|
|
|
if ((event.key === "ArrowRight" && !liElements[0].querySelector(".b3-list-item__arrow--open") && !liElements[0].querySelector(".b3-list-item__toggle").classList.contains("fn__hidden")) ||
|
|
|
|
|
|
(event.key === "ArrowLeft" && liElements[0].querySelector(".b3-list-item__arrow--open"))) {
|
|
|
|
|
|
files.getLeaf(liElements[0], notebookId);
|
2022-11-02 22:48:40 +08:00
|
|
|
|
liElements.forEach((item, index) => {
|
2022-11-03 00:09:44 +08:00
|
|
|
|
if (index !== 0) {
|
2022-11-04 21:50:03 +08:00
|
|
|
|
item.classList.remove("b3-list-item--focus");
|
2022-11-03 00:09:44 +08:00
|
|
|
|
}
|
2022-11-04 21:50:03 +08:00
|
|
|
|
});
|
2022-11-03 00:09:44 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (event.key === "ArrowLeft") {
|
|
|
|
|
|
let parentElement = liElements[0].parentElement.previousElementSibling;
|
|
|
|
|
|
if (parentElement) {
|
|
|
|
|
|
if (parentElement.tagName !== "LI") {
|
|
|
|
|
|
parentElement = files.element.querySelector(".b3-list-item");
|
|
|
|
|
|
}
|
|
|
|
|
|
liElements.forEach((item) => {
|
2022-11-04 21:50:03 +08:00
|
|
|
|
item.classList.remove("b3-list-item--focus");
|
|
|
|
|
|
});
|
2022-11-03 00:09:44 +08:00
|
|
|
|
parentElement.classList.add("b3-list-item--focus");
|
|
|
|
|
|
const parentRect = parentElement.getBoundingClientRect();
|
|
|
|
|
|
const fileRect = files.element.getBoundingClientRect();
|
|
|
|
|
|
if (parentRect.top < fileRect.top || parentRect.bottom > fileRect.bottom) {
|
|
|
|
|
|
parentElement.scrollIntoView(parentRect.top < fileRect.top);
|
|
|
|
|
|
}
|
2022-06-07 18:19:22 +08:00
|
|
|
|
}
|
2022-11-03 00:09:44 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2022-11-03 00:09:44 +08:00
|
|
|
|
if (event.key === "ArrowDown" || event.key === "ArrowRight") {
|
|
|
|
|
|
let nextElement = liElements[0];
|
|
|
|
|
|
while (nextElement) {
|
|
|
|
|
|
if (nextElement.nextElementSibling) {
|
|
|
|
|
|
if (nextElement.nextElementSibling.tagName === "UL") {
|
|
|
|
|
|
nextElement = nextElement.nextElementSibling.firstElementChild;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
nextElement = nextElement.nextElementSibling;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
2022-11-03 00:09:44 +08:00
|
|
|
|
if (nextElement.parentElement.classList.contains("fn__flex-1")) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
nextElement = nextElement.parentElement;
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2022-11-03 00:09:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (nextElement.classList.contains("b3-list-item")) {
|
|
|
|
|
|
liElements.forEach((item) => {
|
2022-11-04 21:50:03 +08:00
|
|
|
|
item.classList.remove("b3-list-item--focus");
|
|
|
|
|
|
});
|
2022-11-03 00:09:44 +08:00
|
|
|
|
nextElement.classList.add("b3-list-item--focus");
|
|
|
|
|
|
const nextRect = nextElement.getBoundingClientRect();
|
|
|
|
|
|
const fileRect = files.element.getBoundingClientRect();
|
|
|
|
|
|
if (nextRect.top < fileRect.top || nextRect.bottom > fileRect.bottom) {
|
|
|
|
|
|
nextElement.scrollIntoView(nextRect.top < fileRect.top);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (event.key === "ArrowUp") {
|
|
|
|
|
|
let previousElement = liElements[0];
|
|
|
|
|
|
while (previousElement) {
|
|
|
|
|
|
if (previousElement.previousElementSibling) {
|
|
|
|
|
|
if (previousElement.previousElementSibling.tagName === "LI") {
|
|
|
|
|
|
previousElement = previousElement.previousElementSibling;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const liElements = previousElement.previousElementSibling.querySelectorAll(".b3-list-item");
|
|
|
|
|
|
previousElement = liElements[liElements.length - 1];
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
break;
|
|
|
|
|
|
} else {
|
2022-11-03 00:09:44 +08:00
|
|
|
|
if (previousElement.parentElement.classList.contains("fn__flex-1")) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
previousElement = previousElement.parentElement;
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-11-03 00:09:44 +08:00
|
|
|
|
if (previousElement.classList.contains("b3-list-item")) {
|
|
|
|
|
|
liElements.forEach((item) => {
|
2022-11-04 21:50:03 +08:00
|
|
|
|
item.classList.remove("b3-list-item--focus");
|
|
|
|
|
|
});
|
2022-11-03 00:09:44 +08:00
|
|
|
|
previousElement.classList.add("b3-list-item--focus");
|
|
|
|
|
|
const previousRect = previousElement.getBoundingClientRect();
|
|
|
|
|
|
const fileRect = files.element.getBoundingClientRect();
|
|
|
|
|
|
if (previousRect.top < fileRect.top || previousRect.bottom > fileRect.bottom) {
|
|
|
|
|
|
previousElement.scrollIntoView(previousRect.top < fileRect.top);
|
|
|
|
|
|
}
|
2022-06-07 18:19:22 +08:00
|
|
|
|
}
|
2022-11-03 00:09:44 +08:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (event.key === "Delete" || (event.key === "Backspace" && isMac())) {
|
2022-11-02 22:48:40 +08:00
|
|
|
|
window.siyuan.menus.menu.remove();
|
2022-11-04 21:50:03 +08:00
|
|
|
|
deleteFiles(liElements);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (event.key === "Enter") {
|
2022-11-02 22:48:40 +08:00
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
|
liElements.forEach(item => {
|
|
|
|
|
|
if (item.getAttribute("data-type") === "navigation-file") {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openFileById({app, id: item.getAttribute("data-node-id"), action: [Constants.CB_GET_FOCUS]});
|
2022-11-02 22:48:40 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
const itemTopULElement = hasTopClosestByTag(item, "UL");
|
|
|
|
|
|
if (itemTopULElement) {
|
|
|
|
|
|
files.getLeaf(item, itemTopULElement.getAttribute("data-url"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-11-04 21:50:03 +08:00
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2022-12-07 18:27:24 +08:00
|
|
|
|
|
2023-05-30 00:27:47 +08:00
|
|
|
|
const panelTreeKeydown = (app: App, event: KeyboardEvent) => {
|
2022-12-07 18:27:24 +08:00
|
|
|
|
// 面板折叠展开操作
|
2022-12-12 21:58:34 +08:00
|
|
|
|
const target = event.target as HTMLElement;
|
2023-02-16 14:03:03 +08:00
|
|
|
|
if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" ||
|
|
|
|
|
|
hasClosestByAttribute(target, "contenteditable", null) ||
|
|
|
|
|
|
hasClosestByClassName(target, "protyle", true)) {
|
2022-12-12 21:58:34 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2022-12-07 18:27:24 +08:00
|
|
|
|
if (!matchHotKey(window.siyuan.config.keymap.editor.general.collapse.custom, event) &&
|
|
|
|
|
|
!matchHotKey(window.siyuan.config.keymap.editor.general.expand.custom, event) &&
|
|
|
|
|
|
!event.key.startsWith("Arrow") && event.key !== "Enter") {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
let activePanelElement = document.querySelector(".layout__tab--active");
|
|
|
|
|
|
if (!activePanelElement) {
|
|
|
|
|
|
Array.from(document.querySelectorAll(".layout__wnd--active .layout-tab-container > div")).find(item => {
|
|
|
|
|
|
if (!item.classList.contains("fn__none") && item.className.indexOf("sy__") > -1) {
|
|
|
|
|
|
activePanelElement = item;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!activePanelElement) {
|
2022-12-07 22:52:41 +08:00
|
|
|
|
return false;
|
2022-12-07 18:27:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (activePanelElement.className.indexOf("sy__") === -1) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!event.repeat && matchHotKey(window.siyuan.config.keymap.editor.general.collapse.custom, event)) {
|
|
|
|
|
|
const collapseElement = activePanelElement.querySelector('.block__icon[data-type="collapse"]');
|
|
|
|
|
|
if (collapseElement) {
|
|
|
|
|
|
collapseElement.dispatchEvent(new CustomEvent("click"));
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!event.repeat && matchHotKey(window.siyuan.config.keymap.editor.general.expand.custom, event)) {
|
|
|
|
|
|
const expandElement = activePanelElement.querySelector('.block__icon[data-type="expand"]');
|
|
|
|
|
|
if (expandElement) {
|
|
|
|
|
|
expandElement.dispatchEvent(new CustomEvent("click"));
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (activePanelElement.classList.contains("sy__inbox") ||
|
|
|
|
|
|
activePanelElement.classList.contains("sy__globalGraph") ||
|
|
|
|
|
|
activePanelElement.classList.contains("sy__graph")) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2023-05-30 00:27:47 +08:00
|
|
|
|
|
|
|
|
|
|
let matchCommand = false;
|
|
|
|
|
|
app.plugins.find(item => {
|
|
|
|
|
|
item.commands.find(command => {
|
|
|
|
|
|
if (command.dockCallback && matchHotKey(command.customHotkey, event)) {
|
|
|
|
|
|
matchCommand = true;
|
|
|
|
|
|
command.dockCallback(activePanelElement as HTMLElement);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (matchCommand) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (matchCommand) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2022-12-07 18:27:24 +08:00
|
|
|
|
const model = (getInstanceById(activePanelElement.getAttribute("data-id"), window.siyuan.layout.layout) as Tab)?.model;
|
|
|
|
|
|
if (!model) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2022-12-07 22:52:41 +08:00
|
|
|
|
let activeItemElement = activePanelElement.querySelector(".b3-list-item--focus");
|
2022-12-07 18:27:24 +08:00
|
|
|
|
if (!activeItemElement) {
|
|
|
|
|
|
activeItemElement = activePanelElement.querySelector(".b3-list .b3-list-item");
|
|
|
|
|
|
if (activeItemElement) {
|
2022-12-07 22:52:41 +08:00
|
|
|
|
activeItemElement.classList.add("b3-list-item--focus");
|
2022-12-07 18:27:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-07 22:52:41 +08:00
|
|
|
|
let tree = (model as Backlink).tree;
|
2022-12-07 18:27:24 +08:00
|
|
|
|
if (activeItemElement.parentElement.parentElement.classList.contains("backlinkMList")) {
|
2022-12-07 22:52:41 +08:00
|
|
|
|
tree = (model as Backlink).mTree;
|
2022-12-07 18:27:24 +08:00
|
|
|
|
}
|
2022-12-12 21:58:34 +08:00
|
|
|
|
if (!tree) {
|
2022-12-13 14:10:53 +08:00
|
|
|
|
return false;
|
2022-12-12 21:58:34 +08:00
|
|
|
|
}
|
2022-12-07 18:27:24 +08:00
|
|
|
|
if (event.key === "Enter") {
|
|
|
|
|
|
tree.click(activeItemElement);
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2022-12-07 22:52:41 +08:00
|
|
|
|
const arrowElement = activeItemElement.querySelector(".b3-list-item__arrow");
|
2022-12-07 18:27:24 +08:00
|
|
|
|
if ((event.key === "ArrowRight" && !arrowElement.classList.contains("b3-list-item__arrow--open") && !arrowElement.parentElement.classList.contains("fn__hidden")) ||
|
|
|
|
|
|
(event.key === "ArrowLeft" && arrowElement.classList.contains("b3-list-item__arrow--open") && !arrowElement.parentElement.classList.contains("fn__hidden"))) {
|
|
|
|
|
|
tree.toggleBlocks(activeItemElement);
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
const ulElement = hasClosestByClassName(activeItemElement, "b3-list");
|
|
|
|
|
|
if (!ulElement) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (event.key === "ArrowLeft") {
|
|
|
|
|
|
let parentElement = activeItemElement.parentElement.previousElementSibling;
|
|
|
|
|
|
if (parentElement) {
|
|
|
|
|
|
if (parentElement.tagName !== "LI") {
|
|
|
|
|
|
parentElement = ulElement.querySelector(".b3-list-item");
|
|
|
|
|
|
}
|
|
|
|
|
|
activeItemElement.classList.remove("b3-list-item--focus");
|
|
|
|
|
|
parentElement.classList.add("b3-list-item--focus");
|
|
|
|
|
|
const parentRect = parentElement.getBoundingClientRect();
|
|
|
|
|
|
const scrollRect = ulElement.parentElement.getBoundingClientRect();
|
|
|
|
|
|
if (parentRect.top < scrollRect.top || parentRect.bottom > scrollRect.bottom) {
|
|
|
|
|
|
parentElement.scrollIntoView(parentRect.top < scrollRect.top);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (event.key === "ArrowDown" || event.key === "ArrowRight") {
|
|
|
|
|
|
let nextElement = activeItemElement;
|
|
|
|
|
|
while (nextElement) {
|
|
|
|
|
|
if (nextElement.nextElementSibling) {
|
|
|
|
|
|
if (nextElement.nextElementSibling.tagName === "UL") {
|
2022-12-08 15:41:27 +08:00
|
|
|
|
if (nextElement.nextElementSibling.classList.contains("fn__none")) { // 遇到折叠内容
|
|
|
|
|
|
if (nextElement.nextElementSibling.nextElementSibling) {
|
2022-12-08 21:53:07 +08:00
|
|
|
|
nextElement = nextElement.nextElementSibling.nextElementSibling;
|
2022-12-08 15:41:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
nextElement = nextElement.nextElementSibling.firstElementChild;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (nextElement.nextElementSibling.classList.contains("protyle")) { // backlink
|
2022-12-07 18:27:24 +08:00
|
|
|
|
if (nextElement.nextElementSibling.nextElementSibling) {
|
|
|
|
|
|
nextElement = nextElement.nextElementSibling.nextElementSibling;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
nextElement = nextElement.nextElementSibling;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (nextElement.parentElement.classList.contains("fn__flex-1")) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
nextElement = nextElement.parentElement;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (nextElement.classList.contains("b3-list-item") && !nextElement.classList.contains("b3-list-item--focus")) {
|
|
|
|
|
|
activeItemElement.classList.remove("b3-list-item--focus");
|
|
|
|
|
|
nextElement.classList.add("b3-list-item--focus");
|
|
|
|
|
|
const nextRect = nextElement.getBoundingClientRect();
|
|
|
|
|
|
const scrollRect = ulElement.parentElement.getBoundingClientRect();
|
|
|
|
|
|
if (nextRect.top < scrollRect.top || nextRect.bottom > scrollRect.bottom) {
|
|
|
|
|
|
nextElement.scrollIntoView(nextRect.top < scrollRect.top);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (event.key === "ArrowUp") {
|
|
|
|
|
|
let previousElement = activeItemElement;
|
|
|
|
|
|
while (previousElement) {
|
|
|
|
|
|
if (previousElement.previousElementSibling) {
|
|
|
|
|
|
if (previousElement.previousElementSibling.tagName === "LI") {
|
|
|
|
|
|
previousElement = previousElement.previousElementSibling;
|
|
|
|
|
|
} else if (previousElement.previousElementSibling.classList.contains("protyle")) {
|
|
|
|
|
|
if (previousElement.previousElementSibling.previousElementSibling) {
|
|
|
|
|
|
previousElement = previousElement.previousElementSibling.previousElementSibling;
|
|
|
|
|
|
}
|
2022-12-08 15:41:27 +08:00
|
|
|
|
} else if (previousElement.previousElementSibling.tagName === "UL" && previousElement.previousElementSibling.classList.contains("fn__none")) { // 遇到折叠内容
|
|
|
|
|
|
if (previousElement.previousElementSibling.previousElementSibling) {
|
|
|
|
|
|
previousElement = previousElement.previousElementSibling.previousElementSibling;
|
|
|
|
|
|
}
|
2022-12-07 18:27:24 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
const liElements = previousElement.previousElementSibling.querySelectorAll(".b3-list-item");
|
|
|
|
|
|
previousElement = liElements[liElements.length - 1];
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (previousElement.parentElement.classList.contains("fn__flex-1")) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
previousElement = previousElement.parentElement;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (previousElement.classList.contains("b3-list-item") && !previousElement.classList.contains("b3-list-item--focus")) {
|
|
|
|
|
|
activeItemElement.classList.remove("b3-list-item--focus");
|
|
|
|
|
|
previousElement.classList.add("b3-list-item--focus");
|
|
|
|
|
|
const previousRect = previousElement.getBoundingClientRect();
|
|
|
|
|
|
const scrollRect = ulElement.parentElement.getBoundingClientRect();
|
|
|
|
|
|
if (previousRect.top < scrollRect.top || previousRect.bottom > scrollRect.bottom) {
|
|
|
|
|
|
previousElement.scrollIntoView(previousRect.top < scrollRect.top);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2022-12-07 22:52:41 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
};
|
2022-12-07 18:27:24 +08:00
|
|
|
|
|