UI编辑器撤销回退功能 #261

Merged
kdletters merged 29 commits from feat/ui-editor-edit-history into master 2026-09-03 19:31:26 +08:00
Member

整理已有的 UI树的改变操作, 把其中的高频改变(如拖动, 颜色选取) 改为最后时提交

撤销和回退的实现:

简单地对整个树进行快照

close #260

整理已有的 UI树的改变操作, 把其中的高频改变(如拖动, 颜色选取) 改为最后时提交 撤销和回退的实现: 简单地对整个树进行快照 close #260
k88936 self-assigned this 2026-09-03 11:03:55 +08:00
k88936 added this to the 陶泥儿gameAgent project 2026-09-03 11:03:55 +08:00
k88936 added 1 commit 2026-09-03 11:03:56 +08:00
调整 UI 编辑器节点变换为松开时提交
Project CI / Repository checks (pull_request) Failing after 16s
Project CI / Frontend tests (pull_request) Failing after 2m3s
Project CI / Backend tests (pull_request) Failing after 20s
Project CI / Native shell tests (pull_request) Failing after 4m30s
8a18b1b181
拖动和缩放期间仅更新预览临时变换

指针松开时提交最终变换,取消操作不写入 State

补充 UI 编辑器拖动变换提交边界文档
k88936 added 16 commits 2026-09-03 12:45:30 +08:00
明确撤销与重做的 State 范围、事务边界和生命周期

明确连续控件与节点变换的低频提交规则

明确资产文件、副作用、快捷键和验收标准
在统一 State 提交入口增加 100 条快照历史与 no-op 过滤

提供撤销、重做、事务分组及加载重置历史 API

补充 State 历史、事务回滚和加载清理测试
新增统一的加锁并包裹历史事务操作

将 AI 建议、识别、合并和批量绑定改用统一入口
颜色拖动期间使用本地草稿预览

指针释放时一次提交最终颜色 State
清空编辑器时重置撤销与重做栈

补充清空操作不会进入历史的测试
在编辑器头部增加撤销与重做按钮及禁用态

增加桌面 Cmd/Ctrl 快捷键并保留文本控件原生行为
将撤销重做规格加入文档总览入口
仅在预览变换实际变化时创建新 Map\n避免取消不存在手势时触发预览树重渲染
通过 ref 读取最新预览回调\n避免回调身份变化时重复取消进行中的手势
透明度修改提交前显式清除颜色草稿\n避免无效更新后残留未提交颜色
仅将文本输入控件视为可编辑目标\n保持工具栏按钮聚焦时仍可使用撤销重做快捷键
按稳定的撤销重做回调绑定全局监听\n尊重已被其他处理器阻止的键盘事件
用可提前退出的递归比较替代完整状态序列化\n减少每次编辑提交的无谓 JSON 字符串构造
移除撤销事务 API 与额外事务状态

让绑定每个 batch 独立提交一条撤销记录

同步更新规格和独立提交测试
断言 pointermove 仅更新预览\n断言 pointerup 才提交一次节点变换
提交颜色选择器结束态草稿
Project CI / Repository checks (pull_request) Failing after 19s
Project CI / Backend tests (pull_request) Failing after 19s
Project CI / Frontend tests (pull_request) Successful in 2m41s
Project CI / Native shell tests (pull_request) Successful in 14m54s
d6f0c2642f
使用 RgbaColorPicker 的 onChangeEnd 处理指针与键盘结束\n关闭颜色弹层时提交仍存在的草稿
k88936 added 8 commits 2026-09-03 13:45:25 +08:00
复用空的预览变换映射,避免节点递归渲染重复分配
单次读取节点预览变换,移除重复 Map 查找和非空断言
为撤销历史容量 100 增加命名常量,便于理解和调节内存权衡
提交历史时复用已克隆的 nextState,避免每次编辑产生冗余深拷贝
忽略 keydown 重复事件,避免长按撤销或重做键耗尽历史记录
为 sameResource 增加对象对访问跟踪,遇到循环结构时安全终止递归
组件卸载前提交仍未关闭的颜色草稿,避免切换面板或删除组件导致颜色丢失
统一节点变换实时预览
Project CI / Frontend tests (pull_request) Successful in 3m17s
Project CI / Backend tests (pull_request) Failing after 11s
Project CI / Repository checks (pull_request) Failing after 12s
Project CI / Native shell tests (pull_request) Successful in 19m52s
e4680d6f70
预览拖动和缩放时同步解析保持子节点页面矩形的变换

