Skip to content

[Bug] 键位捕获态跨页面存活,切换页面后按任意键会静默改写并落盘用户键位 #116

Closed as not planned

Description

@Twelve-eight

模块范围

Mod settings(模组设置)

严重程度

Major / regression(主要问题 / 回归)

发生了什么?

ModSettingsKeyBindingControl 的键位捕获状态 _capturing 只在 Escape、Backspace、成功捕获这几种情况下清零,没有 _ExitTree 清理,也没有焦点退出清理。

设置页面切走时只把 Root.Visible = false,节点仍留在树里。于是:

  1. 在 A 页面点开键位捕获
  2. 切换到 B 页面(捕获状态没被清除)
  3. 在 B 页面按任意键

这个按键会被 SetInputAsHandled() 吃掉,然后走 ApplyBinding → entry.Binding.Write,静默改写用户的键位并落盘。

对照:同目录的 ModSettingsDropdownChoiceControl.cs:166-171 有正确的清理模式 ——

public override void _ExitTree()
{
    if (_dropOpen)
        CloseDropdown();
    base._ExitTree();
}

键位控件没有对应的实现。

复现步骤

  1. 打开某个 mod 的设置页,点「捕获键位」进入捕获态
  2. 切换到另一个设置页(不按 Escape)
  3. 按任意键
  4. 回到原页面 → 键位已被改写;检查配置 json → 已落盘

期望行为

节点离开场景树、或捕获控件失去焦点时,捕获态应当结束,且不写入任何绑定。

实际行为

捕获态跨页面存活,下一次按键被误当作绑定输入。

建议修法

public override void _ExitTree()
{
    if (_capturing)
    {
        _capturing = false;
        _pendingModifierBindings.Clear();
        RefreshText();
    }
    base._ExitTree();
}

由于页面只是 Visible = false 而不离树,建议同时订阅 _captureButton.FocusExited 结束捕获(我已按此修法在本地验证可编译,0 警告 0 错误)。

补充:一处被我撤回的判断

初稿时我怀疑这还会导致「方向键导航永久禁用」。复核后发现 TryHandleDirectionalFocusInput(:3098-3100)与 IsQuickSearchShortcutClaimedByFocusedControl(QuickSearch.cs:493-497)都是从焦点持有者沿父链找 claimant,焦点离开后不会命中,所以那个推断不成立。本条 issue 只包含已经确认的「静默改写键位」部分。

版本

  • RitsuLib: v0.6.7(2332d9d0)

Activity

  1. added
    area/settingsMod settings UI, config entries, persistence, or input handling.
    priority/p1High priority regression or high-impact work.
    severity/majorSignificant bug with workaround or limited scope.
    on Oct 19, 2026
  2. Twelve-eight commented on Oct 19, 2026

    @Twelve-eight
    Author

    撤回:提交前未完成交叉验证,判断依据不充分。待核对完整证据链后如需要会重新提交。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/settingsMod settings UI, config entries, persistence, or input handling.priority/p1High priority regression or high-impact work.severity/majorSignificant bug with workaround or limited scope.status/needs-triageNeeds maintainer or analyzer triage.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions