fix(state): 拖动窗格内最后一个 tab 到自身边缘会直接丢失该 tab - #763
Open
nanami-0713 wants to merge 1 commit into
Open
nanami-0713 wants to merge 1 commit into
nanami-0713 wants to merge 1 commit into
Conversation
…ses the tab moveTabToEdge 对边缘 zone 先把 tab 从源窗格摘除:若源窗格因此清空, removeLeafAt 会把该叶子从树上删除;随后的 insertLeafAt 再以同一 id 为目标时已找不到叶子,携带被拖 tab 的新叶子成为孤儿被整体丢弃—— tab 从会话中消失(未保存的编辑器草稿一并丢失),activePane 悬挂, 且布局在 200ms 防抖后把无 tab 状态持久化到 localStorage。 改为边缘 zone 先切分目标窗格、再摘 tab:insertLeafAt 完成后目标 叶子仍在树上(自身拖拽时以 target 副本保留原 id),摘除/清空删除 逻辑不变;center 路径行为保持原样。 新增回归测试:单 tab 自拖边缘(旧代码丢 tab,新代码原地切分)、 多 tab 自拖边缘(被拖 tab 进入新叶子,其余留在原叶子)。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
moveTabToEdge(src/client/state.ts)对边缘 zone(left/right/up/down)的处理顺序是先摘 tab、后切分:removeLeafAt立即把该叶子从树上删除insertLeafAt以toPane为目标插入新叶子当 fromPane === toPane(把窗格内唯一的 tab 拖到它自己窗格的边缘热区——小窗格下四边 25% 的边缘带很容易误触)时,第 1 步已把目标叶子删除,第 2 步的
mapLeaf找不到该 id,原样返回树——携带着被拖 tab 的新叶子成为孤儿被整体丢弃。实际后果:tab 从会话中彻底消失(未保存的 CodeMirror 草稿一并丢失),
activePane悬挂为不存在的 id,且布局在 200ms 防抖后把无 tab 状态持久化到 localStorage,刷新无法恢复。现有测试(tests/state.spec.ts 的 moveTabToEdge 用例)只覆盖了跨窗格、center 与幽灵窗格场景,未覆盖自拖边缘。
修复
边缘 zone 改为先切分、后摘 tab:
insertLeafAt完成时目标叶子仍在树上(自身拖拽时以 target 副本保留原 id),随后的摘除与清空删除逻辑不变;center 路径行为保持原样。测试
activePane指向新叶子