From cb20d7056c9ab2516184ec743cadea3323d17d38 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Wed, 21 Oct 2026 23:56:47 +0200 Subject: [PATCH] Book title: draw Select All's highlight, as BookSignScreen's EditBox The title box is an unbordered, centred EditBox (black, no shadow) in vanilla. Horizon kept Ctrl/Cmd+A's selection but never drew it, and centred the title together with its cursor. Draw it with ui::append_field (now with a text shadow flag): the value centred alone, the cursor after it, and the inverted highlight. horizon-ctl gets the super (Cmd) and F6 key names, and A/C/V/X with the edit modifier held act on the open book. Part of #275 Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game.rs | 2 +- crates/horizon-client/src/game/books.rs | 25 +++++++++++++--------- crates/horizon-client/src/game/control.rs | 22 +++++++++++++++++++ crates/horizon-client/src/game/stations.rs | 2 +- crates/horizon-client/src/ui.rs | 16 +++++++------- 5 files changed, 47 insertions(+), 20 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 82be49ed7..48c58baeb 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -8884,7 +8884,7 @@ impl Game<'_> { atlas, search, (ox + 82.0, oy + 6.0, 80.0), - u32::MAX, + (u32::MAX, true), clipboard::CREATIVE_SEARCH_CHARS, self.text_selection .covers(clipboard::CREATIVE_SEARCH, search), diff --git a/crates/horizon-client/src/game/books.rs b/crates/horizon-client/src/game/books.rs index 8745c6f35..3dd49c005 100644 --- a/crates/horizon-client/src/game/books.rs +++ b/crates/horizon-client/src/game/books.rs @@ -241,7 +241,7 @@ impl Game<'_> { /// Ctrl+A/C/V/X: the title box (an `EditBox` of 15) while signing, else /// the page (`MultilineTextField.insertText`: line breaks kept, cut to /// the 1024 characters left, rejected when it overflows the 14 lines). - fn book_shortcut(&mut self, shortcut: horizon_client::clipboard::EditShortcut) { + pub(super) fn book_shortcut(&mut self, shortcut: horizon_client::clipboard::EditShortcut) { let font = &self.gui.atlas.font; match self.book.as_mut() { Some(BookScreen::Edit { @@ -616,16 +616,21 @@ impl Game<'_> { BLACK, false, ); - let blink = (opened.elapsed().as_millis() / 300) % 2 == 0; - let shown = format!("{title}{}", if blink { "_" } else { " " }); - let tw = HudBatch::text_width(atlas, &shown); - batch.text( + // The title box: an unbordered, centred EditBox of 114 with + // black text and no shadow; the value alone is centred, the + // cursor follows it. + let x = left + 36.0; + let tx = x + ((114.0 - HudBatch::text_width(atlas, title)) / 2.0).floor(); + horizon_client::ui::append_field( + batch, atlas, - &shown, - left + 36.0 + (114.0 - tw) / 2.0, - 50.0, - BLACK, - false, + title, + (tx, 50.0, x + 114.0 - tx), + (BLACK, false), + 15, + self.text_selection.covers(BOOK_TITLE, title), + true, + opened.elapsed().as_millis(), ); let by = tr("book.byAuthor", "by %1$s").replace("%1$s", super::chat::PLAYER_NAME); let tw = HudBatch::text_width(atlas, &by); diff --git a/crates/horizon-client/src/game/control.rs b/crates/horizon-client/src/game/control.rs index 5cdf46110..0d172387d 100644 --- a/crates/horizon-client/src/game/control.rs +++ b/crates/horizon-client/src/game/control.rs @@ -220,6 +220,25 @@ impl Game<'_> { "key" => { let key = key_code(arg(1)?).ok_or_else(|| format!("unknown key {}", words[1]))?; self.require_world()?; + // A held edit modifier (`key super down`) and A/C/V/X: the + // open book's Select All, Copy, Paste or Cut. + if self.book.is_some() && arg(2)? != "up" { + let held = |k: [KeyCode; 2]| k.iter().any(|k| self.keys.contains(k)); + let edit = if cfg!(target_os = "macos") { + held([KeyCode::SuperLeft, KeyCode::SuperRight]) + } else { + held([KeyCode::ControlLeft, KeyCode::ControlRight]) + }; + let name = arg(1)?; + let letter = name.chars().next().filter(|_| name.len() == 1); + let shift = held([KeyCode::ShiftLeft, KeyCode::ShiftRight]); + if let Some(shortcut) = + horizon_client::clipboard::edit_shortcut(letter, edit, shift, false) + { + self.book_shortcut(shortcut); + return ok(); + } + } // KeyboardHandler.keyPress: the debug keys see the physical key first. let physical = key; { @@ -909,6 +928,8 @@ fn key_code(name: &str) -> Option { "space" => KeyCode::Space, "shift" | "lshift" => KeyCode::ShiftLeft, "ctrl" | "control" | "lctrl" => KeyCode::ControlLeft, + // The edit modifier on macOS (Cmd+A selects all there). + "super" | "cmd" | "meta" => KeyCode::SuperLeft, "esc" | "escape" => KeyCode::Escape, "tab" => KeyCode::Tab, "enter" | "return" => KeyCode::Enter, @@ -917,6 +938,7 @@ fn key_code(name: &str) -> Option { "f3" => KeyCode::F3, "f4" => KeyCode::F4, "f5" => KeyCode::F5, + "f6" => KeyCode::F6, "f11" => KeyCode::F11, "slash" | "/" => KeyCode::Slash, "backspace" => KeyCode::Backspace, diff --git a/crates/horizon-client/src/game/stations.rs b/crates/horizon-client/src/game/stations.rs index 536224367..62088138c 100644 --- a/crates/horizon-client/src/game/stations.rs +++ b/crates/horizon-client/src/game/stations.rs @@ -1663,7 +1663,7 @@ impl Game<'_> { atlas, &s.name, (ox + 62.0, oy + 24.0, 103.0), - u32::MAX, + (u32::MAX, true), ANVIL_NAME_CHARS, self.text_selection.covers(ANVIL_NAME, &s.name), false, diff --git a/crates/horizon-client/src/ui.rs b/crates/horizon-client/src/ui.rs index eb1661802..b1ffab866 100644 --- a/crates/horizon-client/src/ui.rs +++ b/crates/horizon-client/src/ui.rs @@ -719,14 +719,14 @@ impl Caret { /// highlight when Select All covers the value (`invert_text` as /// `setInvertHighlightedTextColor`), and the cursor, blinking from when the /// field took the focus (`TextCursorUtils.isCursorVisible`): an underscore, -/// or a bar once the value is `max_chars` long. +/// or a bar once the value is `max_chars` long. `shadow` is `setTextShadow`. #[allow(clippy::too_many_arguments)] pub fn append_field( batch: &mut HudBatch, atlas: &HudAtlas, value: &str, (x, y, width): (f32, f32, f32), - color: u32, + (color, shadow): (u32, bool), max_chars: usize, selected: bool, invert_text: bool, @@ -734,7 +734,7 @@ pub fn append_field( ) { let mut cursor_x = x; if !value.is_empty() { - batch.text(atlas, value, x, y, color, true); + batch.text(atlas, value, x, y, color, shadow); cursor_x += HudBatch::text_width(atlas, value) + 1.0; } let insert = char_len(value) >= max_chars; @@ -750,7 +750,7 @@ pub fn append_field( if insert { batch.fill(atlas, cursor_x, y - 1.0, 1.0, 11.0, color); } else { - batch.text(atlas, "_", cursor_x, y, color, true); + batch.text(atlas, "_", cursor_x, y, color, shadow); } } } @@ -1152,7 +1152,7 @@ mod tests { &atlas, "abc", (10.0, 20.0, 80.0), - u32::MAX, + (u32::MAX, true), 50, true, true, @@ -1170,7 +1170,7 @@ mod tests { &atlas, "abc", (10.0, 20.0, 103.0), - u32::MAX, + (u32::MAX, true), 50, true, false, @@ -1185,7 +1185,7 @@ mod tests { &atlas, "abc", (10.0, 20.0, 103.0), - 0, + (0, true), 50, false, false, @@ -1201,7 +1201,7 @@ mod tests { &atlas, "abc", (10.0, 20.0, 80.0), - u32::MAX, + (u32::MAX, true), 3, false, true,