Skip to content

Commit

Permalink
🎨 #12914
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Nov 1, 2024
1 parent de0b3b8 commit 641550e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
29 changes: 23 additions & 6 deletions app/src/layout/dock/Files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import {mountHelp, newNotebook} from "../../util/mount";
import {confirmDialog} from "../../dialog/confirmDialog";
import {isNotCtrl, isOnlyMeta, setStorageVal, updateHotkeyTip} from "../../protyle/util/compatibility";
import {openFileById} from "../../editor/util";
import {hasClosestByAttribute, hasClosestByTag, hasTopClosestByTag} from "../../protyle/util/hasClosest";
import {
hasClosestByAttribute,
hasClosestByClassName,
hasClosestByTag,
hasTopClosestByTag
} from "../../protyle/util/hasClosest";
import {isTouchDevice} from "../../util/functions";
import {App} from "../../index";
import {refreshFileTree} from "../../dialog/processSystem";
Expand Down Expand Up @@ -938,20 +943,31 @@ export class Files extends Model {
if (!liElement) {
return;
}
let fileHTML = "";
data.files.forEach((item: IFile) => {
fileHTML += this.genFileHTML(item);
});
let nextElement = liElement.nextElementSibling;
if (nextElement && nextElement.tagName === "UL") {
// 文件展开时,刷新
// TODO nextElement.innerHTML = fileHTML;
const tempElement = document.createElement("template");
tempElement.innerHTML = fileHTML;
// 保持文件夹展开状态
nextElement.querySelectorAll(":scope > .b3-list-item > .b3-list-item__toggle> .b3-list-item__arrow--open").forEach(item => {
const openLiElement = hasClosestByClassName(item, "b3-list-item")
if (openLiElement) {
const tempOpenLiElement = tempElement.content.querySelector(`.b3-list-item[data-node-id="${openLiElement.getAttribute("data-node-id")}"]`)
tempOpenLiElement.after(openLiElement.nextElementSibling);
tempOpenLiElement.querySelector(".b3-list-item__arrow").classList.add("b3-list-item__arrow--open");
}
});
nextElement.innerHTML = tempElement.innerHTML;
if (typeof scrollTop === "number") {
this.element.scroll({top: scrollTop, behavior: "smooth"});
}
return;
}
liElement.querySelector(".b3-list-item__arrow").classList.add("b3-list-item__arrow--open");
let fileHTML = "";
data.files.forEach((item: IFile) => {
fileHTML += this.genFileHTML(item);
});
liElement.insertAdjacentHTML("afterend", `<ul class="file-tree__sliderDown">${fileHTML}</ul>`);
nextElement = liElement.nextElementSibling;
setTimeout(() => {
Expand Down Expand Up @@ -1204,3 +1220,4 @@ aria-label="${escapeHtml(ariaLabel)}">${getDisplayName(item.name, true, true)}</
return window.siyuan.menus.menu;
}
}

27 changes: 21 additions & 6 deletions app/src/mobile/dock/MobileFiles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {hasClosestByTag, hasTopClosestByTag} from "../../protyle/util/hasClosest";
import {hasClosestByClassName, hasClosestByTag, hasTopClosestByTag} from "../../protyle/util/hasClosest";
import {escapeHtml} from "../../util/escape";
import {Model} from "../../layout/Model";
import {Constants} from "../../constants";
Expand Down Expand Up @@ -528,18 +528,33 @@ export class MobileFiles extends Model {
}

private onLsHTML(data: { files: IFile[], box: string, path: string }) {
if (data.files.length === 0) {
return;
}
const liElement = this.element.querySelector(`ul[data-url="${data.box}"] li[data-path="${data.path}"]`);
if (!liElement) {
return;
}
let fileHTML = "";
data.files.forEach((item: IFile) => {
fileHTML += this.genFileHTML(item);
});
if (fileHTML === "") {
return;
}
const liElement = this.element.querySelector(`ul[data-url="${data.box}"] li[data-path="${data.path}"]`);
let nextElement = liElement.nextElementSibling;
if (nextElement && nextElement.tagName === "UL") {
// 文件展开时,刷新
nextElement.remove();
const tempElement = document.createElement("template");
tempElement.innerHTML = fileHTML;
// 保持文件夹展开状态
nextElement.querySelectorAll(":scope > .b3-list-item > .b3-list-item__toggle> .b3-list-item__arrow--open").forEach(item => {
const openLiElement = hasClosestByClassName(item, "b3-list-item")
if (openLiElement) {
const tempOpenLiElement = tempElement.content.querySelector(`.b3-list-item[data-node-id="${openLiElement.getAttribute("data-node-id")}"]`)
tempOpenLiElement.after(openLiElement.nextElementSibling);
tempOpenLiElement.querySelector(".b3-list-item__arrow").classList.add("b3-list-item__arrow--open");
}
});
nextElement.innerHTML = tempElement.innerHTML;
return;
}
liElement.querySelector(".b3-list-item__arrow").classList.add("b3-list-item__arrow--open");
liElement.insertAdjacentHTML("afterend", `<ul class="file-tree__sliderDown">${fileHTML}</ul>`);
Expand Down

0 comments on commit 641550e

Please sign in to comment.