fix(diff): 首次打开 diff 预览自动定位到第一个变更行#1149
Open
david188888 wants to merge 1 commit into
Open
Conversation
Contributor
|
感谢解决issue问题~ |
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.
关联 Issue
Closes #1017
根因
DiffView.tsx:144-148的滚动容器无 ref、无"首次打开自动定位"effect。DiffTabContent.tsx:801-840的restoreScroll只在有缓存滚动位置(restoreScrollRef.current === true)时触发;首次打开(无缓存)时在:802直接 return,视图停在scrollTop=0(文件顶部),离实际变更可能隔着好几屏。修复
在
DiffTabContent新增独立的"首次打开自动定位"effect(:845-891):!previewOnly && !loading && !restoreScrollRef.current && !scrollPositionCache.has(scrollKey) && 未触发过restoreScroll同模式)querySelector('[data-line-type=change-addition], [data-line-type=change-deletion]')+scrollIntoView({ block: 'center' })restoreScrollRef.current与scrollPositionCache.has(scrollKey),有缓存位置时完全不介入[filePath, sessionId]变化时重置querySelector命中第一个有变更的文件的第一个变更行采用
scrollIntoView而非手动算offsetTop,因为滚动容器嵌套(scrollContainerRef的 overflow-auto div 与@pierre/diffs内部[data-code]滚动元素),浏览器自动滚动所有可滚动祖先,对单文件与多文件均生效。验证
bun run typecheck:通过bun test:通过(1 个 pre-existing flake 同 Agent 技能管理页面未显示所有已安装的工作区 Skill #1134 说明)bun run build:renderer:通过改动范围
apps/electron/src/renderer/components/diff/DiffTabContent.tsx:+50 行(auto-scroll effect + cleanup)apps/electron/package.json:patch 版本递增