2022-06-29 09:09:18 +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";
|
|
|
|
|
|
import {newFile} from "./newFile";
|
|
|
|
|
|
import {Constants} from "../constants";
|
|
|
|
|
|
import {openSetting} from "../config";
|
2022-06-10 16:07:38 +08:00
|
|
|
|
import {exportLayout, getDockByType, getInstanceById, setPanelFocus} 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";
|
|
|
|
|
|
import {newDailyNote} from "./mount";
|
|
|
|
|
|
import {hideElements} from "../protyle/ui/hideElements";
|
|
|
|
|
|
import {fetchPost} from "./fetch";
|
|
|
|
|
|
import {goBack, goForward} from "./backForward";
|
|
|
|
|
|
import {onGet} from "../protyle/util/onGet";
|
2022-11-04 21:48:50 +08:00
|
|
|
|
import {getDisplayName, getNotebookName, getTopPaths, movePathTo} from "./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";
|
|
|
|
|
|
import {openHistory} from "./history";
|
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";
|
2022-06-29 18:47:02 +08:00
|
|
|
|
import {escapeHtml} from "./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-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;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-06-29 09:52:50 +08:00
|
|
|
|
const switchDialogEvent = (event: MouseEvent, switchDialog: Dialog) => {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
let target = event.target as HTMLElement;
|
|
|
|
|
|
while (!target.isSameNode(switchDialog.element)) {
|
|
|
|
|
|
if (target.classList.contains("b3-list-item")) {
|
|
|
|
|
|
const currentType = target.getAttribute("data-type") as TDockType;
|
|
|
|
|
|
if (currentType) {
|
|
|
|
|
|
getDockByType(currentType).toggleModel(currentType, true);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const currentId = target.getAttribute("data-id");
|
|
|
|
|
|
getAllTabs().find(item => {
|
|
|
|
|
|
if (item.id === currentId) {
|
|
|
|
|
|
item.parent.switchTab(item.headElement);
|
|
|
|
|
|
setPanelFocus(item.headElement.parentElement.parentElement);
|
|
|
|
|
|
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
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
export const globalShortcut = () => {
|
|
|
|
|
|
window.addEventListener("mousemove", (event) => {
|
|
|
|
|
|
if (window.siyuan.hideBreadcrumb) {
|
|
|
|
|
|
getAllModels().editor.forEach(item => {
|
|
|
|
|
|
item.editor.protyle.breadcrumb.show();
|
|
|
|
|
|
});
|
|
|
|
|
|
window.siyuan.blockPanels.forEach(item => {
|
|
|
|
|
|
item.editors.forEach(edit => {
|
|
|
|
|
|
edit.protyle.breadcrumb.show();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
const blockElement = hasClosestBlock(target);
|
|
|
|
|
|
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.stopPropagation();
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
goBack();
|
|
|
|
|
|
} else if (event.button === 4) {
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
goForward();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
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-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");
|
|
|
|
|
|
}
|
2022-06-29 09:10:03 +08:00
|
|
|
|
const currentType = currentLiElement.getAttribute("data-type") as TDockType;
|
2022-06-28 23:20:12 +08:00
|
|
|
|
if (currentType) {
|
|
|
|
|
|
getDockByType(currentType).toggleModel(currentType, true);
|
|
|
|
|
|
const target = event.target as HTMLElement;
|
|
|
|
|
|
if (target.classList.contains("protyle-wysiwyg") ||
|
|
|
|
|
|
target.classList.contains("protyle-title__input") ||
|
|
|
|
|
|
target.tagName === "INPUT" || target.tagName === "TEXTAREA") {
|
|
|
|
|
|
target.blur();
|
|
|
|
|
|
}
|
|
|
|
|
|
} 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);
|
|
|
|
|
|
setPanelFocus(item.headElement.parentElement.parentElement);
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 仅处理以下快捷键操作
|
|
|
|
|
|
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) {
|
2022-10-30 00:16:48 +08:00
|
|
|
|
showPopover();
|
2022-10-28 23:29:07 +08:00
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
window.siyuan.ctrlIsPressed = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!event.altKey && event.shiftKey && !isCtrl(event)) {
|
|
|
|
|
|
if (event.key === "Shift") {
|
|
|
|
|
|
window.siyuan.shiftIsPressed = true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
window.siyuan.shiftIsPressed = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (event.altKey && !event.shiftKey && !isCtrl(event)) {
|
|
|
|
|
|
if (event.key === "Alt") {
|
|
|
|
|
|
window.siyuan.altIsPressed = true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
window.siyuan.altIsPressed = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-06-29 09:09:18 +08:00
|
|
|
|
}).forEach(item => {
|
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-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-06-29 09:10:03 +08:00
|
|
|
|
icon = `<span class="b3-list-item__graphic">${unicode2Emoji(item.docIcon || Constants.SIYUAN_IMAGE_FILE)}</span>`;
|
2022-06-28 23:20:12 +08:00
|
|
|
|
}
|
2022-07-13 23:08:27 +08:00
|
|
|
|
tabHtml += `<li 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 = "";
|
|
|
|
|
|
getAllDocks().forEach(item => {
|
|
|
|
|
|
dockHtml += `<li data-type="${item.type}" class="b3-list-item${(!tabHtml && !dockHtml) ? " b3-list-item--focus" : ""}">
|
|
|
|
|
|
<svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg>
|
|
|
|
|
|
<span class="b3-list-item__text">${window.siyuan.languages[item.hotkeyLangId]}</span>
|
|
|
|
|
|
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general[item.hotkeyLangId].custom)}</span>
|
|
|
|
|
|
</li>`;
|
|
|
|
|
|
});
|
2022-06-28 23:20:12 +08:00
|
|
|
|
switchDialog = new Dialog({
|
|
|
|
|
|
content: `<div class="fn__flex-column b3-dialog--switch">
|
|
|
|
|
|
<div class="fn__hr"></div>
|
|
|
|
|
|
<div class="fn__flex">
|
|
|
|
|
|
<ul class="b3-list b3-list--background">${dockHtml}</ul>
|
|
|
|
|
|
<ul class="b3-list b3-list--background">${tabHtml}</ul>
|
|
|
|
|
|
</div>
|
2022-07-13 23:08:27 +08:00
|
|
|
|
<div class="dialog__path"></div>
|
2022-06-29 09:21:08 +08:00
|
|
|
|
</div>`,
|
2022-06-29 09:52:50 +08:00
|
|
|
|
disableClose: true,
|
|
|
|
|
|
disableAnimation: true,
|
|
|
|
|
|
transparent: true,
|
2022-06-28 23:20:12 +08:00
|
|
|
|
});
|
2022-06-29 09:52:50 +08:00
|
|
|
|
if (isMac()) {
|
|
|
|
|
|
switchDialog.element.addEventListener("contextmenu", (event) => {
|
2022-06-29 17:52:37 +08:00
|
|
|
|
switchDialogEvent(event, switchDialog);
|
2022-06-29 09:52:50 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
switchDialog.element.addEventListener("click", (event) => {
|
2022-06-29 17:52:37 +08:00
|
|
|
|
switchDialogEvent(event, switchDialog);
|
2022-06-29 09:10:03 +08:00
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-07-09 15:53:52 +08:00
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.syncNow.custom, event)) {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
event.stopPropagation();
|
2022-08-28 11:08:33 +08:00
|
|
|
|
syncGuide(document.querySelector("#barSync"));
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.lockScreen.custom, event)) {
|
2022-06-11 10:56:58 +08:00
|
|
|
|
exportLayout(false, () => {
|
|
|
|
|
|
fetchPost("/api/system/logoutAuth", {}, () => {
|
2022-06-10 16:07:38 +08:00
|
|
|
|
window.location.href = "/";
|
2022-06-11 00:51:42 +08:00
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.stopPropagation();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-09-25 23:20:08 +08:00
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.dataHistory.custom, event)) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
openHistory();
|
|
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.stopPropagation();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!window.siyuan.config.readonly && matchHotKey(window.siyuan.config.keymap.general.config.custom, event)) {
|
|
|
|
|
|
openSetting();
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
event.stopPropagation();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
return;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
const target = event.target as HTMLElement;
|
|
|
|
|
|
if (matchHotKey("⌘A", event) && target.tagName !== "INPUT" && target.tagName !== "TEXTAREA") {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const matchDock = getAllDocks().find(item => {
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general[item.hotkeyLangId].custom, event)) {
|
|
|
|
|
|
getDockByType(item.type).toggleModel(item.type);
|
|
|
|
|
|
if (target.classList.contains("protyle-wysiwyg") ||
|
|
|
|
|
|
target.classList.contains("protyle-title__input") ||
|
|
|
|
|
|
target.tagName === "INPUT" || target.tagName === "TEXTAREA") {
|
|
|
|
|
|
target.blur();
|
|
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.stopPropagation();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (matchDock) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.dailyNote.custom, event)) {
|
|
|
|
|
|
newDailyNote();
|
|
|
|
|
|
if (target.classList.contains("protyle-wysiwyg") ||
|
|
|
|
|
|
target.classList.contains("protyle-title__input") ||
|
|
|
|
|
|
target.tagName === "INPUT" || target.tagName === "TEXTAREA") {
|
|
|
|
|
|
target.blur();
|
|
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.stopPropagation();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.newFile.custom, event)) {
|
|
|
|
|
|
newFile(undefined, undefined, true);
|
|
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.stopPropagation();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
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();
|
|
|
|
|
|
if (item.esc) {
|
|
|
|
|
|
item.esc();
|
|
|
|
|
|
}
|
|
|
|
|
|
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)) {
|
|
|
|
|
|
goForward();
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.goBack.custom, event)) {
|
|
|
|
|
|
goBack();
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const confirmElement = document.querySelector("#confirmDialogConfirmBtn");
|
|
|
|
|
|
if (confirmElement && event.key === "Enter") {
|
|
|
|
|
|
confirmElement.dispatchEvent(new CustomEvent("click"));
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 面板折叠展开操作
|
2022-09-22 15:22:11 +08:00
|
|
|
|
if (!event.repeat && (matchHotKey(window.siyuan.config.keymap.editor.general.collapse.custom, event) || matchHotKey(window.siyuan.config.keymap.editor.general.expand.custom, event))) {
|
2022-10-14 22:29:40 +08:00
|
|
|
|
let activePanelElement = document.querySelector(".layout__tab--active");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (!activePanelElement) {
|
|
|
|
|
|
Array.from(document.querySelectorAll(".layout__wnd--active .layout-tab-container > div")).forEach(item => {
|
|
|
|
|
|
if (!item.classList.contains("fn__none")) {
|
|
|
|
|
|
activePanelElement = item;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (activePanelElement) {
|
2022-09-06 22:46:34 +08:00
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.collapse.custom, event)) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (activePanelElement.querySelector('.block__icon[data-type="collapse"]')) {
|
|
|
|
|
|
activePanelElement.querySelector('.block__icon[data-type="collapse"]').dispatchEvent(new CustomEvent("click"));
|
|
|
|
|
|
}
|
2022-09-06 22:46:34 +08:00
|
|
|
|
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.expand.custom, event)) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (activePanelElement.querySelector('.block__icon[data-type="expand"]')) {
|
|
|
|
|
|
activePanelElement.querySelector('.block__icon[data-type="expand"]').dispatchEvent(new CustomEvent("click"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
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();
|
|
|
|
|
|
event.stopPropagation();
|
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) {
|
2022-07-15 09:56:52 +08:00
|
|
|
|
let type: TDockType;
|
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__")) {
|
|
|
|
|
|
type = item.replace("sy__", "") as TDockType;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (type) {
|
|
|
|
|
|
getDockByType(type).toggleModel(type, false, true);
|
|
|
|
|
|
}
|
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);
|
|
|
|
|
|
openGlobalSearch(range.toString(), false);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
openGlobalSearch("", false);
|
|
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.stopPropagation();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (editKeydown(event)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 文件树的操作
|
|
|
|
|
|
if (fileTreeKeydown(event)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
openSearch(searchKey, range.toString());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
openSearch(searchKey);
|
|
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.stopPropagation();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-07-09 15:53:52 +08:00
|
|
|
|
|
|
|
|
|
|
// https://github.com/siyuan-note/insider/issues/445
|
|
|
|
|
|
if (matchHotKey("⌘S", event)) {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
if (!hasClosestByClassName(event.target, "pdf__outer")) {
|
|
|
|
|
|
document.querySelectorAll(".pdf__util").forEach(item => {
|
|
|
|
|
|
item.classList.add("fn__none");
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
const copyElement = hasTopClosestByClassName(event.target, "protyle-action__copy");
|
|
|
|
|
|
if (copyElement) {
|
|
|
|
|
|
writeText(copyElement.parentElement.nextElementSibling.textContent.trimEnd());
|
|
|
|
|
|
showMessage(window.siyuan.languages.copied, 2000);
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 点击空白,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();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const editKeydown = (event: KeyboardEvent) => {
|
|
|
|
|
|
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)) {
|
|
|
|
|
|
openSearch(searchKey, range.toString(), protyle.notebookId, protyle.path);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
openSearch(searchKey);
|
|
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.stopPropagation();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (nodeElement && range && protyle.element.contains(range.startContainer)) {
|
|
|
|
|
|
protyle.toolbar.showFile(protyle, [nodeElement], range);
|
|
|
|
|
|
} else {
|
2022-11-04 21:48:50 +08:00
|
|
|
|
movePathTo([protyle.path]);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.stopPropagation();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
const target = event.target as HTMLElement;
|
|
|
|
|
|
if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || hasClosestByAttribute(target, "contenteditable", null)) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.preview.custom, event)) {
|
|
|
|
|
|
setEditMode(protyle, "preview");
|
|
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.stopPropagation();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
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 => {
|
|
|
|
|
|
onGet(getResponse, protyle);
|
|
|
|
|
|
});
|
|
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.stopPropagation();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 没有光标时,无法撤销 https://ld246.com/article/1624021111567
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.undo.custom, event)) {
|
|
|
|
|
|
protyle.undo.undo(protyle);
|
|
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.stopPropagation();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.redo.custom, event)) {
|
|
|
|
|
|
protyle.undo.redo(protyle);
|
|
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.stopPropagation();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const fileTreeKeydown = (event: KeyboardEvent) => {
|
|
|
|
|
|
const dockFile = getDockByType("file");
|
|
|
|
|
|
if (!dockFile) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
const files = dockFile.data.file as Files;
|
2022-06-07 21:20:02 +08:00
|
|
|
|
if (matchHotKey(window.siyuan.config.keymap.general.selectOpen1.custom, event)) {
|
|
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.stopPropagation();
|
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) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (event.key.startsWith("Arrow")) {
|
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";
|
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();
|
|
|
|
|
|
event.stopPropagation();
|
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) {
|
2022-11-02 22:48:40 +08:00
|
|
|
|
initFileMenu(notebookId, pathString, liElements[0]).popup({
|
2022-05-26 15:18:53 +08:00
|
|
|
|
x: liRect.right - 15,
|
|
|
|
|
|
y: liRect.top + 15
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
2022-11-02 22:48:40 +08:00
|
|
|
|
initNavigationMenu(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-04 21:48:50 +08:00
|
|
|
|
movePathTo(getTopPaths(liElements), false);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.stopPropagation();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
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) {
|
|
|
|
|
|
openSearch(searchKey, undefined, notebookId, getDisplayName(pathString, false, true));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
openSearch(searchKey, undefined, notebookId);
|
|
|
|
|
|
}
|
|
|
|
|
|
event.preventDefault();
|
2022-07-09 15:53:52 +08:00
|
|
|
|
event.stopPropagation();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
const target = event.target as HTMLElement;
|
|
|
|
|
|
if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || hasClosestByAttribute(target, "contenteditable", null)) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (bindMenuKeydown(event)) {
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
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;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
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") {
|
|
|
|
|
|
openFileById({id: item.getAttribute("data-node-id"), action: [Constants.CB_GET_FOCUS]});
|
|
|
|
|
|
} 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;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|