fix(ui): spell-bar drag-reorder works — the per-frame rebuild was destroying the dragged cell (#354)
Some checks are pending
Headless portability / portable-headless (ubuntu-latest) (push) Waiting to run
Headless portability / portable-headless (windows-latest) (push) Waiting to run
Headless portability / linux-graphical (push) Waiting to run
Headless portability / linux-vulkan (push) Waiting to run

Everything already existed — the drag payloads, the favorite wire pair
(0x1E3 add-at-position / 0x1E4 remove, byte-confirmed against retail's
Event_AddSpellFavorite @0x006A0F70 and ACE), the insert-shift state
ops. The bug: lifting a favorite fires SpellbookChanged, the next
per-frame Tick rebuilt the bar, the rebuild flushed and recreated
every cell, and UiRoot's subtree-removal safety net canceled the
in-flight drag whose source had just been destroyed — one frame after
every lift, before any drop could land.

The rebuild now defers for the duration of the drag gesture, and the
drop ports retail's own -1-if-lifted-before-target index adjustment
(SpellCastSubMenu::AddFavorite @0x004C7060) so final positions are
byte-identical: insert-shift, not swap; drag-out still deletes (the
lift's removal stands on a missed drop, retail's shape). The
real-pointer-pipeline test fails against the pre-fix code with the
exact cancellation and passes after; a discriminator pins that
physical-item drop handlers reject the spell payload.

AP-172 files the one presentation divergence (mid-drag reflow happens
on release, not continuously) — renumbered from the agent's AP-171
draft, which collided with the same-day double-click row. #354 filed
and closed.

Clean-room complete solution: 11,541 passed / 4 skipped / 0 failed.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-08-08 18:28:47 +02:00
parent 0a996a1a91
commit 81a9d85a1d
5 changed files with 260 additions and 5 deletions

View file

@ -199,6 +199,55 @@ public sealed class SpellbookTests
Assert.Equal(1, book.ActiveCount);
}
/// <summary>
/// #354: retail's SpellCastSubMenu::AddFavorite @ 0x004C7060 reorders a favorite
/// bar by removing the dragged spell from wherever it currently sits, then
/// InsertPos-ing it at the (possibly shifted) target index — never a two-slot
/// swap. Dragging slot 0 onto slot 2 must land it directly BEFORE the spell
/// that was there, shifting everything between one slot toward the vacated gap.
/// </summary>
[Fact]
public void SetFavorite_MovingWithinTheSameBar_InsertShiftsRatherThanSwaps()
{
var book = new Spellbook();
book.SetFavorite(0, 0, 1u);
book.SetFavorite(0, 1, 2u);
book.SetFavorite(0, 2, 3u);
// Drag spell 1 (index 0) onto spell 3's slot (index 2, already adjusted for
// the pre-lift removal by the caller, matching PlayerModule::AddSpellFavorite
// @ 0x005D43E0's InsertPos(list, position, spellId) contract).
book.SetFavorite(0, 1, 1u);
Assert.Equal(new uint[] { 2u, 1u, 3u }, book.GetFavorites(0));
}
[Fact]
public void SetFavorite_MovingToTheEnd_AppendsRatherThanLeavingAGap()
{
var book = new Spellbook();
book.SetFavorite(0, 0, 1u);
book.SetFavorite(0, 1, 2u);
book.SetFavorite(0, 2, 3u);
book.SetFavorite(0, 2, 1u);
Assert.Equal(new uint[] { 2u, 3u, 1u }, book.GetFavorites(0));
}
[Fact]
public void RemoveFavorite_LeavesTheRemainingBarContiguous()
{
var book = new Spellbook();
book.SetFavorite(0, 0, 1u);
book.SetFavorite(0, 1, 2u);
book.SetFavorite(0, 2, 3u);
book.RemoveFavorite(0, 2u);
Assert.Equal(new uint[] { 1u, 3u }, book.GetFavorites(0));
}
[Fact]
public void OnEnchantmentRemoved_FiresEvent()
{