fix(chat): the tell prefill leaves the caret after the prefix, not before it

Clicking a name filled the entry with "@tell Name, " correctly but parked the
caret at column 0, so the player had to click the chat bar to get behind their
own prefix before typing — which defeats most of the point of the affordance.

Self-inflicted in d32ef388. SetText already places the caret at the end, and I
stacked an explicit "move to the end" on top of it. MoveCaret takes a DELTA, so
int.MaxValue overflowed _caret + delta to negative and the clamp landed at
column 0. The redundant call was not merely redundant; it was the bug.

Removing it is the whole fix. The test now pins CaretPos as well as the text,
and reintroducing the call reproduces the reported symptom exactly (expected
11, actual 0).

Solution builds clean; full hermetic gate green.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-08-21 08:00:43 +02:00
parent d32ef388f0
commit 78bf62c80e
2 changed files with 11 additions and 1 deletions

View file

@ -855,8 +855,12 @@ public sealed class ChatWindowController : IRetainedWindowStateController, IReta
/// <summary>Aims the chat entry at <paramref name="name"/> and focuses it.</summary>
internal void StartTell(string name)
{
// SetText already places the caret at the end. An explicit "move to
// the end" on top of it is not merely redundant: MoveCaret takes a
// DELTA, so int.MaxValue overflows _caret + delta to negative and the
// clamp lands the caret at column 0 — the player then has to click the
// bar to get behind their own prefix.
Input.SetText($"@tell {name}, ");
Input.MoveCaret(int.MaxValue);
FindRootOf(Input)?.SetKeyboardFocus(Input);
}

View file

@ -175,6 +175,12 @@ public class ChatWindowControllerTests
ctrl!.StartTell("Dww");
Assert.Equal("@tell Dww, ", ctrl.Input.Text);
// ...and the caret sits AFTER the prefix, ready to type into. It landed
// at column 0 in the first cut because an explicit MoveCaret(int.MaxValue)
// was stacked on top of SetText, which already ends there — MoveCaret
// takes a delta, so that overflowed negative and clamped to zero.
Assert.Equal("@tell Dww, ".Length, ctrl.Input.CaretPos);
}
// ── Talk-focus specials: "Tell to X" / "Squelch (ignore) X" ─────────────