This commit is contained in:
Vanessa 2022-11-04 21:50:03 +08:00
parent bc3ab68a9d
commit be3ac44ce7
12 changed files with 80 additions and 85 deletions

View file

@ -33,7 +33,7 @@ export const deleteFiles = (liElements: Element[]) => {
if (liElements.length === 1) { if (liElements.length === 1) {
const itemTopULElement = hasTopClosestByTag(liElements[0], "UL"); const itemTopULElement = hasTopClosestByTag(liElements[0], "UL");
if (itemTopULElement) { if (itemTopULElement) {
const itemNotebookId = itemTopULElement.getAttribute("data-url") const itemNotebookId = itemTopULElement.getAttribute("data-url");
if (liElements[0].getAttribute("data-type") === "navigation-file") { if (liElements[0].getAttribute("data-type") === "navigation-file") {
deleteFile(itemNotebookId, liElements[0].getAttribute("data-path"), getDisplayName(liElements[0].getAttribute("data-name"), false, true)); deleteFile(itemNotebookId, liElements[0].getAttribute("data-path"), getDisplayName(liElements[0].getAttribute("data-name"), false, true));
} else { } else {
@ -47,13 +47,13 @@ export const deleteFiles = (liElements: Element[]) => {
} }
} }
} else { } else {
const paths: string[] = [] const paths: string[] = [];
liElements.forEach(item => { liElements.forEach(item => {
const dataPath = item.getAttribute("data-path") const dataPath = item.getAttribute("data-path");
if (dataPath !== "/") { if (dataPath !== "/") {
paths.push(item.getAttribute("data-path")); paths.push(item.getAttribute("data-path"));
} }
}) });
if (paths.length === 0) { if (paths.length === 0) {
showMessage(window.siyuan.languages.notBatchRemove); showMessage(window.siyuan.languages.notBatchRemove);
return; return;
@ -65,4 +65,4 @@ export const deleteFiles = (liElements: Element[]) => {
}); });
}); });
} }
} };

View file

