Repository navigation
fix(editor): optimize ResetViewBox positioning and remove zoom UI from site LiveEditor - #201
Conversation
Summary of ChangesHello @xxMudCloudxx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 本次拉取请求主要致力于提升编辑器中 Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
本次 PR 主要优化了 ResetViewBox 插件的定位逻辑,并清理了网站 LiveEditor 中不再需要的缩放 UI,目标明确,改动清晰。
核心的定位修复逻辑考虑了父元素的 transform: scale 影响,并增加了对容器边界的判断,增强了插件的鲁棒性,值得肯定。
我提出了两点可以进一步提升代码鲁棒性的建议,主要集中在 reset-viewbox.ts 文件中:
- 建议移除对
stableContainer的缓存,以更好地应对动态 DOM 变化。 - 建议调整
_findStableContainer中的循环逻辑,以确保能正确检查<body>和<html>元素作为潜在的溢出容器。
整体来看,这是一次高质量的修复和重构。采纳建议后,代码的健壮性将得到进一步提升。
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #201 +/- ##
==========================================
+ Coverage 45.92% 45.93% +0.01%
==========================================
Files 338 338
Lines 27000 27038 +38
Branches 2189 2200 +11
==========================================
+ Hits 12400 12421 +21
- Misses 14590 14606 +16
- Partials 10 11 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
本次修改旨在修复
ResetViewBox按钮在父容器存在 CSS transform(如缩放)时的定位偏移问题。同时,清理了PreviewPanel中不再需要的缩放控制代码。改动详情
1. 修复按钮定位逻辑
文件:
src/editor/plugins/reset-viewbox.tsplaceButton方法,采用相对于offsetParent的坐标计算方式,使其能够自适应父容器的 transform 变换。transform scale的动态计算,确保布局布局参数包含 CSS 缩放的影响。2. 增强鲁棒性 (Robustness)
为了应对复杂的集成环境,对插件底层逻辑进行了加固:
findStableContainer逻辑,识别最近的滚动或overflow容器。当 SVG 内容超出容器时,强制将按钮位置限制在容器可视区域内,防止按钮“溢出”不可见。getTransformScale) 时增加了对offsetWidth/Height为 0 的检查,防止除以零导致的NaN错误。svg.isConnected检查,避免对未挂载的 DOM 元素进行无效计算。offsetParent和容器检测提供了完善的兜底逻辑,确保在极端的 DOM 树结构下依然保持程序稳定。3. 代码清理
文件:
site/src/components/LiveEditor/PreviewPanel.tsx前后对比
修改前:
transform会影响到按钮的定位

修改后:
移除

PreviewPanel缩放控制逻辑前, 按钮不会溢出:移除

PreviewPanel缩放控制逻辑后的UI布局: