From 36c0dc3ca0a2674cea95336876ba4d1294a450f6 Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Sun, 11 Oct 2026 11:42:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=8E=8B=E7=BC=A9=E6=80=A7=E8=83=BD):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=9A=E6=96=87=E6=A1=A3=E5=8E=8B=E7=BC=A9?= =?UTF-8?q?=E5=86=85=E5=AD=98=E4=B8=8E=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdgo_editor_resource_scope.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ofdgo_editor_resource_scope.go b/ofdgo_editor_resource_scope.go index 690c2ad..0079e02 100644 --- a/ofdgo_editor_resource_scope.go +++ b/ofdgo_editor_resource_scope.go @@ -20,7 +20,7 @@ import ( "slices" ) -// resourceReferenceScopes 按文档归集资源标识和字体用字,共享资源索引合并所属文档的引用 +// resourceReferenceScopes 按文档归集资源标识和字体用字,同文档索引共用只读结果,跨文档索引独立合并 // 入参: ctx 取消上下文, parts 输出改动, generated 自产页面引用, documents 文档入口, resources 资源索引, references 文件引用, selected 限定的文档入口,空值统计全部文档 // 返回: map[string]*editorResourceRefs 各资源索引的引用,存在无法归属的引用时为空, error 读取或取消错误 func (r *Reader) resourceReferenceScopes(ctx context.Context, parts map[string][]byte, generated map[string]editorGeneratedReferences, documents map[string]bool, resources []string, references map[string]*editorResourceRefs, selected string) (map[string]*editorResourceRefs, error) { @@ -30,6 +30,7 @@ func (r *Reader) resourceReferenceScopes(ctx context.Context, parts map[string][ } used := make(map[string]bool) result := make(map[string]*editorResourceRefs) + shared := make(map[string]bool) for _, entry := range slices.Sorted(maps.Keys(documents)) { scope, err := r.versionFileDependencies(ctx, entry, parts, generated) if err != nil { @@ -37,6 +38,9 @@ func (r *Reader) resourceReferenceScopes(ctx context.Context, parts map[string][ } refs := &editorResourceRefs{ids: make(map[string]bool), fonts: make(map[string]*editorFontUsage)} for name := range scope { + if err := ctx.Err(); err != nil { + return nil, err + } if source := references[name]; source != nil { used[name] = true if selected == "" || selected == entry { @@ -48,11 +52,21 @@ func (r *Reader) resourceReferenceScopes(ctx context.Context, parts map[string][ continue } for name := range scope { + if err := ctx.Err(); err != nil { + return nil, err + } if !indexes[name] { continue } if result[name] == nil { - result[name] = &editorResourceRefs{ids: make(map[string]bool), fonts: make(map[string]*editorFontUsage)} + result[name] = refs + continue + } + if !shared[name] { + merged := &editorResourceRefs{ids: make(map[string]bool), fonts: make(map[string]*editorFontUsage)} + merged.merge(result[name]) + result[name] = merged + shared[name] = true } result[name].merge(refs) }