Skip to content

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

:bug: Refine database rich-text previews and toolbar https://github.com/siyuan-note/siyuan/issues/11553

Danielf5ae24316727
diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scss
index 03981f1c0b..d6b90a0b0f 100644
--- a/app/src/assets/scss/business/_av.scss
+++ b/app/src/assets/scss/business/_av.scss
@@ -1117,37 +1117,38 @@
&--rich {
width: 100%;
- max-height: 8.125em;
+ max-height: 1.625em;
overflow: hidden;
- white-space: normal;
+ white-space: nowrap;
+ text-overflow: ellipsis;
font: inherit;
- > p,
- > h1,
- > h2,
- > h3,
- > h4,
- > h5,
- > h6,
- > blockquote,
- > ul,
- > ol,
- > .code-block,
- > .language-math {
- margin: 0;
- }
-
- li > p,
- > p,
- blockquote > p {
+ p,
+ h1,
+ h2,
+ h3,
+ h4,
+ h5,
+ h6,
+ blockquote,
+ ul,
+ ol,
+ li,
+ pre,
+ .render-node {
+ display: inline;
min-height: 0;
- padding: 0;
margin: 0;
+ padding: 0;
line-height: inherit;
+ list-style: none;
}
- > :not(:first-child) {
- margin-top: 4px;
+ > :not(:first-child),
+ li + li,
+ li > :not(:first-child),
+ blockquote > :not(:first-child) {
+ margin-left: .5em;
}
}
@@ -1177,10 +1178,6 @@
}
}
- &__cell[data-wrap="false"] > &__celltext--rich {
- max-height: 1.625em;
- }
-
&__checkbox {
color: var(--b3-theme-on-surface);
height: 1.625em;
diff --git a/app/src/block/popover.ts b/app/src/block/popover.ts
index 6854fa59db..7adff8d024 100644
--- a/app/src/block/popover.ts
+++ b/app/src/block/popover.ts
@@ -6,6 +6,10 @@ import {isEncryptedBox, isLocalPath, parseSiYuanUriInfo} from "../util/pathName"
import type {App} from "../index";
import {Constants} from "../constants";
import {getCellText} from "../protyle/render/av/cell";
+import {
+ hasAVCellContentOverflow,
+ shouldMeasureAVCellContentOverflow,
+} from "../protyle/render/av/cellOverflow";
import {isTouchDevice} from "../util/functions";
import {escapeAriaLabel, escapeHtml, escapeLessThans} from "../util/escape";
import {isListItemActionElement} from "../protyle/wysiwyg/listContext";
@@ -108,9 +112,12 @@ export const initBlockPopover = (app: App) => {
}
}
tip = "";
- if (!tip && aElement.dataset.wrap !== "true" && event.target.dataset.type !== "block-more" && !hasClosestByClassName(event.target, "block__icon")) {
+ const richTextElement = aElement.querySelector<HTMLElement>(".av__celltext--rich");
+ if (!tip && shouldMeasureAVCellContentOverflow(aElement.dataset.wrap, Boolean(richTextElement)) &&
+ event.target.dataset.type !== "block-more" &&
+ !hasClosestByClassName(event.target, "block__icon")) {
aElement.style.overflow = "auto";
- if (aElement.scrollWidth > aElement.clientWidth + 2) {
+ if (hasAVCellContentOverflow(aElement, richTextElement)) {
tip = Lute.EscapeHTMLStr(getCellText(aElement));
}
aElement.style.overflow = "";
diff --git a/app/src/protyle/render/av/cellOverflow.test.ts b/app/src/protyle/render/av/cellOverflow.test.ts
new file mode 100644
index 0000000000..862f837cd0
--- /dev/null
+++ b/app/src/protyle/render/av/cellOverflow.test.ts
@@ -0,0 +1,36 @@
+import * as assert from "node:assert/strict";
+import {describe, it} from "node:test";
+import {
+ AVCellOverflowMetrics,
+ hasAVCellContentOverflow,
+ shouldMeasureAVCellContentOverflow,
+} from "./cellOverflow";
+
+const metrics = (clientWidth: number, scrollWidth: number,
+ clientHeight = 24, scrollHeight = clientHeight): AVCellOverflowMetrics => ({
+ clientHeight,
+ clientWidth,
+ scrollHeight,
+ scrollWidth,
+});
+
+describe("attribute view cell overflow", () => {
+ it("detects regular horizontal overflow", () => {
+ assert.equal(hasAVCellContentOverflow(metrics(100, 103)), true);
+ assert.equal(hasAVCellContentOverflow(metrics(100, 102)), false);
+ });
+
+ it("detects overflow clipped inside a rich-text preview", () => {
+ const cell = metrics(100, 100);
+
+ assert.equal(hasAVCellContentOverflow(cell, metrics(100, 101)), true);
+ assert.equal(hasAVCellContentOverflow(cell, metrics(100, 100, 24, 25)), true);
+ assert.equal(hasAVCellContentOverflow(cell, metrics(100, 100, 24, 24)), false);
+ });
+
+ it("measures wrapped cells only when their rich-text preview remains clipped", () => {
+ assert.equal(shouldMeasureAVCellContentOverflow("true", false), false);
+ assert.equal(shouldMeasureAVCellContentOverflow("true", true), true);
+ assert.equal(shouldMeasureAVCellContentOverflow("false", false), true);
+ });
+});
diff --git a/app/src/protyle/render/av/cellOverflow.ts b/app/src/protyle/render/av/cellOverflow.ts
new file mode 100644
index 0000000000..d68a6001d8
--- /dev/null
+++ b/app/src/protyle/render/av/cellOverflow.ts
@@ -0,0 +1,15 @@
+export interface AVCellOverflowMetrics {
+ clientHeight: number;
+ clientWidth: number;
+ scrollHeight: number;
+ scrollWidth: number;
+}
+
+export const hasAVCellContentOverflow = (cell: AVCellOverflowMetrics,
+ richText?: AVCellOverflowMetrics | null) =>
+ cell.scrollWidth > cell.clientWidth + 2 || Boolean(richText &&
+ (richText.scrollWidth > richText.clientWidth + 0.5 ||
+ richText.scrollHeight > richText.clientHeight + 0.5));
+
+export const shouldMeasureAVCellContentOverflow = (wrap: string | undefined, richText: boolean) =>
+ wrap !== "true" || richText;
diff --git a/app/src/protyle/render/av/richTextEditor.ts b/app/src/protyle/render/av/richTextEditor.ts
index 4193644eb3..91f1647527 100644
--- a/app/src/protyle/render/av/richTextEditor.ts
+++ b/app/src/protyle/render/av/richTextEditor.ts
@@ -3,6 +3,7 @@ import {isMobile} from "../../../util/functions";
import {callMobileAppShowKeyboard} from "../../../mobile/util/mobileAppUtil";
import {hintRef, hintSlash} from "../../hint/extend";
import {mountProtyleLiteFragment} from "../../lite/fragmentEditor";
+import {getDefaultToolbar} from "../../toolbar/defaults";
import {highlightRender} from "../highlightRender";
import {mathRender} from "../mathRender";
import {positionAVRichTextEditor} from "./richTextEditorPosition";
@@ -110,10 +111,7 @@ export const openAVRichTextEditor = (options: AVRichTextEditorOptions) => {
setPanelPosition(panelElement, options.anchorElement);
const source = getAVTextSource(options.value);
- const toolbar: IProtyleOptions["toolbar"] = [
- "block-ref", "a", "|", "text", "strong", "em", "u", "s", "mark", "sup", "sub",
- "code", "kbd", "tag", "inline-math", "inline-memo", "clear",
- ];
+ const toolbar = getDefaultToolbar(isMobile());
const hint: IProtyleOptions["hint"] = {
extend: [{key: "((", hint: hintAVRef}, {key: "【【", hint: hintAVRef},
{key: "((", hint: hintAVRef}, {key: "[[", hint: hintAVRef},