Skip to content

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Dec 17, 2025

Kapture 2025-12-16 at 21 54 30

Summary by CodeRabbit

发版说明

  • Refactor

    • 优化了弹出框对齐机制的内部处理流程
  • Tests

    • 增强了对齐调整功能的测试覆盖范围

✏️ Tip: You can customize this high-level summary in your review settings.

@codecov
Copy link

codecov bot commented Dec 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.42%. Comparing base (338a80f) to head (5109394).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #599      +/-   ##
==========================================
+ Coverage   96.40%   96.42%   +0.01%     
==========================================
  Files          17       17              
  Lines         947      950       +3     
  Branches      279      279              
==========================================
+ Hits          913      916       +3     
  Misses         34       34              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai
Copy link

coderabbitai bot commented Dec 17, 2025

工作总结

src/hooks/useAlign.ts 和 src/util.ts 中的对齐逻辑进行了内部重构。reversePoints 函数改为返回 Points 元组而非字符串,引入 flatPoints 辅助函数进行最终转换。nextAlignInfo.points 的赋值改为通过临时 nextPoints 数组进行,使用元组形式处理多种翻转情况(bt、tb、rl、lr),最终转换回字符串形式。isPointsEq 中添加 getVal 辅助函数以安全处理数组索引访问。

变更内容

内聚体 / 文件 变更摘要
点位处理重构
src/hooks/useAlign.ts
reversePoints 函数签名变更:现返回 Points 元组而非字符串。引入 flatPoints(points) 辅助函数用于将元组转换为字符串。使用临时 nextPoints 数组替代直接变更 nextAlignInfo.points,在所有翻转逻辑(bt、tb、rl、lr)中传递更新后的点位元组,最后通过 flatPoints 转换为字符串形式进行最终赋值。
相等性检查优化
src/util.ts
导入语句从多行改为单行。isPointsEq 函数内添加本地辅助函数 getVal(a, index) 用于安全的数组索引访问,返回值或空字符串。更新相等性检查逻辑:isAlignPoint 为真时使用 getVal(a1, 0) === getVal(a2, 0),为假时使用 getVal 处理两个索引位置。
对齐测试用例
tests/align.test.tsx
新增测试用例"both adjustX and adjustY should get correct points",验证当弹出框在左上角时触发翻转到右下角,同时启用 X 和 Y 方向的溢出调整,确保 onPopupAlign 被调用时包含正确的点位 ['br', 'tr']。

预估代码审查工作量

🎯 3 (中等) | ⏱️ ~25-35 分钟

  • 重点关注领域:
    • reversePoints 函数在所有调用处的返回值使用是否正确(从字符串改为 Points 元组)
    • flatPoints 辅助函数在各个翻转情况(bt、tb、rl、lr)中的一致性应用
    • nextPoints 数组的初始化、更新和最终转换逻辑是否无误
    • isPointsEq 中 getVal 辅助函数对 undefined/null 值的处理是否符合预期
    • 新增测试用例覆盖的场景是否充分验证重构后的逻辑

建议审查人

  • afc163

诗文献礼

🐰 点位元组舞翻飞,字符串化尾收尾,
临时数组路清晰,安全索引永不失,
对齐逻辑焕新彩,兔兔欢呼贺今朝!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title "fix: Align flip should both work" is vague and generic, using non-specific phrasing that doesn't clearly convey what alignment flip behavior is being fixed. Replace with a more specific title describing the actual fix, e.g., "fix: Ensure align flip works correctly with both X and Y overflow adjustments" or similar.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-align-info

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 338a80f and 5109394.

📒 Files selected for processing (3)
  • src/hooks/useAlign.ts (6 hunks)
  • src/util.ts (1 hunks)
  • tests/align.test.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/align.test.tsx (2)
docs/examples/point.tsx (1)
  • render (35-87)
tests/util.tsx (1)
  • awaitFakeTimer (97-104)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (6)
src/util.ts (1)

8-13: 逻辑改进正确!

添加 getVal 辅助函数提供了安全的数组访问,通过返回空字符串处理未定义或缺失的索引。这使得点位比较更加健壮,与 useAlign.ts 中基于元组的点位处理保持一致。

tests/align.test.tsx (1)

300-335: 测试覆盖全面!

这个测试用例有效验证了双轴翻转场景:

  • 将目标定位在左上角 (0, 0) 强制触发溢出
  • 同时启用 adjustXadjustY
  • 正确断言点位从 ['tl', 'bl'] 翻转到 ['br', 'tr']

测试设计符合 PR 目标,验证了对齐翻转逻辑在两个方向同时调整时的正确性。

src/hooks/useAlign.ts (4)

72-87: 重构设计优秀!

将点位处理重构为函数式风格:

  • reversePoints 使用扩展运算符创建不可变副本,避免了直接修改
  • flatPoints 提供了从元组到字符串的清晰转换
  • 返回类型 Points 增强了类型安全性

这种方式比直接字符串操作更易于维护和测试。


