Skip to content

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

:bug: Keep RTL list gutters outside content https://github.com/siyuan-note/siyuan/issues/19007

Daniela15bb4bece80
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index 375e1b35c0..258f6c4dd4 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -114,7 +114,8 @@ import {
getBacklinkGutterContentTop,
getContainerGutterSpace,
getFixedGutterPosition,
- getGutterMarginHeight
+ getGutterMarginHeight,
+ getListGutterAnchorLeft
} from "./layout";
import {closeSubElement} from "../toolbar/subElementLifecycle";
import {canShowGutterInsert, genGutterBlockButtonHTML} from "./button";
@@ -3766,16 +3767,25 @@ data-type="fold"${viewOccurrenceID ? ` data-view-occurrence-id="${encodeURICompo
}
let rect = element.getBoundingClientRect();
let marginHeight = 0;
- if (listItem && !window.siyuan.config.editor.rtl && getComputedStyle(element).direction !== "rtl") {
+ const isRTL = window.siyuan.config.editor.rtl || getComputedStyle(element).direction === "rtl";
+ if (listItem && !isRTL) {
rect = listItem.firstElementChild.getBoundingClientRect();
space = 0;
} else if (nodeElement.getAttribute("data-type") === "NodeBlockQueryEmbed") {
rect = nodeElement.getBoundingClientRect();
space = 0;
}
+ let horizontalAnchorLeft = rect.left;
+ if (listItem && element.classList.contains("protyle-action") &&
+ element.parentElement.getAttribute("data-type") === "NodeListItem") {
+ const listItemElement = element.parentElement;
+ const contentElement = listItemElement.querySelector<HTMLElement>(":scope > [data-node-id]");
+ const contentLeft = (contentElement || listItemElement).getBoundingClientRect().left;
+ horizontalAnchorLeft = getListGutterAnchorLeft(rect.left, contentLeft, isRTL);
+ }
const buttonCount = html.split("</button>").length - 1;
const getNaturalLeft = (width: number) => {
- let left = rect.left - width - space;
+ let left = horizontalAnchorLeft - width - space;
if (nodeElement.getAttribute("data-type") === "NodeBlockQueryEmbed" && buttonCount === 1) {
// 嵌入块为列表时
left = nodeElement.getBoundingClientRect().left - width - space;
@@ -3834,7 +3844,8 @@ data-type="fold"${viewOccurrenceID ? ` data-view-occurrence-id="${encodeURICompo
const top = Math.max(rect.top + marginHeight, contentTop, foldElement ? foldElement.getBoundingClientRect().top : 0);
this.element.style.top = `${getFixedGutterPosition(top, fixedContainerRect?.top)}px`;
// 压缩模式需加 2,否则和折叠标题无法对齐
- const left = compressed ? rect.left - this.element.clientWidth - space / 2 + 3 : getNaturalLeft(this.element.clientWidth);
+ const left = compressed ? horizontalAnchorLeft - this.element.clientWidth - space / 2 + 3 :
+ getNaturalLeft(this.element.clientWidth);
this.element.style.left = `${getFixedGutterPosition(left, fixedContainerRect?.left)}px`;
}
}
diff --git a/app/src/protyle/gutter/layout.test.ts b/app/src/protyle/gutter/layout.test.ts
index fca0416754..2182f5fccc 100644
--- a/app/src/protyle/gutter/layout.test.ts
+++ b/app/src/protyle/gutter/layout.test.ts
@@ -4,7 +4,8 @@ import {
getBacklinkGutterContentTop,
getContainerGutterSpace,
getFixedGutterPosition,
- getGutterMarginHeight
+ getGutterMarginHeight,
+ getListGutterAnchorLeft
} from "./layout";
describe("getGutterMarginHeight", () => {
@@ -60,3 +61,13 @@ describe("getContainerGutterSpace", () => {
assert.equal(getContainerGutterSpace("NodeParagraph", false), 0);
});
});
+
+describe("getListGutterAnchorLeft", () => {
+ it("uses the content edge for RTL list actions", () => {
+ assert.equal(getListGutterAnchorLeft(680, 120, true), 120);
+ });
+
+ it("keeps the list action edge for LTR lists", () => {
+ assert.equal(getListGutterAnchorLeft(120, 154, false), 120);
+ });
+});
diff --git a/app/src/protyle/gutter/layout.ts b/app/src/protyle/gutter/layout.ts
index 128396cde9..1e908047e6 100644
--- a/app/src/protyle/gutter/layout.ts
+++ b/app/src/protyle/gutter/layout.ts
@@ -17,3 +17,6 @@ export const getFixedGutterPosition = (viewportPosition: number, fixedContainerP
export const getContainerGutterSpace = (type: string, usesContainerRect: boolean) =>
!usesContainerRect && ["NodeBlockquote", "NodeCallout"].includes(type) ? 10 : 0;
+
+export const getListGutterAnchorLeft = (actionLeft: number, contentLeft: number, rtl: boolean) =>
+ rtl ? contentLeft : actionLeft;