@ -483,7 +483,7 @@ export class Wnd {
private renderTabList(event: MouseEvent) { private renderTabList(event: MouseEvent) {
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();
window.siyuan.menus.menu.element.classList.add("b3-menu--list") window.siyuan.menus.menu.element.classList.add("b3-menu--list");
Array.from(this.headersElement.children).forEach((item: HTMLElement) => { Array.from(this.headersElement.children).forEach((item: HTMLElement) => {
const iconElement = item.querySelector(".item__icon"); const iconElement = item.querySelector(".item__icon");
const graphicElement = item.querySelector(".item__graphic"); const graphicElement = item.querySelector(".item__graphic");

View file

@ -1,6 +1,5 @@
import {Tab} from "../Tab"; import {Tab} from "../Tab";
import {Model} from "../Model"; import {Model} from "../Model";
import {getDisplayName} from "../../util/pathName";
import {Tree} from "../../util/Tree"; import {Tree} from "../../util/Tree";
import {getDockByType, setPanelFocus} from "../util"; import {getDockByType, setPanelFocus} from "../util";
import {fetchPost} from "../../util/fetch"; import {fetchPost} from "../../util/fetch";

View file

@ -282,34 +282,34 @@ export class Files extends Model {
window.getSelection().removeAllRanges(); window.getSelection().removeAllRanges();
const liElement = hasClosestByTag(event.target, "LI"); const liElement = hasClosestByTag(event.target, "LI");
if (liElement) { if (liElement) {
let selectElements: Element[] = Array.from(this.element.querySelectorAll(".b3-list-item--focus")) let selectElements: Element[] = Array.from(this.element.querySelectorAll(".b3-list-item--focus"));
if (!liElement.classList.contains("b3-list-item--focus")) { if (!liElement.classList.contains("b3-list-item--focus")) {
selectElements.forEach((item) => { selectElements.forEach((item) => {
item.classList.remove("b3-list-item--focus"); item.classList.remove("b3-list-item--focus");
}) });
liElement.classList.add("b3-list-item--focus"); liElement.classList.add("b3-list-item--focus");
selectElements = [liElement]; selectElements = [liElement];
} }
let ids = "" let ids = "";
selectElements.forEach((item: HTMLElement) => { selectElements.forEach((item: HTMLElement) => {
item.style.opacity = "0.1"; item.style.opacity = "0.1";
ids += (item.getAttribute("data-node-id") || "") + "," ids += (item.getAttribute("data-node-id") || "") + ",";
}) });
const img = new Image(); const img = new Image();
// TODO: drag preview // TODO: drag preview
img.src = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACYAAAAmCAYAAACoPemuAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABklJREFUeNqsmFtwE1UYx/97Tdqkbei91Gk6IFouYjqjBR3aQTstoM40DD4gOIO++sL4pr45+q7iu+OMyJMD1RcZAXGEBxiUm0JrKfQiD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/tfgAEAQ3WUFGFdgUwAAAAASUVORK5CYII=";
event.dataTransfer.setDragImage(img, 10, 10); event.dataTransfer.setDragImage(img, 10, 10);
event.dataTransfer.setData(Constants.SIYUAN_DROP_FILE, ids); event.dataTransfer.setData(Constants.SIYUAN_DROP_FILE, ids);
event.dataTransfer.dropEffect = "move"; event.dataTransfer.dropEffect = "move";
const tempEelement = document.createElement("div") const tempEelement = document.createElement("div");
tempEelement.innerText = ids; tempEelement.innerText = ids;
window.siyuan.dragElement = tempEelement; window.siyuan.dragElement = tempEelement;
} }
}); });
this.element.addEventListener("dragend", (event: DragEvent & { target: HTMLElement }) => { this.element.addEventListener("dragend", () => {
this.element.querySelectorAll(".b3-list-item--focus").forEach((item: HTMLElement) => { this.element.querySelectorAll(".b3-list-item--focus").forEach((item: HTMLElement) => {
item.style.opacity = "" item.style.opacity = "";
}) });
window.siyuan.dragElement = undefined; window.siyuan.dragElement = undefined;
}); });
this.element.addEventListener("dragover", (event: DragEvent & { target: HTMLElement }) => { this.element.addEventListener("dragover", (event: DragEvent & { target: HTMLElement }) => {
@ -330,13 +330,13 @@ export class Files extends Model {
event.preventDefault(); event.preventDefault();
return; return;
} }
let sourceOnlyRoot = true let sourceOnlyRoot = true;
Array.from(this.element.querySelectorAll(".b3-list-item--focus")).find((item: HTMLElement) => { Array.from(this.element.querySelectorAll(".b3-list-item--focus")).find((item: HTMLElement) => {
if (item.getAttribute("data-type") === "navigation-file") { if (item.getAttribute("data-type") === "navigation-file") {
sourceOnlyRoot = false sourceOnlyRoot = false;
return true; return true;
} }
}) });
const targetType = liElement.getAttribute("data-type"); const targetType = liElement.getAttribute("data-type");
if (sourceOnlyRoot && targetType !== "navigation-root") { if (sourceOnlyRoot && targetType !== "navigation-root") {
event.preventDefault(); event.preventDefault();
@ -379,7 +379,7 @@ export class Files extends Model {
} }
const toURL = newUlElement.getAttribute("data-url"); const toURL = newUlElement.getAttribute("data-url");
const toPath = newElement.getAttribute("data-path"); const toPath = newElement.getAttribute("data-path");
const gutterType = window.siyuan.dragElement?.getAttribute("data-type") const gutterType = window.siyuan.dragElement?.getAttribute("data-type");
if (newElement.classList.contains("dragover") && ["NodeListItem", "NodeHeading"].includes(gutterType)) { if (newElement.classList.contains("dragover") && ["NodeListItem", "NodeHeading"].includes(gutterType)) {
// 块标拖拽 // 块标拖拽
if (gutterType === "NodeHeading") { if (gutterType === "NodeHeading") {
@ -406,22 +406,22 @@ export class Files extends Model {
newElement.classList.remove("dragover", "dragover__bottom", "dragover__top"); newElement.classList.remove("dragover", "dragover__bottom", "dragover__top");
return; return;
} }
const selectRootElements: HTMLElement[] = [] const selectRootElements: HTMLElement[] = [];
const selectFileElements: HTMLElement[] = [] const selectFileElements: HTMLElement[] = [];
const fromPaths: string[] = [] const fromPaths: string[] = [];
this.element.querySelectorAll(".b3-list-item--focus").forEach((item: HTMLElement) => { this.element.querySelectorAll(".b3-list-item--focus").forEach((item: HTMLElement) => {
if (item.getAttribute("data-type") === "navigation-root") { if (item.getAttribute("data-type") === "navigation-root") {
selectRootElements.push(item) selectRootElements.push(item);
} else { } else {
const dataPath = item.getAttribute("data-path") const dataPath = item.getAttribute("data-path");
const isChild = fromPaths.find(item => { const isChild = fromPaths.find(item => {
if (dataPath.startsWith(item.replace(".sy", ""))) { if (dataPath.startsWith(item.replace(".sy", ""))) {
return true; return true;
} }
}) });
if (!isChild) { if (!isChild) {
selectFileElements.push(item) selectFileElements.push(item);
fromPaths.push(dataPath) fromPaths.push(dataPath);
} }
} }
}); });
@ -437,11 +437,11 @@ export class Files extends Model {
if (newElement.classList.contains("dragover__top")) { if (newElement.classList.contains("dragover__top")) {
selectRootElements.forEach(item => { selectRootElements.forEach(item => {
newElement.parentElement.before(item.parentElement); newElement.parentElement.before(item.parentElement);
}) });
} else { } else {
selectRootElements.reverse().forEach(item => { selectRootElements.reverse().forEach(item => {
newElement.parentElement.after(item.parentElement); newElement.parentElement.after(item.parentElement);
}) });
} }
const notebooks: string[] = []; const notebooks: string[] = [];
Array.from(this.element.children).forEach(item => { Array.from(this.element.children).forEach(item => {
@ -461,7 +461,7 @@ export class Files extends Model {
}); });
selectFileElements.forEach(item => { selectFileElements.forEach(item => {
item.setAttribute("data-path", pathPosix().join(toDir, item.getAttribute("data-node-id") + ".sy")); item.setAttribute("data-path", pathPosix().join(toDir, item.getAttribute("data-node-id") + ".sy"));
}) });
hasMove = true; hasMove = true;
} }
if (newElement.classList.contains("dragover__top")) { if (newElement.classList.contains("dragover__top")) {
@ -474,7 +474,7 @@ export class Files extends Model {
if (nextULElement) { if (nextULElement) {
item.after(nextULElement); item.after(nextULElement);
} }
}) });
} else if (newElement.classList.contains("dragover__bottom")) { } else if (newElement.classList.contains("dragover__bottom")) {
selectFileElements.reverse().forEach(item => { selectFileElements.reverse().forEach(item => {
let nextULElement; let nextULElement;
@ -489,7 +489,7 @@ export class Files extends Model {
if (nextULElement) { if (nextULElement) {
item.after(nextULElement); item.after(nextULElement);
} }
}) });
} }
const paths: string[] = []; const paths: string[] = [];
Array.from(newElement.parentElement.children).forEach(item => { Array.from(newElement.parentElement.children).forEach(item => {
@ -668,7 +668,7 @@ export class Files extends Model {
targetElement.remove(); targetElement.remove();
} }
} }
}) });
} }
private onMount(data: { data: { box: INotebook, existed?: boolean }, callback?: string }) { private onMount(data: { data: { box: INotebook, existed?: boolean }, callback?: string }) {

View file

@ -23,7 +23,6 @@ import {rename} from "../editor/rename";
import {matchHotKey} from "../protyle/util/hotKey"; import {matchHotKey} from "../protyle/util/hotKey";
import * as dayjs from "dayjs"; import * as dayjs from "dayjs";
import {Constants} from "../constants"; import {Constants} from "../constants";
import {deleteFile} from "../editor/deleteFile";
const bindAttrInput = (inputElement: HTMLInputElement, confirmElement: Element) => { const bindAttrInput = (inputElement: HTMLInputElement, confirmElement: Element) => {
inputElement.addEventListener("keydown", (event) => { inputElement.addEventListener("keydown", (event) => {
@ -266,7 +265,7 @@ export const openFileAttr = (attrs: IObject, id: string, focusName = "bookmark")
}); });
} }
window.siyuan.menus.menu.element.style.zIndex = "310"; window.siyuan.menus.menu.element.style.zIndex = "310";
window.siyuan.menus.menu.element.classList.add("b3-menu--list") window.siyuan.menus.menu.element.classList.add("b3-menu--list");
window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY + 16, w: 16}); window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY + 16, w: 16});
}); });
break; break;
@ -472,7 +471,7 @@ export const openAttr = (nodeElement: Element, protyle: IProtyle, focusName = "b
}); });
} }
window.siyuan.menus.menu.element.style.zIndex = "310"; window.siyuan.menus.menu.element.style.zIndex = "310";
window.siyuan.menus.menu.element.classList.add("b3-menu--list") window.siyuan.menus.menu.element.classList.add("b3-menu--list");
window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY + 16, w: 16}); window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY + 16, w: 16});
}); });
break; break;

