Skip to content

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

:art: Omit empty OCR sections and simplify tooltip separators https://github.com/siyuan-note/siyuan/issues/20516

Danield216e7a197c6
diff --git a/app/src/block/popover.test.ts b/app/src/block/popover.test.ts
index c129248151..748e9462fa 100644
--- a/app/src/block/popover.test.ts
+++ b/app/src/block/popover.test.ts
@@ -63,7 +63,7 @@ const browserCases = async (source: string) => {
config: {editor: {floatWindowMode: 0, floatWindowDelay: 20}},
menus: {menu: {element: document.createElement("div")}},
blockPanels: [],
- languages: {ocrResult: "OCR text", emptyContent: "No related content found"},
+ languages: {ocrResult: "OCR text", emptyContent: "No related content found", modifiedAt: "Modified", createdAt: "Created"},
} as unknown as typeof window.siyuan;
window.JSAndroid = {} as typeof window.JSAndroid;
const root = document.createElement("div");
@@ -180,7 +180,7 @@ const browserCases = async (source: string) => {
Object.defineProperties(image, {naturalWidth: {value: 1920}, naturalHeight: {value: 1080}});
image.style.width = "100px";
image.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));
- check.equal(tooltip, 'photo &lt;name>.png<div class="fn__hr"></div>PNG · 1920 × 1080');
+ check.equal(tooltip, "photo &lt;name>.png<br>PNG · 1920 × 1080");
check.equal(assetRequests.length, 1);
assetRequests[0].receive({code: 0, data: {hSize: "2 MiB"}});
check.match(tooltip, /PNG · 1920 × 1080 · 2 MiB$/);
@@ -202,7 +202,7 @@ const browserCases = async (source: string) => {
check.equal(tooltip, unavailable);
ocrRequests[2](" \n ");
await Promise.resolve();
- check.match(tooltip, /OCR text:<br>No related content found$/);
+ check.equal(tooltip, unavailable, "empty OCR leaves only the existing image information");
image.setAttribute("data-src", "https://example.com/photo.webp");
image.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));
check.match(tooltip, /photo.webp.*WEBP · 1920 × 1080/);
@@ -242,6 +242,27 @@ const browserCases = async (source: string) => {
check.ok(tooltip.endsWith("1<br>2<br>3<br>4<br>5<br>6"), "six complete lines remain unchanged");
check.equal(image.title, "");
check.equal(image.alt, "");
+ const link = document.createElement("span");
+ link.setAttribute("data-type", "a");
+ link.setAttribute("data-href", "https://example.com/file.pdf");
+ link.setAttribute("data-title", "Link title");
+ document.body.append(link);
+ link.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));
+ check.equal(tooltip, '<span style="word-break: break-all">https://example.com/file.pdf</span><br><span>Link title</span>');
+ link.setAttribute("data-href", "assets/file.pdf");
+ link.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));
+ assetRequests.at(-1).receive({code: 0, data: {hSize: "1 KiB", hUpdated: "Updated", hCreated: "Created"}});
+ check.equal(tooltip, '<span style="word-break: break-all">assets/file.pdf</span> 1 KiB<br><span>Link title</span><br>Modified Updated<br>Created Created');
+ link.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));
+ assetRequests.at(-1).receive({code: 1});
+ check.equal(tooltip, '<span style="word-break: break-all">assets/file.pdf</span><br><span>Link title</span>');
+ const url = document.createElement("span");
+ url.className = "av__celltext--url ariaLabel";
+ url.setAttribute("aria-label", "https://example.com/");
+ url.setAttribute("data-name", "Column title");
+ document.body.append(url);
+ url.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));
+ check.equal(tooltip, '<span style="word-break: break-all">https://example.com/</span><br><span>Column title</span>');
return "Popover interaction cases passed";
};
diff --git a/app/src/block/popover.ts b/app/src/block/popover.ts
index 5575b26b74..073af7425f 100644
--- a/app/src/block/popover.ts
+++ b/app/src/block/popover.ts
@@ -260,7 +260,7 @@ export const initBlockPopover = (app: App) => {
}
} else if (aElement.classList.contains("av__celltext--url")) {
const title = aElement.getAttribute("data-name") || "";
- tip = tip ? `<span style="word-break: break-all">${tip.substring(0, Constants.SIZE_TITLE)}</span>${title ? '<div class="fn__hr"></div><span>' + title + "</span>" : ""}` : title;
+ tip = tip ? `<span style="word-break: break-all">${tip.substring(0, Constants.SIZE_TITLE)}</span>${title ? "<br><span>" + title + "</span>" : ""}` : title;
tooltipClass = "href";
} else if (aElement.classList.contains("av__calc--ashow") && aElement.clientWidth + 2 < aElement.scrollWidth) {
tip = aElement.lastChild.textContent + " " + aElement.firstElementChild.textContent;
@@ -305,10 +305,10 @@ export const initBlockPopover = (app: App) => {
}
if (response.code === 1) {
if (title) {
- assetTip += '<div class="fn__hr"></div><span>' + title + "</span>";
+ assetTip += "<br><span>" + title + "</span>";
}
} else {
- assetTip += ` ${response.data.hSize}${title ? '<div class="fn__hr"></div><span>' + title + "</span>" : ""}<br>${window.siyuan.languages.modifiedAt} ${response.data.hUpdated}<br>${window.siyuan.languages.createdAt} ${response.data.hCreated}`;
+ assetTip += ` ${response.data.hSize}${title ? "<br><span>" + title + "</span>" : ""}<br>${window.siyuan.languages.modifiedAt} ${response.data.hUpdated}<br>${window.siyuan.languages.createdAt} ${response.data.hCreated}`;
}
try {
showTooltip(decodeURIComponent(assetTip), aElement, tooltipClass, event, tooltipSpace);
@@ -321,7 +321,7 @@ export const initBlockPopover = (app: App) => {
}, undefined, undefined, signal);
tip = "";
} else if (title) {
- tip = (tip ? (tip + '<div class="fn__hr"></div>') : "") + "<span>" + title + "</span>";
+ tip = (tip ? (tip + "<br>") : "") + "<span>" + title + "</span>";
}
}
diff --git a/app/src/protyle/render/imageTooltip.ts b/app/src/protyle/render/imageTooltip.ts
index 7af999e75a..bf21948b43 100644
--- a/app/src/protyle/render/imageTooltip.ts
+++ b/app/src/protyle/render/imageTooltip.ts
@@ -40,10 +40,11 @@ export const getImageTooltip = (image: HTMLImageElement, size?: string, ocrText?
// 原始尺寸不受编辑器缩放和图片排版宽度影响。
const dimensions = image.naturalWidth && image.naturalHeight ? `${image.naturalWidth} × ${image.naturalHeight}` : "";
const information = [format, dimensions, size].filter(Boolean).map(value => escapeHtml(value)).join(" · ");
- const tooltip = text + (text && information ? '<div class="fn__hr"></div>' : "") + information;
- if (ocrText === undefined) {
+ const tooltip = text + (text && information ? "<br>" : "") + information;
+ const preview = ocrText === undefined ? "" : getOCRPreview(ocrText);
+ if (!preview) {
return tooltip;
}
- const ocr = escapeHtml(getOCRPreview(ocrText) || window.siyuan.languages.emptyContent).replace(/\n/g, "<br>");
- return tooltip + '<div class="fn__hr"></div>' + escapeHtml(window.siyuan.languages.ocrResult) + ":<br>" + ocr;
+ const ocr = escapeHtml(preview).replace(/\n/g, "<br>");
+ return (tooltip ? tooltip + "<br>" : "") + escapeHtml(window.siyuan.languages.ocrResult) + ":<br>" + ocr;
};