将检查器的子节点保持选项传入预览交互并补充回归测试
Member

Genarrative 自动审查(head sha: e4680d6f7013f06739819da15d92535ebe87c743

P2 — 批量绑定产生多个撤销步骤

文件:apps/ai-game-creator-shell/src/view/ui-editor/useUiEditorPage.ts:1031

bindComponents 是一次用户触发的批量绑定操作,但每个 batch 都调用 editor.replaceState(current)replaceState 默认会把每次调用都压入 undo 栈并清空 redo 栈。因此素材超过一个 batch 时,点击一次“绑定组件”会产生多个撤销步骤,撤销一次只能回退最后一个 batch,甚至可能达到 100 条历史上限而无法恢复到操作前的完整状态。建议整个批处理结束后只提交一次历史快照(中间调用使用 history: 'skip',最后一次使用默认记录)。

Genarrative 自动审查(head sha: `e4680d6f7013f06739819da15d92535ebe87c743`) **P2 — 批量绑定产生多个撤销步骤** 文件:`apps/ai-game-creator-shell/src/view/ui-editor/useUiEditorPage.ts:1031` `bindComponents` 是一次用户触发的批量绑定操作,但每个 batch 都调用 `editor.replaceState(current)`;`replaceState` 默认会把每次调用都压入 undo 栈并清空 redo 栈。因此素材超过一个 batch 时,点击一次“绑定组件”会产生多个撤销步骤,撤销一次只能回退最后一个 batch,甚至可能达到 100 条历史上限而无法恢复到操作前的完整状态。建议整个批处理结束后只提交一次历史快照(中间调用使用 `history: 'skip'`,最后一次使用默认记录)。
kdletters reviewed 2026-09-03 13:50:41 +08:00
kdletters left a comment
Member

本次审查 head sha: e4680d6f7013f06739819da15d92535ebe87c743。发现 1 个非阻塞问题,已通过 PR 总评论回写(ID 3255)。

本次审查 head sha: `e4680d6f7013f06739819da15d92535ebe87c743`。发现 1 个非阻塞问题,已通过 PR 总评论回写(ID 3255)。
Member

bindComponents 每个 batch 都调用 editor.replaceState(current),而 replaceState 默认记录历史。因此一次批量绑定会产生多个撤销步骤;请在批处理期间使用 history: 'skip',最后统一记录一次。

`bindComponents` 每个 batch 都调用 `editor.replaceState(current)`,而 `replaceState` 默认记录历史。因此一次批量绑定会产生多个撤销步骤;请在批处理期间使用 `history: 'skip'`,最后统一记录一次。
k88936 marked this conversation as resolved
k88936 added 1 commit 2026-09-03 14:42:43 +08:00
合并批量组件绑定历史记录
Project CI / Repository checks (pull_request) Failing after 11s
Project CI / Backend tests (pull_request) Failing after 10s
Project CI / Frontend tests (pull_request) Successful in 3m7s
Project CI / Native shell tests (pull_request) Successful in 22m4s
9fd160efc5
批处理中的前置绑定批次跳过历史,最后一批使用非跳过替换统一形成撤销边界

为跳过后记录历史的状态基线补充撤销回归测试
k88936 added 1 commit 2026-09-03 14:44:38 +08:00
Merge branch 'master' into feat/ui-editor-edit-history
Project CI / Repository checks (pull_request) Failing after 1m57s
Project CI / Frontend tests (pull_request) Successful in 4m9s
Project CI / Backend tests (pull_request) Successful in 6m17s
Project CI / Native shell tests (pull_request) Failing after 20m35s
0c0cad7fa4
Member

本次审查 head sha: 9fd160efc5fa5f2b6ea8db041f6b0c92168d7898。已检查该 head 相对 base 的代码变更,并运行 UI 编辑器相关测试(15/15 通过)及 ai-game-creator-shell typecheck(通过)。未发现明确问题。

本次审查 head sha: `9fd160efc5fa5f2b6ea8db041f6b0c92168d7898`。已检查该 head 相对 base 的代码变更,并运行 UI 编辑器相关测试(15/15 通过)及 ai-game-creator-shell typecheck(通过)。未发现明确问题。
k88936 marked the pull request as ready for review 2026-09-03 15:04:46 +08:00
k88936 requested review from kdletters 2026-09-03 15:04:50 +08:00
k88936 added 1 commit 2026-09-03 16:08:26 +08:00
Merge branch 'master' into feat/ui-editor-edit-history
Project CI / Backend tests (pull_request) Successful in 7m2s
Project CI / Repository checks (pull_request) Successful in 3m8s
Project CI / Frontend tests (pull_request) Successful in 3m9s
Project CI / Native shell tests (pull_request) Successful in 21m38s
51b7d51d01
Member

本次审查 head sha: 。

已检查完整 diff,并运行 UI 编辑器相关测试(15/15 通过)及 ai-game-creator-shell typecheck(通过)。

未发现明确问题。

本次审查 head sha: 。 已检查完整 diff,并运行 UI 编辑器相关测试(15/15 通过)及 ai-game-creator-shell typecheck(通过)。 未发现明确问题。
Member

本次审查 head sha: 51b7d51d019855c4b64b771cc9eb1d24a2ee668d

已检查该 head 相对 base d5e05d79fed5af57f7afa44d2916992487aff0ed 的完整 diff(12 个文件),并结合现有 UI 编辑器代码、测试和配置审查;已运行 UI 编辑器相关测试(15/15 通过)及 ai-game-creator-shell typecheck(通过)。

未发现明确问题。

本次审查 head sha: `51b7d51d019855c4b64b771cc9eb1d24a2ee668d`。 已检查该 head 相对 base `d5e05d79fed5af57f7afa44d2916992487aff0ed` 的完整 diff(12 个文件),并结合现有 UI 编辑器代码、测试和配置审查;已运行 UI 编辑器相关测试(15/15 通过)及 `ai-game-creator-shell` typecheck(通过)。 未发现明确问题。
kdletters reviewed 2026-09-03 16:13:43 +08:00
kdletters left a comment
Member

本次审查未发现明确问题。

本次审查未发现明确问题。
kdletters added 1 commit 2026-09-03 19:30:44 +08:00
Merge branch 'master' into feat/ui-editor-edit-history
Project CI / Repository checks (pull_request) Successful in 2m40s
Project CI / Frontend tests (pull_request) Successful in 3m6s
Project CI / Backend tests (pull_request) Successful in 6m40s
Project CI / Native shell tests (pull_request) Successful in 20m27s
b7641f94b7
kdletters merged commit cb7bc50ef9 into master 2026-09-03 19:31:26 +08:00
kdletters deleted branch feat/ui-editor-edit-history 2026-09-03 19:31:26 +08:00
kdletters reviewed 2026-09-03 19:34:26 +08:00
kdletters left a comment
Member

本次审查 head sha: b7641f94b724fafe3aca0a84727cac82696a1af8。未发现明确问题。

本次审查 head sha: `b7641f94b724fafe3aca0a84727cac82696a1af8`。未发现明确问题。
Sign in to join this conversation.