fix(selection): prevent stale touch drag offset after blank click#5072
fix(selection): prevent stale touch drag offset after blank click#5072xiaoyierle wants to merge 2 commits into
Conversation
Cancel pending selection drag frame and offset when cleaning selection, so touch devices do not apply the previous drag offset again after blank click. Closes antvis#5070
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to properly cancel and clean up selection translation states, specifically addressing an issue where pending drag offsets were not discarded when a selection was cleared. It adds a new test case to verify this behavior and introduces helper methods stopSelectionTranslatingBatch and cancelSelectionTranslating to centralize the cleanup logic. Feedback from the review suggests refactoring existing cleanup blocks to use these new helper methods to reduce code duplication and improve maintainability.
| this.stopSelectionTranslatingBatch() | ||
| // 清理本次拖拽缓存 | ||
| this.translatingCache = null | ||
| this.draggingPreviewMode = 'translate' |
There was a problem hiding this comment.
The logic for cleaning up translation state (stopping the batch, clearing cache, and resetting the preview mode) is now duplicated between this block and the new cancelSelectionTranslating method. While a full refactor of this block is partially outside the current diff hunks, using the new helper method here would improve maintainability and ensure that all translation-related state is cleared consistently.
Cancel pending selection drag frame and offset when cleaning selection, so touch devices do not apply the previous drag offset again after blank click.
Closes #5070
📝 Description
当框选节点后进行拖拽,随后点击画布空白处时,可能会复用上一次尚未清理的拖拽偏移,导致节点再次发生位移。本次修复将 selection 拖拽状态的清理逻辑集中处理,在 clean() 时取消未执行的拖拽动画帧,清空残留的拖拽偏移和缓存状态,恢复拖拽过程中的路由降级状态,并关闭 selection 拖拽开启的 move-selection batch。
同时补充了 touch 清理路径的回归测试。
🖼️ Screenshot
💡 Motivation and Context
修复 https://github.com/antvis/X6/issues/5070。
该问题只在触摸设备上更容易复现,原因是 touch 拖拽结束后可能仍保留上一轮 selection 拖拽的 pending offset。清理选区时主动丢弃这些残留状态,可以避免后续空白点击再次触发节点位移。
本次改动不涉及公开 API 变化。
🧩 Types of changes
🔍 Self Check before Merge