Merge pull request #1123 from ludovic111/fix/book-title-edit-box

🤖 Agent: merged. Verify passes. Local integration of #1121–#1125 on main 2d586fac: parity --changed, all 101 affected harnesses pass. Screenshots in the body.
This commit is contained in:
Ludovic Marie
2026-10-22 02:59:54 +02:00
committed by GitHub
5 changed files with 47 additions and 20 deletions
+1 -1
View File
@@ -8980,7 +8980,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),
+15 -10
View File
@@ -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);
+22
View File
@@ -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<KeyCode> {
"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<KeyCode> {
"f3" => KeyCode::F3,
"f4" => KeyCode::F4,
"f5" => KeyCode::F5,
"f6" => KeyCode::F6,
"f11" => KeyCode::F11,
"slash" | "/" => KeyCode::Slash,
"backspace" => KeyCode::Backspace,
+1 -1
View File
@@ -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,
+8 -8
View File
@@ -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,