From a756ca2ddea53cf16ffccb9896c62edc29199951 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 5 Nov 2025 11:29:51 +0800 Subject: [PATCH] :bug: Image OCR may not work in some cases https://github.com/siyuan-note/siyuan/issues/16287 Signed-off-by: Daniel <845765@qq.com> --- kernel/util/ocr.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kernel/util/ocr.go b/kernel/util/ocr.go index 6dd817fff..ba01cc3f7 100644 --- a/kernel/util/ocr.go +++ b/kernel/util/ocr.go @@ -132,12 +132,11 @@ func SaveAssetsTexts() { } func SetAssetText(asset, text string) { - var oldText string assetsTextsLock.Lock() - oldText = assetsTexts[asset] + oldText, ok := assetsTexts[asset] assetsTexts[asset] = text assetsTextsLock.Unlock() - if oldText != text { + if !ok || oldText != text { assetsTextsChanged.Store(true) } } @@ -265,7 +264,7 @@ func Tesseract(imgAbsPath string) (ret []map[string]interface{}) { return } -// 提取并连接所有 text 字段的函数 +// GetOcrJsonText 提取并连接所有 text 字段的函数 func GetOcrJsonText(jsonData []map[string]interface{}) (ret string) { for _, dataMap := range jsonData { // 检查 text 字段是否存在