From e6c1a91a6549d6fb3128f95ae5b7c88dba4a4e6d Mon Sep 17 00:00:00 2001 From: masa-masa-0314 <348336850+masa-masa-0314@users.noreply.github.com> Date: Wed, 28 Oct 2026 00:53:07 +0800 Subject: [PATCH] creative: rebuild the search state when the screen opens CreativeModeInventoryScreen is a fresh screen per open (init() makes a new search box and a zeroed scrollbar; only selectedTab is static), but Horizon keeps one Creative for the game's lifetime, so the last search stayed in the box after closing the inventory. Clear the box, refocus it on the search tab and reset the scrollbar at both open paths (local and remote). Fixes #2873. Co-Authored-By: ZCode --- crates/horizon-client/src/creative.rs | 13 +++++++++++++ crates/horizon-client/src/game.rs | 9 +++++---- crates/horizon-client/src/game/remote.rs | 9 +++++---- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/crates/horizon-client/src/creative.rs b/crates/horizon-client/src/creative.rs index 1a227db65..36cc34362 100644 --- a/crates/horizon-client/src/creative.rs +++ b/crates/horizon-client/src/creative.rs @@ -355,6 +355,19 @@ impl Creative { pub fn search_items(&self) -> &[ItemStack] { &self.search_items } + /// Opening the screen: vanilla rebuilds CreativeModeInventoryScreen, whose + /// init() makes a fresh search box and a zeroed scrollbar; only the tab + /// persists (its static selectedTab). selectTab on the reopened screen + /// takes the oldTab != tab branch, so it empties and refocuses the box. + pub fn reopen(&mut self) { + self.search.set_value(""); + self.release(); + self.scroll = 0.0; + self.search.focused = self.tab().search; + if self.search.focused { + self.search.reset_blink(); + } + } /// Indices into `search_items` that CreativeModeInventoryScreen.refreshSearchResults /// shows for `term`: the whole tab when empty, the tag tree after `#`, else /// the name tree, both over vanilla's suffix arrays (substring matches, diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index aa1b03669..7876fb743 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -11784,11 +11784,12 @@ impl Game<'_> { Screen::Playing => { // key.inventory while riding a tamed mount opens its inventory. if !self.open_ridden_mount_menu() { - self.screen = if self.creative { - Screen::Creative + if self.creative { + self.screen = Screen::Creative; + self.creative_screen.reopen(); } else { - Screen::Inventory - }; + self.screen = Screen::Inventory; + } self.capture(false); } } diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 3e79f1437..6c7e8fe08 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -5089,11 +5089,12 @@ impl Game<'_> { KeyCode::KeyE => { // The inventory opens without telling the server. self.recipe_ui.reset_screen(); - self.screen = if self.creative { - Screen::Creative + if self.creative { + self.screen = Screen::Creative; + self.creative_screen.reopen(); } else { - Screen::Inventory - }; + self.screen = Screen::Inventory; + } self.craft_size = 2; self.capture(false); Ok(true)