View file

@ -19,23 +19,22 @@ import {onGetnotebookconf} from "./onGetnotebookconf";
import {openSearch} from "../search/spread"; import {openSearch} from "../search/spread";
import {openFileById} from "../editor/util"; import {openFileById} from "../editor/util";
/// #endif /// #endif
import {confirmDialog} from "../dialog/confirmDialog";
import {Constants} from "../constants"; import {Constants} from "../constants";
import {newFile} from "../util/newFile"; import {newFile} from "../util/newFile";
import {hasClosestByClassName} from "../protyle/util/hasClosest"; import {hasClosestByClassName} from "../protyle/util/hasClosest";
import {deleteFile, deleteFiles} from "../editor/deleteFile"; import {deleteFiles} from "../editor/deleteFile";
export const initNavigationMenu = (liElement: HTMLElement) => { export const initNavigationMenu = (liElement: HTMLElement) => {
const fileElement = hasClosestByClassName(liElement, "sy__file") const fileElement = hasClosestByClassName(liElement, "sy__file");
if (!fileElement) { if (!fileElement) {
return; return;
} }
if (!liElement.classList.contains("b3-list-item--focus")) { if (!liElement.classList.contains("b3-list-item--focus")) {
fileElement.querySelectorAll(".b3-list-item--focus").forEach(item => { fileElement.querySelectorAll(".b3-list-item--focus").forEach(item => {
item.classList.remove("b3-list-item--focus"); item.classList.remove("b3-list-item--focus");
item.removeAttribute("select-end") item.removeAttribute("select-end");
item.removeAttribute("select-start") item.removeAttribute("select-start");
}) });
liElement.classList.add("b3-list-item--focus"); liElement.classList.add("b3-list-item--focus");
} }
const notebookId = liElement.parentElement.getAttribute("data-url"); const notebookId = liElement.parentElement.getAttribute("data-url");
@ -93,7 +92,7 @@ export const initNavigationMenu = (liElement: HTMLElement) => {
label: window.siyuan.languages.delete, label: window.siyuan.languages.delete,
accelerator: "⌦", accelerator: "⌦",
click: () => { click: () => {
deleteFiles(Array.from(fileElement.querySelectorAll(".b3-list-item--focus"))) deleteFiles(Array.from(fileElement.querySelectorAll(".b3-list-item--focus")));
} }
}).element); }).element);
} }
@ -143,16 +142,16 @@ export const initNavigationMenu = (liElement: HTMLElement) => {
}; };
export const initFileMenu = (notebookId: string, pathString: string, liElement: Element) => { export const initFileMenu = (notebookId: string, pathString: string, liElement: Element) => {
const fileElement = hasClosestByClassName(liElement, "sy__file") const fileElement = hasClosestByClassName(liElement, "sy__file");
if (!fileElement) { if (!fileElement) {
return; return;
} }
if (!liElement.classList.contains("b3-list-item--focus")) { if (!liElement.classList.contains("b3-list-item--focus")) {
fileElement.querySelectorAll(".b3-list-item--focus").forEach(item => { fileElement.querySelectorAll(".b3-list-item--focus").forEach(item => {
item.classList.remove("b3-list-item--focus"); item.classList.remove("b3-list-item--focus");
item.removeAttribute("select-end") item.removeAttribute("select-end");
item.removeAttribute("select-start") item.removeAttribute("select-start");
}) });
liElement.classList.add("b3-list-item--focus"); liElement.classList.add("b3-list-item--focus");
} }
const id = liElement.getAttribute("data-node-id"); const id = liElement.getAttribute("data-node-id");
@ -216,7 +215,7 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
label: window.siyuan.languages.delete, label: window.siyuan.languages.delete,
accelerator: "⌦", accelerator: "⌦",
click: () => { click: () => {
deleteFiles(Array.from(fileElement.querySelectorAll(".b3-list-item--focus"))) deleteFiles(Array.from(fileElement.querySelectorAll(".b3-list-item--focus")));
} }
}).element); }).element);
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element); window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);