342-342: 引入 nextPoints 中间表示!

使用 nextPoints 数组在翻转逻辑中跟踪点位变化,在所有调整完成后才通过 flatPoints 转换为字符串。这种延迟编码的方式使得多次翻转(例如同时在 X 和 Y 轴上翻转)能够正确累积,修复了之前可能存在的翻转冲突问题。


454-457: 翻转逻辑一致且正确!

在每个翻转分支中,使用 reversePoints 同时更新 nextPoints[0](弹出层点位)和 nextPoints[1](目标点位):

  • 上下翻转使用索引 0(top/bottom)
  • 左右翻转使用索引 1(left/right)

这确保了当 adjustXadjustY 同时启用时,两个维度的翻转能够正确累积,解决了 PR 标题中提到的问题。

Also applies to: 500-503, 553-556, 599-602


608-611: 最终编码时机正确!

在所有翻转逻辑完成后,才通过 flatPoints 将元组点位编码回字符串格式,赋值给 nextAlignInfo.points。这确保了:

  1. 多个维度的翻转可以顺序累积到 nextPoints
  2. 公共 API(onPopupAlign 回调)接收到的是正确的最终点位字符串数组
  3. 避免了中间编码/解码导致的点位丢失

与新增的测试用例配合,验证了修复的有效性。


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @zombieJ, 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!

This pull request resolves an issue in the alignment utility where the points property might not be correctly updated after a flip operation, especially when both horizontal and vertical adjustments are active. The changes refactor the internal handling of alignment points during the flipping process, ensuring that the points information accurately reflects the adjusted alignment, thereby improving the reliability of popup positioning.

Highlights

  • Refactored Point Reversal Logic: The reversePoints utility function now returns an array of points (Points) instead of a joined string, improving type safety and internal consistency within the alignment logic.
  • Introduced flatPoints Helper: A new utility function flatPoints was added to convert an array of points back into a string representation when needed, complementing the change in reversePoints.
  • Improved Alignment Flipping Mechanism: The core alignment logic in useAlign was updated to use a mutable nextPoints array for tracking popup and target alignment points during overflow adjustments. This ensures that the points are correctly updated when both horizontal (adjustX) and vertical (adjustY) flipping are active.
  • Enhanced isPointsEq Robustness: The isPointsEq utility function now uses a safer method to access array elements, preventing potential errors with undefined indices and making the comparison more reliable.
  • Added Comprehensive Test Case: A new test was introduced to specifically verify the correct flipping behavior when both horizontal (adjustX) and vertical (adjustY) adjustments are enabled, ensuring the fix works as expected.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses a bug where sequential horizontal and vertical alignment flips would not compose correctly. The fix involves refactoring reversePoints to return a Points array instead of a string, and introducing a nextPoints variable to track the state of the points through multiple flips. This is a clean and effective solution. A new test case has been added to validate the fix for combined flips. I've included one suggestion to improve the type safety of the reversePoints function.

Comment on lines +72 to +83
function reversePoints(points: Points, index: number): Points {
const reverseMap = {
t: 'b',
b: 't',
l: 'r',
r: 'l',
};

return points
.map((point, i) => {
if (i === index) {
return reverseMap[point] || 'c';
}
return point;
})
.join('');
const clone = [...points] as Points;
clone[index] = reverseMap[points[index]] || 'c';
return clone;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this implementation is more efficient and correctly enables chained flips, it relies on a type assertion (as Points) and the structure of reverseMap to maintain type safety, which might not be immediately obvious. The assignment clone[index] = reverseMap[points[index]] || 'c' is not strictly type-safe because TypeScript can't guarantee that (for example) a AlignPointLeftRight value isn't assigned to clone[0].

Consider a slightly more verbose but type-safe implementation that makes the logic clearer and safer by separating the vertical and horizontal reversal logic. This avoids potential issues if Points or the reversal logic were to change in the future.

Suggested change
function reversePoints(points: Points, index: number): Points {
const reverseMap = {
t: 'b',
b: 't',
l: 'r',
r: 'l',
};
return points
.map((point, i) => {
if (i === index) {
return reverseMap[point] || 'c';
}
return point;
})
.join('');
const clone = [...points] as Points;
clone[index] = reverseMap[points[index]] || 'c';
return clone;
}
function reversePoints(points: Points, index: number): Points {
const clone: Points = [...points];
if (index === 0) {
const verticalMap: Record<AlignPointTopBottom, AlignPointTopBottom> = { t: 'b', b: 't', c: 'c' };
clone[0] = verticalMap[clone[0]];
} else {
const horizontalMap: Record<AlignPointLeftRight, AlignPointLeftRight> = { l: 'r', r: 'l', c: 'c' };
clone[1] = horizontalMap[clone[1]];
}
return clone;
}

@zombieJ zombieJ merged commit aaea98c into master Dec 17, 2025
10 checks passed
@zombieJ zombieJ deleted the fix-align-info branch December 17, 2025 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants