[PR #7455] [MERGED] Closing the inventory clears the keyboard focus #7614

Closed
opened 2026-11-03 07:20:47 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7455
Author: @oxi-does-dev
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: fix-tab-focus


📝 Commits (1)

  • cd18f6c Clear a container's keyboard focus when it closes

📊 Changes

3 files changed (+47 additions, -0 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+6 -0)
📝 crates/horizon-client/src/game/pad_menu.rs (+37 -0)
📝 crates/horizon-client/src/game/remote.rs (+4 -0)

📄 Description

🤖 Opened by oxi-does-dev's AI agent (OpenCode, GLM 5.3), not by oxi-does-dev personally.

Fixes #6432

What broke

With the inventory bound to Tab, opening the inventory works, but closing it leaves a widget focused: the focus ring stays on the recipe-book button (or whatever Tab moved to) as the screen goes away, instead of nothing being focused as in vanilla.

Why

Vanilla's Gui.setScreen runs Screen.clearFocus() on the screen it takes down, before the next frame. Horizon keeps that focus in PadMenu.

AbstractContainerScreen.keyPressed tries super.keyPressed(event) first, so Tab moves the keyboard focus, returns false, and only then does the inventory key match and close the screen. The same press therefore both focuses a widget and closes the screen.

The close itself goes through the remote menu path in single player: remote.rs::remote_key handles KeyE/Escape on Screen::Inventory directly (single player runs on the server thread), so it never reached close_container, and nothing cleared the focus. The stale focus then stayed in pad status after the screen was already playing.

What changed

  • MenuCursor::clear_focus / Game::pad_clear_focus: Screen.clearFocus, dropping the focus, the click origin and the slider edit (ComponentPath.applyFocus(false)).
  • Call it where a container is taken down: close_container, the remote menu teardown remote_close_local (this is the path the reported repro uses, and it also covers a server-closed window and dimension changes), and the Creative screen's two close arms (Escape and the inventory key).
  • Unit test clear_focus_leaves_nothing_focused.

Verification

Real-key repro under Xvfb: inventory bound to key.keyboard.tab, a scratch survival world, Tab to open and Tab to close, read through the control socket.

Before: pad status right after the close reported focus: {"kind": "button", "rect": [229, 98, 20, 18]}, targets: [] while the screen was already playing.

After (two runs): focus: null immediately after the close, with the same trace of the key path.

Check Result
cargo build -p horizon-client --profile fast pass
cargo test -p horizon-client --lib pad_menu 3 passed
cargo clippy -p horizon-client --lib -- -D warnings pass
cargo fmt --all -- --check pass

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/7455 **Author:** [@oxi-does-dev](https://github.com/oxi-does-dev) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix-tab-focus` --- ### 📝 Commits (1) - [`cd18f6c`](https://github.com/horizon-rust/horizon/commit/cd18f6c74f8c33e37ac18c54310b4babbf2d3a5c) Clear a container's keyboard focus when it closes ### 📊 Changes **3 files changed** (+47 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+6 -0) 📝 `crates/horizon-client/src/game/pad_menu.rs` (+37 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+4 -0) </details> ### 📄 Description > 🤖 Opened by oxi-does-dev's AI agent (OpenCode, GLM 5.3), not by oxi-does-dev personally. Fixes #6432 ## What broke With the inventory bound to Tab, opening the inventory works, but closing it leaves a widget focused: the focus ring stays on the recipe-book button (or whatever Tab moved to) as the screen goes away, instead of nothing being focused as in vanilla. ## Why Vanilla's `Gui.setScreen` runs `Screen.clearFocus()` on the screen it takes down, before the next frame. Horizon keeps that focus in `PadMenu`. `AbstractContainerScreen.keyPressed` tries `super.keyPressed(event)` first, so Tab moves the keyboard focus, returns false, and only then does the inventory key match and close the screen. The same press therefore both focuses a widget and closes the screen. The close itself goes through the remote menu path in single player: `remote.rs::remote_key` handles KeyE/Escape on `Screen::Inventory` directly (single player runs on the server thread), so it never reached `close_container`, and nothing cleared the focus. The stale focus then stayed in `pad status` after the screen was already `playing`. ## What changed - `MenuCursor::clear_focus` / `Game::pad_clear_focus`: `Screen.clearFocus`, dropping the focus, the click origin and the slider edit (`ComponentPath.applyFocus(false)`). - Call it where a container is taken down: `close_container`, the remote menu teardown `remote_close_local` (this is the path the reported repro uses, and it also covers a server-closed window and dimension changes), and the Creative screen's two close arms (Escape and the inventory key). - Unit test `clear_focus_leaves_nothing_focused`. ## Verification Real-key repro under Xvfb: inventory bound to `key.keyboard.tab`, a scratch survival world, Tab to open and Tab to close, read through the control socket. Before: `pad status` right after the close reported `focus: {"kind": "button", "rect": [229, 98, 20, 18]}, targets: []` while the screen was already `playing`. After (two runs): `focus: null` immediately after the close, with the same trace of the key path. | Check | Result | | --- | --- | | `cargo build -p horizon-client --profile fast` | pass | | `cargo test -p horizon-client --lib pad_menu` | 3 passed | | `cargo clippy -p horizon-client --lib -- -D warnings` | pass | | `cargo fmt --all -- --check` | pass | --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 07:20:47 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#7614
No description provided.