View file

@ -10,7 +10,6 @@ import {genUUID} from "../../util/genID";
import {openMobileFileById} from "../editor"; import {openMobileFileById} from "../editor";
import {unicode2Emoji} from "../../emoji"; import {unicode2Emoji} from "../../emoji";
import {newNotebook} from "../../util/mount"; import {newNotebook} from "../../util/mount";
import {setEmpty} from "./setEmpty";
import {confirmDialog} from "../../dialog/confirmDialog"; import {confirmDialog} from "../../dialog/confirmDialog";
import {MenuItem} from "../../menus/Menu"; import {MenuItem} from "../../menus/Menu";
import {newFile} from "../../util/newFile"; import {newFile} from "../../util/newFile";
@ -525,7 +524,7 @@ export class MobileFiles extends Model {
targetElement.remove(); targetElement.remove();
} }
} }
}) });
} }
public onRename(data: { path: string, title: string, box: string }) { public onRename(data: { path: string, title: string, box: string }) {

View file

@ -22,7 +22,6 @@ import {updatePanelByEditor} from "../editor/util";
import {setPanelFocus} from "../layout/util"; import {setPanelFocus} from "../layout/util";
/// #endif /// #endif
import {Background} from "./header/Background"; import {Background} from "./header/Background";
import {getDisplayName} from "../util/pathName";
import {onGet} from "./util/onGet"; import {onGet} from "./util/onGet";
import {reloadProtyle} from "./util/reload"; import {reloadProtyle} from "./util/reload";
import {renderBacklink} from "./wysiwyg/renderBacklink"; import {renderBacklink} from "./wysiwyg/renderBacklink";

View file

@ -644,7 +644,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
&& targetElement && !protyle.options.backlinkData) { && targetElement && !protyle.options.backlinkData) {
// 文件树拖拽 // 文件树拖拽
const scrollTop = protyle.contentElement.scrollTop; const scrollTop = protyle.contentElement.scrollTop;
const ids = event.dataTransfer.getData(Constants.SIYUAN_DROP_FILE).split(",") const ids = event.dataTransfer.getData(Constants.SIYUAN_DROP_FILE).split(",");
for (let i = 0; i < ids.length; i++) { for (let i = 0; i < ids.length; i++) {
if (ids[i]) { if (ids[i]) {
const response = await fetchSyncPost("/api/filetree/doc2Heading", { const response = await fetchSyncPost("/api/filetree/doc2Heading", {

View file

@ -184,48 +184,48 @@ export const hasPreviousSibling = (element: Node) => {
}; };
export const getNextFileLi = (current: Element) => { export const getNextFileLi = (current: Element) => {
let nextElement = current.nextElementSibling let nextElement = current.nextElementSibling;
if (nextElement) { if (nextElement) {
if (nextElement.tagName === "LI") { if (nextElement.tagName === "LI") {
return nextElement return nextElement;
} else if (nextElement.tagName === "UL") { } else if (nextElement.tagName === "UL") {
return nextElement.firstElementChild return nextElement.firstElementChild;
} }
return false; return false;
} }
nextElement = current.parentElement nextElement = current.parentElement;
while (nextElement.tagName === "UL") { while (nextElement.tagName === "UL") {
if (!nextElement.nextElementSibling) { if (!nextElement.nextElementSibling) {
nextElement = nextElement.parentElement nextElement = nextElement.parentElement;
} else if (nextElement.nextElementSibling.tagName === "LI") { } else if (nextElement.nextElementSibling.tagName === "LI") {
return nextElement.nextElementSibling return nextElement.nextElementSibling;
} else if (nextElement.nextElementSibling.tagName === "UL") { } else if (nextElement.nextElementSibling.tagName === "UL") {
return nextElement.nextElementSibling.firstElementChild; return nextElement.nextElementSibling.firstElementChild;
} }
} }
return false; return false;
} };
export const getPreviousFileLi = (current: Element) => { export const getPreviousFileLi = (current: Element) => {
let previousElement = current.previousElementSibling let previousElement = current.previousElementSibling;
if (previousElement) { if (previousElement) {
if (previousElement.tagName === "LI") { if (previousElement.tagName === "LI") {
return previousElement return previousElement;
} else if (previousElement.tagName === "UL") { } else if (previousElement.tagName === "UL") {
return previousElement.lastElementChild return previousElement.lastElementChild;
} }
return false; return false;
} }
previousElement = current.parentElement previousElement = current.parentElement;
while (previousElement.tagName === "UL") { while (previousElement.tagName === "UL") {
if (!previousElement.previousElementSibling) { if (!previousElement.previousElementSibling) {
previousElement = previousElement.parentElement previousElement = previousElement.parentElement;
} else if (previousElement.previousElementSibling.tagName === "LI") { } else if (previousElement.previousElementSibling.tagName === "LI") {
return previousElement.previousElementSibling; return previousElement.previousElementSibling;
} else if (previousElement.previousElementSibling.tagName === "UL") { } else if (previousElement.previousElementSibling.tagName === "UL") {
const liElements = previousElement.previousElementSibling.querySelectorAll(".b3-list-item") const liElements = previousElement.previousElementSibling.querySelectorAll(".b3-list-item");
return liElements[liElements.length - 1]; return liElements[liElements.length - 1];
} }
} }
return false; return false;
} };

View file

@ -866,7 +866,7 @@ const fileTreeKeydown = (event: KeyboardEvent) => {
if (!files.element.parentElement.classList.contains("layout__tab--active")) { if (!files.element.parentElement.classList.contains("layout__tab--active")) {
return false; return false;
} }
const liElements = Array.from(files.element.querySelectorAll(".b3-list-item--focus")) const liElements = Array.from(files.element.querySelectorAll(".b3-list-item--focus"));
if (liElements.length === 0) { if (liElements.length === 0) {
if (event.key.startsWith("Arrow")) { if (event.key.startsWith("Arrow")) {
const liElement = files.element.querySelector(".b3-list-item"); const liElement = files.element.querySelector(".b3-list-item");
@ -1002,9 +1002,9 @@ const fileTreeKeydown = (event: KeyboardEvent) => {
files.getLeaf(liElements[0], notebookId); files.getLeaf(liElements[0], notebookId);
liElements.forEach((item, index) => { liElements.forEach((item, index) => {
if (index !== 0) { if (index !== 0) {
item.classList.remove("b3-list-item--focus") item.classList.remove("b3-list-item--focus");
} }
}) });
event.preventDefault(); event.preventDefault();
return true; return true;
} }
@ -1015,8 +1015,8 @@ const fileTreeKeydown = (event: KeyboardEvent) => {
parentElement = files.element.querySelector(".b3-list-item"); parentElement = files.element.querySelector(".b3-list-item");
} }
liElements.forEach((item) => { liElements.forEach((item) => {
item.classList.remove("b3-list-item--focus") item.classList.remove("b3-list-item--focus");
}) });
parentElement.classList.add("b3-list-item--focus"); parentElement.classList.add("b3-list-item--focus");
const parentRect = parentElement.getBoundingClientRect(); const parentRect = parentElement.getBoundingClientRect();
const fileRect = files.element.getBoundingClientRect(); const fileRect = files.element.getBoundingClientRect();
@ -1047,8 +1047,8 @@ const fileTreeKeydown = (event: KeyboardEvent) => {
} }
if (nextElement.classList.contains("b3-list-item")) { if (nextElement.classList.contains("b3-list-item")) {
liElements.forEach((item) => { liElements.forEach((item) => {
item.classList.remove("b3-list-item--focus") item.classList.remove("b3-list-item--focus");
}) });
nextElement.classList.add("b3-list-item--focus"); nextElement.classList.add("b3-list-item--focus");
const nextRect = nextElement.getBoundingClientRect(); const nextRect = nextElement.getBoundingClientRect();
const fileRect = files.element.getBoundingClientRect(); const fileRect = files.element.getBoundingClientRect();
@ -1080,8 +1080,8 @@ const fileTreeKeydown = (event: KeyboardEvent) => {
} }
if (previousElement.classList.contains("b3-list-item")) { if (previousElement.classList.contains("b3-list-item")) {
liElements.forEach((item) => { liElements.forEach((item) => {
item.classList.remove("b3-list-item--focus") item.classList.remove("b3-list-item--focus");
}) });
previousElement.classList.add("b3-list-item--focus"); previousElement.classList.add("b3-list-item--focus");
const previousRect = previousElement.getBoundingClientRect(); const previousRect = previousElement.getBoundingClientRect();
const fileRect = files.element.getBoundingClientRect(); const fileRect = files.element.getBoundingClientRect();
@ -1095,7 +1095,7 @@ const fileTreeKeydown = (event: KeyboardEvent) => {
} }
if (event.key === "Delete" || (event.key === "Backspace" && isMac())) { if (event.key === "Delete" || (event.key === "Backspace" && isMac())) {
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();
deleteFiles(liElements) deleteFiles(liElements);
return true; return true;
} }
if (event.key === "Enter") { if (event.key === "Enter") {
@ -1109,7 +1109,7 @@ const fileTreeKeydown = (event: KeyboardEvent) => {
files.getLeaf(item, itemTopULElement.getAttribute("data-url")); files.getLeaf(item, itemTopULElement.getAttribute("data-url"));
} }
} }
}) });
return true; return true;
} }
}; };

View file

@ -60,22 +60,22 @@ export const pathPosix = () => {
}; };
export const getTopPaths = (liElements:Element[]) => { export const getTopPaths = (liElements:Element[]) => {
const fromPaths:string[] = [] const fromPaths:string[] = [];
liElements.forEach((item: HTMLElement) => { liElements.forEach((item: HTMLElement) => {
if (item.getAttribute("data-type") !== "navigation-root") { if (item.getAttribute("data-type") !== "navigation-root") {
const dataPath = item.getAttribute("data-path") const dataPath = item.getAttribute("data-path");
const isChild = fromPaths.find(item => { const isChild = fromPaths.find(item => {
if (dataPath.startsWith(item.replace(".sy", ""))) { if (dataPath.startsWith(item.replace(".sy", ""))) {
return true; return true;
} }
}) });
if (!isChild) { if (!isChild) {
fromPaths.push(dataPath) fromPaths.push(dataPath);
} }
} }
}); });
return fromPaths return fromPaths;
} };
const moveToPath = (fromPaths: string[], toNotebook: string, toPath: string, dialog: Dialog) => { const moveToPath = (fromPaths: string[], toNotebook: string, toPath: string, dialog: Dialog) => {
fetchPost("/api/filetree/moveDocs", { fetchPost("/api/filetree/moveDocs", {