Skip to content

fix(formmain): 修复弹窗时按下回车导致崩溃的问题#2805

Merged
LinQingYuu merged 1 commit intodevfrom
fix/msgbox-keydown
May 8, 2026
Merged

fix(formmain): 修复弹窗时按下回车导致崩溃的问题#2805
LinQingYuu merged 1 commit intodevfrom
fix/msgbox-keydown

Conversation

@Big-Cake-jpg
Copy link
Copy Markdown
Member

@Big-Cake-jpg Big-Cake-jpg commented May 7, 2026

(由 GPT-5.4-mini 生成)

Summary by Sourcery

错误修复:

  • 修复在显示非输入消息对话框时按下 Enter 导致的崩溃问题,通过安全地委托给相应的按钮处理程序来解决。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Fix crash caused by pressing Enter when a non-input message dialog is displayed by safely delegating to the appropriate button handler.

@Big-Cake-jpg Big-Cake-jpg requested a review from a team May 7, 2026 16:14
@pcl-ce-automation pcl-ce-automation Bot added 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 size: S PR 大小评估:小型 labels May 7, 2026
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 7, 2026

审阅者指南(在小型 PR 上折叠)

审阅者指南

处理多种弹出消息类型的 Enter 键按下事件,防止由于假定特定控件类型而导致的崩溃。

弹出消息 Enter 键处理的时序图

sequenceDiagram
    participant User as User
    participant FormMain as FormMain
    participant PanMsg as PanMsg
    participant MyMsgInput as MyMsgInput
    participant MyMsgSelect as MyMsgSelect
    participant MyMsgText as MyMsgText
    participant MyMsgMarkdown as MyMsgMarkdown
    participant MyMsgLogin as MyMsgLogin

    User->>FormMain: KeyDown(Enter)
    FormMain->>FormMain: Check e.Key == Enter
    alt Enter key pressed
        FormMain->>PanMsg: Get Children[0]
        Note over FormMain,PanMsg: Determine message type via switch expression
        alt msg is MyMsgInput
            FormMain->>MyMsgInput: Btn1_Click(sender, null)
        else msg is MyMsgSelect
            FormMain->>MyMsgSelect: Btn1_Click(sender, null)
        else msg is MyMsgText
            FormMain->>MyMsgText: Btn1_Click(sender, null)
        else msg is MyMsgMarkdown
            FormMain->>MyMsgMarkdown: Btn1_Click(sender, null)
        else msg is MyMsgLogin
            FormMain->>MyMsgLogin: Btn1_Click(sender, null)
        else unknown type
            FormMain->>FormMain: enterAction is null
            FormMain->>FormMain: No action invoked
        end
    end
Loading

FormMain 处理弹出消息 Enter 键的类图

classDiagram
    class FormMain {
        +FormMain_KeyDown(sender, e)
    }

    class PanMsg {
        +Children~UIElement[]~
    }

    class MyMsgInput {
        +Btn1_Click(sender, e)
    }

    class MyMsgSelect {
        +Btn1_Click(sender, e)
    }

    class MyMsgText {
        +Btn1_Click(sender, e)
    }

    class MyMsgMarkdown {
        +Btn1_Click(sender, e)
    }

    class MyMsgLogin {
        +Btn1_Click(sender, e)
    }

    FormMain --> PanMsg : uses
    FormMain ..> MyMsgInput : Enter key dispatch
    FormMain ..> MyMsgSelect : Enter key dispatch
    FormMain ..> MyMsgText : Enter key dispatch
    FormMain ..> MyMsgMarkdown : Enter key dispatch
    FormMain ..> MyMsgLogin : Enter key dispatch

    class EnterKeyDispatch {
        +Action enterAction
        +Resolve(msg, sender)
    }

    FormMain ..> EnterKeyDispatch : switch on msg type
    EnterKeyDispatch ..> MyMsgInput
    EnterKeyDispatch ..> MyMsgSelect
    EnterKeyDispatch ..> MyMsgText
    EnterKeyDispatch ..> MyMsgMarkdown
    EnterKeyDispatch ..> MyMsgLogin
Loading

文件级更改

