An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Clarify OCR icons and shorten image hover previews https://github.com/siyuan-note/siyuan/issues/20396
Daniel870fa5f9504f
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100744-br924ar.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100744-br924ar.syindex e4fa02e395..24ed8e79b2 100644--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100744-br924ar.sy+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100744-br924ar.sy@@ -6,7 +6,7 @@"id": "20200924100744-br924ar","title": "Assets","type": "doc",- "updated": "20261010133056"+ "updated": "20261010140118"},"Children": [{@@ -967,7 +967,7 @@"HeadingLevel": 2,"Properties": {"id": "20230117003636-epvk98g",- "updated": "20261006114009"+ "updated": "20261010140118"},"Children": [{@@ -1355,7 +1355,7 @@"HeadingLevel": 3,"Properties": {"id": "20230414202934-1h96or8",- "updated": "20261010133056"+ "updated": "20261010140118"},"Children": [{@@ -1482,7 +1482,7 @@"Type": "NodeParagraph","Properties": {"id": "20260930090802-3zn8sf9",- "updated": "20261010133056"+ "updated": "20261010140118"},"Children": [{@@ -1522,7 +1522,7 @@},{"Type": "NodeText",- "Data": " Hover over a local image to view its OCR text; an empty result is shown explicitly. The text selection icon identifies the OCR action, while the image icon copies the image as PNG, even when no OCR text is available. In a custom appearance profile, use "+ "Data": " Hover over a local image to view its OCR text; an empty result is shown explicitly. The text recognition icon identifies the OCR action, while the image icon copies the image as PNG, even when no OCR text is available. In a custom appearance profile, use "},{"Type": "NodeTextMark",@@ -1550,6 +1550,10 @@{"Type": "NodeText","Data": " to show or hide the image copy button; it is hidden in the Simple profile."+ },+ {+ "Type": "NodeText",+ "Data": " Long OCR text is shortened to at most 200 characters and six lines, followed by three dots. Double-click the OCR icon to view the full text."}]},diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200915214115-42b8zma.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200915214115-42b8zma.syindex 613d69513a..98ca96c8e0 100644--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200915214115-42b8zma.sy+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200915214115-42b8zma.sy@@ -6,7 +6,7 @@"id": "20200915214115-42b8zma","title": "资源文件","type": "doc",- "updated": "20261010133056"+ "updated": "20261010140118"},"Children": [{@@ -979,7 +979,7 @@"HeadingLevel": 2,"Properties": {"id": "20230117002036-vmc0mx4",- "updated": "20261006114009"+ "updated": "20261010140118"},"Children": [{@@ -1363,7 +1363,7 @@"HeadingLevel": 3,"Properties": {"id": "20230414202710-a51lo76",- "updated": "20261010133056"+ "updated": "20261010140118"},"Children": [{@@ -1490,7 +1490,7 @@"Type": "NodeParagraph","Properties": {"id": "20260930090802-qkecuzx",- "updated": "20261010133056"+ "updated": "20261010140118"},"Children": [{@@ -1530,7 +1530,7 @@},{"Type": "NodeText",- "Data": "悬浮在本地图片上可查看 OCR 文字,无识别结果时会显示空内容提示。文字选择图标表示 OCR 操作,图片图标则将图片复制为 PNG,无 OCR 文字时也可复制图片。在自定义外观方案中,可通过 "+ "Data": "悬浮在本地图片上可查看 OCR 文字,无识别结果时会显示空内容提示。文字识别图标表示 OCR 操作,图片图标则将图片复制为 PNG,无 OCR 文字时也可复制图片。在自定义外观方案中,可通过 "},{"Type": "NodeTextMark",@@ -1558,6 +1558,10 @@{"Type": "NodeText","Data": " 显示或隐藏图片复制按钮;该按钮在简洁方案中默认隐藏。"+ },+ {+ "Type": "NodeText",+ "Data": "OCR 悬浮预览最多显示 200 个字符、6 行,超出部分用三个点标记。双击 OCR 图标可查看完整文字。"}]},diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123038-4umgpxy.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123038-4umgpxy.syindex 2b0dc23442..a72271c136 100644--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123038-4umgpxy.sy+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123038-4umgpxy.sy@@ -6,7 +6,7 @@"id": "20211226123038-4umgpxy","title": "資料文件","type": "doc",- "updated": "20261010133056"+ "updated": "20261010140118"},"Children": [{@@ -965,7 +965,7 @@"HeadingLevel": 2,"Properties": {"id": "20230117003901-ze4mbzz",- "updated": "20261006114009"+ "updated": "20261010140118"},"Children": [{@@ -1349,7 +1349,7 @@"HeadingLevel": 3,"Properties": {"id": "20230414203058-foirrwk",- "updated": "20261010133056"+ "updated": "20261010140118"},"Children": [{@@ -1476,7 +1476,7 @@"Type": "NodeParagraph","Properties": {"id": "20260930090802-ffpq13r",- "updated": "20261010133056"+ "updated": "20261010140118"},"Children": [{@@ -1516,7 +1516,7 @@},{"Type": "NodeText",- "Data": "懸浮在本機圖片上可查看 OCR 文字,無辨識結果時會顯示空內容提示。文字選取圖示表示 OCR 操作,圖片圖示則將圖片複製為 PNG,無 OCR 文字時也可複製圖片。在自訂外觀方案中,可透過 "+ "Data": "懸浮在本機圖片上可查看 OCR 文字,無辨識結果時會顯示空內容提示。文字辨識圖示表示 OCR 操作,圖片圖示則將圖片複製為 PNG,無 OCR 文字時也可複製圖片。在自訂外觀方案中,可透過 "},{"Type": "NodeTextMark",@@ -1544,6 +1544,10 @@{"Type": "NodeText","Data": " 顯示或隱藏圖片複製按鈕;該按鈕在簡潔方案中預設隱藏。"+ },+ {+ "Type": "NodeText",+ "Data": "OCR 懸浮預覽最多顯示 200 個字元、6 行,超出部分以三個點標記。按兩下 OCR 圖示可查看完整文字。"}]},diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-1m5un7l.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-1m5un7l.syindex e2c19cbd40..7f4a8cee62 100644--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-1m5un7l.sy+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-1m5un7l.sy@@ -7,7 +7,7 @@"id": "20240530101000-1m5un7l","title": "アセット","type": "doc",- "updated": "20261010133056"+ "updated": "20261010140118"},"Children": [{@@ -1005,7 +1005,7 @@"Properties": {"ID": "20240530101000-5bix8t1","id": "20240530101000-9evyuhr",- "updated": "20261006114009"+ "updated": "20261010140118"},"Children": [{@@ -1398,7 +1398,7 @@"Properties": {"ID": "20240530101000-aefldsk","id": "20240530101000-cpod2qy",- "updated": "20261010133056"+ "updated": "20261010140118"},"Children": [{@@ -1540,7 +1540,7 @@"Type": "NodeParagraph","Properties": {"id": "20260930090802-fdfc9yh",- "updated": "20261010133056"+ "updated": "20261010140118"},"Children": [{@@ -1580,7 +1580,7 @@},{"Type": "NodeText",- "Data": " ローカル画像にマウスを合わせると OCR テキストを確認でき、認識結果が空の場合も表示されます。文字選択アイコンは OCR 操作を示し、画像アイコンは OCR テキストの有無にかかわらず画像を PNG としてコピーします。カスタム外観プロファイルでは "+ "Data": " ローカル画像にマウスを合わせると OCR テキストを確認でき、認識結果が空の場合も表示されます。文字認識アイコンは OCR 操作を示し、画像アイコンは OCR テキストの有無にかかわらず画像を PNG としてコピーします。カスタム外観プロファイルでは "},{"Type": "NodeTextMark",@@ -1608,6 +1608,10 @@{"Type": "NodeText","Data": " で画像コピーボタンの表示を切り替えられます。シンプルプロファイルでは既定で非表示です。"+ },+ {+ "Type": "NodeText",+ "Data": " OCR のホバープレビューは最大 200 文字、6 行まで表示され、長いテキストは末尾の 3 つのドットで省略を示します。OCR アイコンをダブルクリックすると全文を確認できます。"}]},diff --git a/app/src/asset/imageOCR.test.ts b/app/src/asset/imageOCR.test.tsindex a3bc31a0ab..dd07e6bf98 100644--- a/app/src/asset/imageOCR.test.ts+++ b/app/src/asset/imageOCR.test.ts@@ -99,7 +99,7 @@ const browserCases = async (source: string, actionsSource: string, statusSource:check.equal(requests, 1, "hover, focus, and pointer interactions reuse the status");check.equal(root.querySelectorAll(".protyle-action__ocr").length, 1);let action = root.querySelector<HTMLElement>(".protyle-action__ocr");- check.match(action.innerHTML, /#iconSelectText/);+ check.match(action.innerHTML, /#iconOCR/);action.click();await new Promise(resolve => setTimeout(resolve, 30));check.equal(copies, 1);diff --git a/app/src/block/popover.test.ts b/app/src/block/popover.test.tsindex 023e036b17..c129248151 100644--- a/app/src/block/popover.test.ts+++ b/app/src/block/popover.test.ts@@ -212,6 +212,34 @@ const browserCases = async (source: string) => {image.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));check.equal(assetRequests.length, 3);check.equal(ocrRequests.length, 3, "encrypted resources do not query OCR");+ image.setAttribute("data-src", "assets/long-ocr.png");+ image.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));+ const longText = "x".repeat(201);+ ocrRequests[3](longText);+ await Promise.resolve();+ check.ok(tooltip.endsWith("x".repeat(200) + "..."));+ check.equal(tooltip.includes(longText), false);+ image.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));+ ocrRequests[4]("1\r\n2\r3\n4\n5\n6\n7");+ await Promise.resolve();+ check.ok(tooltip.endsWith("1<br>2<br>3<br>4<br>5<br>6..."));+ image.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));+ ocrRequests[5]("😀".repeat(201));+ await Promise.resolve();+ check.ok(tooltip.endsWith("😀".repeat(200) + "..."), "truncation does not split surrogate pairs");+ image.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));+ ocrRequests[6]("<".repeat(201));+ await Promise.resolve();+ check.ok(tooltip.endsWith("<".repeat(200) + "..."), "truncation precedes HTML escaping");+ image.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));+ ocrRequests[7]("x".repeat(200));+ await Promise.resolve();+ check.ok(tooltip.endsWith("x".repeat(200)));+ check.equal(tooltip.endsWith("..."), false, "exact-length text remains complete");+ image.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));+ ocrRequests[8]("1\n2\n3\n4\n5\n6");+ await Promise.resolve();+ 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, "");return "Popover interaction cases passed";diff --git a/app/src/menus/declarations/imageOCRMenu.ts b/app/src/menus/declarations/imageOCRMenu.tsindex 6570e7c412..7fa945e1dc 100644--- a/app/src/menus/declarations/imageOCRMenu.ts+++ b/app/src/menus/declarations/imageOCRMenu.ts@@ -14,6 +14,7 @@ export interface IImageOCRMenuContext {export const IMAGE_OCR_MENU: IMenuDeclaration<IImageOCRMenuContext> = {id: "ocr",label: () => "OCR",+ icon: "iconOCR",simple: false,type: "entry",behavior: context => ({diff --git a/app/src/menus/declarations/menuDeclaration.test.ts b/app/src/menus/declarations/menuDeclaration.test.tsindex 230945336a..ff8bb46796 100644--- a/app/src/menus/declarations/menuDeclaration.test.ts+++ b/app/src/menus/declarations/menuDeclaration.test.ts@@ -30,6 +30,7 @@ test("OCR declarations drive catalog order, defaults and complete menu actions",openResult: () => { clicked.push("result"); }, copyText: () => { clicked.push("copy"); },runLocal: () => { clicked.push("local"); }, runAI: () => { clicked.push("ai"); },}));+ assert.equal(menu.icon, "iconOCR");assert.deepEqual(menu.submenu.map(item => [item.id, item.label, item.icon, item.type]), [["ocrResult", "ocrResult", "iconEdit", undefined], ["copyOCRText", "copy OCR", "iconCopy", undefined],["separator_reOCR", "", undefined, "separator"], ["reOCR", "performOCR", "iconOCR", undefined],diff --git a/app/src/protyle/render/imageActions.ts b/app/src/protyle/render/imageActions.tsindex 6381d175b4..febaee8e8c 100644--- a/app/src/protyle/render/imageActions.ts+++ b/app/src/protyle/render/imageActions.ts@@ -98,7 +98,7 @@ const addImageAction = (image: HTMLImageElement) => {action.setAttribute("role", "button");action.setAttribute("aria-label", window.siyuan.languages.imageOCRActionTip);action.setAttribute("data-position", "north");- action.innerHTML = '<svg><use xlink:href="#iconSelectText"></use></svg>';+ action.innerHTML = '<svg><use xlink:href="#iconOCR"></use></svg>';let timer: number;action.addEventListener("click", event => {event.stopPropagation();diff --git a/app/src/protyle/render/imageTooltip.ts b/app/src/protyle/render/imageTooltip.tsindex b33461146d..7af999e75a 100644--- a/app/src/protyle/render/imageTooltip.ts+++ b/app/src/protyle/render/imageTooltip.ts@@ -2,6 +2,24 @@ import {escapeHtml} from "../../util/escape";import {getAssetExtension, getAssetName} from "../../util/pathName";import {getImageTitle} from "./imageTitle";+const getOCRPreview = (text: string) => {+ const content = text.trim().replace(/\r\n|\r/g, "\n");+ let preview = "";+ let length = 0;+ let lines = 1;+ for (const character of content) {+ if (length === 200 || character === "\n" && lines === 6) {+ return preview.trimEnd() + "...";+ }+ preview += character;+ length++;+ if (character === "\n") {+ lines++;+ }+ }+ return preview;+};+export const getImageTooltip = (image: HTMLImageElement, size?: string, ocrText?: string) => {const source = image.getAttribute("data-src") || image.getAttribute("src") || "";const path = source.split(/[?#]/)[0];@@ -26,6 +44,6 @@ export const getImageTooltip = (image: HTMLImageElement, size?: string, ocrText?if (ocrText === undefined) {return tooltip;}- const ocr = escapeHtml(ocrText.trim() || window.siyuan.languages.emptyContent).replace(/\r\n|\r|\n/g, "<br>");+ 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;};