From 3e0793af21984978f6bd7998da666949e3899ad5 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 15 Oct 2026 18:08:34 +0200 Subject: [PATCH] Select the creative search query when a result is clicked CreativeModeInventoryScreen.slotClicked moves the search box cursor to the end and sets the highlight to 0 on any click of a display slot, so the next typed character replaces the whole query. Horizon kept the query and appended to it. horizon-ctl's type now edits the creative search as typing does (the selection and the 50 character limit apply) instead of appending. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/clipboard.rs | 6 +++++- crates/horizon-client/src/game.rs | 6 ++++++ crates/horizon-client/src/game/control.rs | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/horizon-client/src/clipboard.rs b/crates/horizon-client/src/clipboard.rs index 2f3d7b002..c21460cdb 100644 --- a/crates/horizon-client/src/clipboard.rs +++ b/crates/horizon-client/src/clipboard.rs @@ -223,6 +223,10 @@ impl AppendSelection { pub fn covers(&self, id: FieldId, value: &str) -> bool { self.0.as_ref().is_some_and(|(i, v)| *i == id && v == value) } + /// Select the whole `value` of field `id`, as Select All does. + pub fn select(&mut self, id: FieldId, value: &str) { + self.0 = Some((id, value.to_owned())); + } /// Before typing or a backspace: an all-selected value is cleared (true). pub fn take(&mut self, id: FieldId, value: &mut String) -> bool { let covered = self.covers(id, value); @@ -247,7 +251,7 @@ impl AppendSelection { let covered = self.covers(id, value); match shortcut { EditShortcut::SelectAll => { - self.0 = Some((id, value.clone())); + self.select(id, value); false } EditShortcut::Copy => { diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 89275beef..e79574e94 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -4375,6 +4375,12 @@ impl Game<'_> { input: horizon_client::menu::Input, ) { use horizon_client::creative::{DisplayClick, click_display}; + if self.creative_screen.tab().search { + // CreativeModeInventoryScreen.slotClicked: moveCursorToEnd, then + // setHighlightPos(0), so typing replaces the whole query. + let search = &self.creative_screen.search; + self.text_selection.select(("creative.search", 0), search); + } let items = self.creative_screen.items(&self.res.names); let first = self.creative_screen.first_row(&self.res.names); let shown = items.get(first * 9 + slot - Creative::DISPLAY); diff --git a/crates/horizon-client/src/game/control.rs b/crates/horizon-client/src/game/control.rs index f604ca7d8..51e5379f1 100644 --- a/crates/horizon-client/src/game/control.rs +++ b/crates/horizon-client/src/game/control.rs @@ -425,8 +425,8 @@ impl Game<'_> { self.recipe_text(Some(text), false) } Screen::Creative if self.creative_screen.tab().search => { - self.creative_screen.search.push_str(text); - self.creative_screen.scroll = 0.0; + // As typed: replaces a selected query, keeps the length limit. + self.creative_search_edit(Some(text), false) } _ => { return Err(