变更 详情 文件
将消息面板的 Enter 键处理泛化,以支持多种消息控件类型并避免无效类型转换。
  • 用引用第一个子元素的本地变量替换了将 PanMsg 的第一个子元素直接强制转换为 MyMsgInput 的做法。
  • 引入基于消息控件类型的 switch 表达式,以映射到 MyMsgInput、MyMsgSelect、MyMsgText、MyMsgMarkdown 和 MyMsgLogin 各自对应的 Btn1_Click 处理程序。
  • 使用可空的 Action 和空条件调用,在不抛出异常的情况下安全地处理不受支持的消息类型。
  • 在处理 Enter 键后保留早返回逻辑,以维持现有的控制流语义。
Plain Craft Launcher 2/FormMain.xaml.cs

提示和命令

与 Sourcery 交互

  • 触发新的审查: 在拉取请求上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 在某条审查评论下回复,请求 Sourcery 根据该评论创建 issue。你也可以在审查评论下回复 @sourcery-ai issue 来从该评论创建 issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写上 @sourcery-ai,即可随时生成标题。你也可以在拉取请求上评论 @sourcery-ai title 来(重新)生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任意位置写上 @sourcery-ai summary,即可在指定位置随时生成 PR 摘要。你也可以在拉取请求上评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在拉取请求上评论 @sourcery-ai guide,即可随时(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在拉取请求上评论 @sourcery-ai resolve,以解决所有 Sourcery 评论。当你已经处理完所有评论且不想再看到它们时非常有用。
  • 撤销所有 Sourcery 审查: 在拉取请求上评论 @sourcery-ai dismiss,以撤销所有现有的 Sourcery 审查。尤其适用于你希望从头开始新的审查时——别忘了评论 @sourcery-ai review 来触发新的审查!

自定义你的体验

访问你的 控制面板 以:

  • 启用或禁用审查功能,例如 Sourcery 生成的拉取请求摘要、审阅者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查指令。
  • 调整其他审查设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Handle Enter key presses for multiple popup message types to prevent crashes caused by assuming a specific control type.

Sequence diagram for Enter key handling on popup messages

sequenceDiagram
    participant User as User
    participant FormMain as FormMain
    participant PanMsg as PanMsg
    participant MyMsgInput as MyMsgInput
    participant MyMsgSelect as MyMsgSelect
    participant MyMsgText as MyMsgText
    participant MyMsgMarkdown as MyMsgMarkdown
    participant MyMsgLogin as MyMsgLogin

    User->>FormMain: KeyDown(Enter)
    FormMain->>FormMain: Check e.Key == Enter
    alt Enter key pressed
        FormMain->>PanMsg: Get Children[0]
        Note over FormMain,PanMsg: Determine message type via switch expression
        alt msg is MyMsgInput
            FormMain->>MyMsgInput: Btn1_Click(sender, null)
        else msg is MyMsgSelect
            FormMain->>MyMsgSelect: Btn1_Click(sender, null)
        else msg is MyMsgText
            FormMain->>MyMsgText: Btn1_Click(sender, null)
        else msg is MyMsgMarkdown
            FormMain->>MyMsgMarkdown: Btn1_Click(sender, null)
        else msg is MyMsgLogin
            FormMain->>MyMsgLogin: Btn1_Click(sender, null)
        else unknown type
            FormMain->>FormMain: enterAction is null
            FormMain->>FormMain: No action invoked
        end
    end
Loading

Class diagram for FormMain Enter key popup handling

classDiagram
    class FormMain {
        +FormMain_KeyDown(sender, e)
    }

    class PanMsg {
        +Children~UIElement[]~
    }

    class MyMsgInput {
        +Btn1_Click(sender, e)
    }

    class MyMsgSelect {
        +Btn1_Click(sender, e)
    }

    class MyMsgText {
        +Btn1_Click(sender, e)
    }

    class MyMsgMarkdown {
        +Btn1_Click(sender, e)
    }

    class MyMsgLogin {
        +Btn1_Click(sender, e)
    }

    FormMain --> PanMsg : uses
    FormMain ..> MyMsgInput : Enter key dispatch
    FormMain ..> MyMsgSelect : Enter key dispatch
    FormMain ..> MyMsgText : Enter key dispatch
    FormMain ..> MyMsgMarkdown : Enter key dispatch
    FormMain ..> MyMsgLogin : Enter key dispatch

    class EnterKeyDispatch {
        +Action enterAction
        +Resolve(msg, sender)
    }

    FormMain ..> EnterKeyDispatch : switch on msg type
    EnterKeyDispatch ..> MyMsgInput
    EnterKeyDispatch ..> MyMsgSelect
    EnterKeyDispatch ..> MyMsgText
    EnterKeyDispatch ..> MyMsgMarkdown
    EnterKeyDispatch ..> MyMsgLogin
Loading

File-Level Changes

Change Details Files
Generalized Enter key handling for message panel to support multiple message control types and avoid invalid casts.
  • Replaced direct cast of the first PanMsg child to MyMsgInput with a local variable referencing the first child element.
  • Introduced a switch expression on the message control type to map to the appropriate Btn1_Click handler for MyMsgInput, MyMsgSelect, MyMsgText, MyMsgMarkdown, and MyMsgLogin.
  • Used a nullable Action and null-conditional invocation to safely handle unsupported message types without throwing exceptions.
  • Preserved early return after handling the Enter key to keep existing control flow semantics.
Plain Craft Launcher 2/FormMain.xaml.cs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - 我在这里给出了一些高层面的反馈:

  • 在访问索引 0 之前,建议对 PanMsg.Children 集合为空的情况进行防护,以避免在按下 Enter 键时如果不存在消息控件而导致潜在的 ArgumentOutOfRangeException
  • 针对 MyMsgInput/MyMsgSelect/MyMsgText/MyMsgMarkdown/MyMsgLogin 的基于类型的 switch 语句表明,这些控件可以共享一个公共接口或基类,并对外暴露 Btn1_Click。这样可以消除对 switch 表达式的需求,并让 Enter 键处理逻辑更容易扩展。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- Consider guarding against an empty `PanMsg.Children` collection before accessing index 0 to avoid potential `ArgumentOutOfRangeException` if no message control is present when Enter is pressed.
- The type-based switch for `MyMsgInput/MyMsgSelect/MyMsgText/MyMsgMarkdown/MyMsgLogin` suggests these controls could share a common interface or base class exposing `Btn1_Click`, which would remove the need for the switch expression and make the Enter handling easier to extend.

Sourcery 对开源项目免费——如果你喜欢我们的评审,请考虑分享 ✨
帮我变得更有用!请对每条评论点 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English

Hey - I've left some high level feedback:

  • Consider guarding against an empty PanMsg.Children collection before accessing index 0 to avoid potential ArgumentOutOfRangeException if no message control is present when Enter is pressed.
  • The type-based switch for MyMsgInput/MyMsgSelect/MyMsgText/MyMsgMarkdown/MyMsgLogin suggests these controls could share a common interface or base class exposing Btn1_Click, which would remove the need for the switch expression and make the Enter handling easier to extend.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider guarding against an empty `PanMsg.Children` collection before accessing index 0 to avoid potential `ArgumentOutOfRangeException` if no message control is present when Enter is pressed.
- The type-based switch for `MyMsgInput/MyMsgSelect/MyMsgText/MyMsgMarkdown/MyMsgLogin` suggests these controls could share a common interface or base class exposing `Btn1_Click`, which would remove the need for the switch expression and make the Enter handling easier to extend.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@pcl-ce-automation pcl-ce-automation Bot added 🕑 等待合并 已处理完毕,正在等待代码合并入主分支 and removed 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 labels May 8, 2026
@LinQingYuu LinQingYuu merged commit 845fd02 into dev May 8, 2026
3 checks passed
@pcl-ce-automation pcl-ce-automation Bot added 👌 完成 相关问题已修复或功能已实现,计划在下次版本更新时正式上线 and removed 🕑 等待合并 已处理完毕,正在等待代码合并入主分支 labels May 8, 2026
@LinQingYuu LinQingYuu deleted the fix/msgbox-keydown branch May 8, 2026 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: S PR 大小评估:小型 👌 完成 相关问题已修复或功能已实现,计划在下次版本更新时正式上线

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants