feat(文件归并): 归并同类文件清理辅助代码
build.yaml / build (push) Successful in 51s

This commit is contained in:
xiaoqidun committed 2026-10-14 09:38:41 +08:00
1 parent 961bc52038
commit d07972346b
19 files changed
+835 -1042

No files matched your search

+62
View File
@@ -20,6 +20,15 @@ import (
"slices"
)
// ObjectSelection 保存正文与注解的独立快照,共享当前编辑器的不可变资源
// 来源修改、删除或撤销不改变快照,不用于跨文档传输
type ObjectSelection struct {
editor *Editor
document editorDocumentIdentity
objects []GraphicObject
annotations *AnnotationSelection
}
// SelectionBounds 获取正文与注解混合选区的实际范围,复用同一次度量的资源缓存
// 入参: page 页面索引, objects 正文标识, annotations 注解标识,各列表不得重复
// 返回: Box 页面毫米范围, error 标识或度量错误
@@ -358,3 +367,56 @@ func (e *Editor) transformSelection(page int, objects, annotations []string, mat
return nil
})
}
// CaptureSelection 捕获正文与注解,不修改文档或历史
// 入参: page 页面索引, objects 正文标识, annotations 注解标识,各列表不得重复
// 返回: *ObjectSelection 独立快照, error 标识或资源错误
func (e *Editor) CaptureSelection(page int, objects, annotations []string) (*ObjectSelection, error) {
items, err := e.Objects(page, objects)
if err != nil {
return nil, err
}
selection := &ObjectSelection{editor: e, document: e.documentIdentity(), objects: items}
if len(annotations) != 0 {
selection.annotations, err = e.CaptureAnnotations(page, annotations)
if err != nil {
return nil, err
}
}
return selection, nil
}
// PasteSelection 原子粘贴正文与注解并平移,失败回滚,一次撤销恢复全部
// 入参: page 目标页面索引, selection 当前编辑器快照, dx 横向位移,单位为毫米, dy 纵向位移,单位为毫米
// 返回: []string 新正文标识, []string 新注解标识, error 标识、资源或编辑错误
func (e *Editor) PasteSelection(page int, selection *ObjectSelection, dx, dy float64) ([]string, []string, error) {
if selection == nil || selection.editor != e || !e.documentIdentity().matches(selection.document) || !finite(dx) || !finite(dy) {
return nil, nil, fmt.Errorf("invalid object selection or offset")
}
var objects, annotations []string
err := e.Transaction(func(edit *Editor) error {
var err error
objects, err = edit.CopyObjects(page, selection.objects, dx, dy)
if err == nil && selection.annotations != nil {
annotations, err = edit.PasteAnnotations(page, selection.annotations, dx, dy)
}
return err
})
if err != nil {
return nil, nil, err
}
return objects, annotations, nil
}
// PasteSelectionToComposite 将正文快照粘贴至内部容器,保留源外观,拒绝嵌套注解
// 入参: page 目标页面索引, path 父复合路径, selection 当前编辑器快照, dx 横向位移,单位为毫米, dy 纵向位移,单位为毫米
// 返回: []int 新成员序号, error 选区、资源或编辑错误
func (e *Editor) PasteSelectionToComposite(page int, path ObjectPath, selection *ObjectSelection, dx, dy float64) ([]int, error) {
if selection == nil || selection.editor != e || !e.documentIdentity().matches(selection.document) {
return nil, fmt.Errorf("object selection belongs to another document or editor")
}
if selection.annotations != nil {
return nil, fmt.Errorf("annotations cannot be nested in a page object")
}
return e.CopyObjectsToComposite(page, path, selection.objects, dx, dy)
}