Skip to content

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

:art: https://github.com/siyuan-note/siyuan/issues/11944

Vanessa7d3fd191de0f
diff --git a/app/src/protyle/preview/index.ts b/app/src/protyle/preview/index.ts
index a70f0dd049..d810624e6c 100644
--- a/app/src/protyle/preview/index.ts
+++ b/app/src/protyle/preview/index.ts
@@ -135,7 +135,7 @@ export class Preview {
this.copyToX(tempElement, protyle, type);
} else if (type === "desktop") {
previewElement.style.width = "";
- previewElement.style.padding = protyle.wysiwyg.element.style.padding;
+ this.updatePadding(getPadding(protyle));
} else if (type === "tablet") {
previewElement.style.width = "1024px";
previewElement.style.padding = "8px 16px";
@@ -183,14 +183,18 @@ export class Preview {
this.previewElement = previewElement;
}
+ public updatePadding(padding: { left: number, right: number, bottom: number, top: number }) {
+ if (this.element.style.display !== "none" &&
+ this.element.querySelector('.protyle-preview__action [data-type="desktop"]')?.classList.contains("protyle-preview__action--current")) {
+ this.previewElement.style.padding = `${padding.top}px ${padding.left}px ${padding.bottom}px ${padding.right}px`;
+ }
+ }
+
public render(protyle: IProtyle) {
if (this.element.style.display === "none") {
return;
}
- if (this.element.querySelector('.protyle-preview__action [data-type="desktop"]')?.classList.contains("protyle-preview__action--current")) {
- const padding = getPadding(protyle);
- this.previewElement.style.padding = `${padding.top}px ${padding.left}px ${padding.bottom}px ${padding.right}px`;
- }
+ this.updatePadding(getPadding(protyle));
let loadingElement = this.element.querySelector(".fn__loading");
if (!loadingElement) {
diff --git a/app/src/protyle/scroll/index.ts b/app/src/protyle/scroll/index.ts
index ced30af69b..42d9d28e0f 100644
--- a/app/src/protyle/scroll/index.ts
+++ b/app/src/protyle/scroll/index.ts
@@ -16,11 +16,11 @@ export class Scroll {
constructor(protyle: IProtyle) {
this.parentElement = document.createElement("div");
- this.parentElement.classList.add("protyle-scroll");
+ this.parentElement.classList.add("protyle-scroll", "fn__none");
this.parentElement.innerHTML = `<div class="protyle-scroll__up ariaLabel" data-position="north" aria-label="${updateHotkeyTip("⌘Home")}">
<svg><use xlink:href="#iconUp"></use></svg>
</div>
-<div class="fn__none protyle-scroll__bar ariaLabel" data-position="2west" aria-label="Blocks 1/1">
+<div class="protyle-scroll__bar ariaLabel" data-position="2west" aria-label="Blocks 1/1">
<input class="b3-slider" type="range" max="1" min="1" step="1" value="1" />
</div>
<div class="protyle-scroll__down ariaLabel" aria-label="${updateHotkeyTip("⌘End")}">
@@ -29,9 +29,6 @@ export class Scroll {
this.element = this.parentElement.querySelector(".protyle-scroll__bar");
this.keepLazyLoad = false;
- if (!protyle.options.render.scroll) {
- this.parentElement.classList.add("fn__none");
- }
this.lastScrollTop = 0;
this.inputElement = this.element.firstElementChild as HTMLInputElement;
this.inputElement.addEventListener("input", () => {
@@ -112,14 +109,8 @@ export class Scroll {
this.inputElement.setAttribute("max", protyle.block.blockCount.toString());
this.element.setAttribute("aria-label", `Blocks ${this.inputElement.value}/${protyle.block.blockCount}`);
}
- if (protyle.block.showAll) {
- this.element.classList.add("fn__none");
- } else {
- if (protyle.block.scroll && !protyle.contentElement.classList.contains("fn__none")) {
- this.element.classList.remove("fn__none");
- } else {
- this.element.classList.add("fn__none");
- }
- }
+ const visible = protyle.options.render.scroll && !protyle.block.showAll && protyle.block.scroll &&
+ !protyle.contentElement.classList.contains("fn__none");
+ this.parentElement.classList.toggle("fn__none", !visible);
}
}
diff --git a/app/src/protyle/ui/initUI.ts b/app/src/protyle/ui/initUI.ts
index 910a188681..680f9d5f19 100644
--- a/app/src/protyle/ui/initUI.ts
+++ b/app/src/protyle/ui/initUI.ts
@@ -337,6 +337,7 @@ export const setPadding = (protyle: IProtyle) => {
};
}
const padding = getPadding(protyle);
+ protyle.preview.updatePadding(padding);
const paddingLeft = protyle.options.backlinkData ? 24 : padding.left;
const paddingRight = protyle.options.backlinkData ? 16 : padding.right;
const backlinkBottomElement = protyle.contentElement.querySelector(".sy__backlink--bottom") as HTMLElement;
@@ -382,7 +383,7 @@ export const getPadding = (protyle: IProtyle) => {
let right = 16;
let left = 24;
let bottom = 16;
- if (protyle.options.typewriterMode) {
+ if (protyle.options.typewriterMode && protyle.preview.element.classList.contains("fn__none")) {
bottom = protyle.element.clientHeight / 2;
}
if (!isMobile()) {
diff --git a/app/src/protyle/util/setEditMode.ts b/app/src/protyle/util/setEditMode.ts
index ad4792a7c1..edde9f9ccc 100644
--- a/app/src/protyle/util/setEditMode.ts
+++ b/app/src/protyle/util/setEditMode.ts
@@ -10,7 +10,7 @@ export const setEditMode = (protyle: IProtyle, type: TEditorMode) => {
}
protyle.preview.element.classList.remove("fn__none");
protyle.contentElement.classList.add("fn__none");
- protyle.scroll?.element.classList.add("fn__none");
+ protyle.scroll?.update(protyle);
if (protyle.options.render.breadcrumb) {
protyle.breadcrumb?.element.classList.add("fn__none");
protyle.breadcrumb.toggleExit(true);
@@ -25,9 +25,7 @@ export const setEditMode = (protyle: IProtyle, type: TEditorMode) => {
}
protyle.preview.element.classList.add("fn__none");
protyle.contentElement.classList.remove("fn__none");
- if (protyle.options.render.scroll) {
- protyle.scroll?.element.classList.remove("fn__none");
- }
+ protyle.scroll?.update(protyle);
if (protyle.options.render.breadcrumb) {
protyle.breadcrumb?.element.classList.remove("fn__none");
protyle.breadcrumb.toggleExit(!protyle.block.showAll);