Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Prevent document tree animation overlap https://github.com/siyuan-note/siyuan/issues/18700

Daniel87229b921379
diff --git a/app/src/layout/dock/fileTreeAnimation.test.ts b/app/src/layout/dock/fileTreeAnimation.test.ts
index fee18ed090..2752cbae82 100644
--- a/app/src/layout/dock/fileTreeAnimation.test.ts
+++ b/app/src/layout/dock/fileTreeAnimation.test.ts
@@ -63,9 +63,12 @@ const createTreeElements = (expanded = true) => {
let arrowOpen = expanded;
const style = {
overflow: "",
+ position: "",
removeProperty(property: string) {
if (property === "overflow") {
this.overflow = "";
+ } else if (property === "position") {
+ this.position = "";
}
return "";
},
@@ -112,7 +115,7 @@ const createTreeElements = (expanded = true) => {
};
describe("fileTreeAnimation", () => {
- it("expands to the actual content height and restores overflow", async () => {
+ it("expands to the actual content height and restores animation styles", async () => {
const tree = createTreeElements();
let finished = false;
expandFileTree(tree.leafElement, () => {
@@ -122,14 +125,30 @@ describe("fileTreeAnimation", () => {
assert.deepEqual(tree.getFrames(), [{height: "0"}, {height: "96px"}]);
assert.equal(tree.getOptions().duration, 200);
assert.equal(tree.leafElement.style.overflow, "clip");
+ assert.equal(tree.leafElement.style.position, "relative");
tree.animation.finish();
await tree.animation.animation.finished;
assert.equal(tree.animation.isCanceled(), true);
assert.equal(tree.leafElement.style.overflow, "");
+ assert.equal(tree.leafElement.style.position, "");
assert.equal(finished, true);
});
+ it("restores animation styles if expansion fails", async () => {
+ const tree = createTreeElements();
+ let finished = false;
+ expandFileTree(tree.leafElement, () => {
+ finished = true;
+ });
+
+ tree.animation.fail(new Error("Animation failed"));
+ await assert.rejects(tree.animation.animation.finished);
+ assert.equal(tree.leafElement.style.overflow, "");
+ assert.equal(tree.leafElement.style.position, "");
+ assert.equal(finished, false);
+ });
+
it("uses no duration when reduced motion is requested", async () => {
reduceMotion = true;
const tree = createTreeElements();
@@ -149,6 +168,7 @@ describe("fileTreeAnimation", () => {
assert.equal(isFileTreeCollapsing(tree.liElement), true);
assert.deepEqual(tree.getFrames(), [{height: "96px"}, {height: "0"}]);
assert.equal(tree.leafElement.style.overflow, "clip");
+ assert.equal(tree.leafElement.style.position, "relative");
tree.animation.finish();
await tree.animation.animation.finished;
diff --git a/app/src/layout/dock/fileTreeAnimation.ts b/app/src/layout/dock/fileTreeAnimation.ts
index af30239a40..3ea8405232 100644
--- a/app/src/layout/dock/fileTreeAnimation.ts
+++ b/app/src/layout/dock/fileTreeAnimation.ts
@@ -8,8 +8,18 @@ const getAnimationOptions = (): KeyframeAnimationOptions => ({
fill: "both",
});
-export const expandFileTree = (element: HTMLElement, onFinish?: () => void) => {
+const setAnimationStyles = (element: HTMLElement) => {
element.style.overflow = "clip";
+ element.style.position = "relative";
+};
+
+const clearAnimationStyles = (element: HTMLElement) => {
+ element.style.removeProperty("overflow");
+ element.style.removeProperty("position");
+};
+
+export const expandFileTree = (element: HTMLElement, onFinish?: () => void) => {
+ setAnimationStyles(element);
const animation = element.animate([
{height: "0"},
{height: `${element.scrollHeight}px`},
@@ -19,11 +29,11 @@ export const expandFileTree = (element: HTMLElement, onFinish?: () => void) => {
if (!element.isConnected) {
return;
}
- element.style.removeProperty("overflow");
+ clearAnimationStyles(element);
onFinish?.();
}, () => {
if (element.isConnected) {
- element.style.removeProperty("overflow");
+ clearAnimationStyles(element);
}
});
};
@@ -61,7 +71,7 @@ export const collapseFileTree = (liElement: Element, onFinish: () => void) => {
return;
}
- leafElement.style.overflow = "clip";
+ setAnimationStyles(leafElement);
const animation = leafElement.animate([
{height: `${leafElement.scrollHeight}px`},
{height: "0"},