diff --git a/Changelog/2026-10-04-nav-panel-scroll-fix.md b/Changelog/2026-10-04-nav-panel-scroll-fix.md new file mode 100644 index 0000000..c2f31e3 --- /dev/null +++ b/Changelog/2026-10-04-nav-panel-scroll-fix.md @@ -0,0 +1,27 @@ +# Engine — Nav panel waypoint list no longer jumps while editing + +**Date:** 2026-10-04 +**Branch:** `SK-local` +**Ships in:** next installer release (2026.10.4.8; previous 2026.10.4.7) + +## Fixed +- **Nav panel (Avalonia "Nav" tab, `UI/Panels/NavPanel.cs`): the waypoint list kept scrolling + back to the top, so points could not be selected or deleted.** + - Cause: the 1-second poll timer rebuilt the entire panel every tick, including a brand-new + waypoint `ScrollViewer`, so its scroll offset reset to 0 once a second. A rebuild that landed + between mouse press and release also dropped the click on a row or its X button. + - The waypoint `ScrollViewer` (and its row stack) is now created once and only refilled on + rebuild; the scroll offset is saved and re-applied (immediately and after layout). + - The poll only rebuilds when the plugin's nav JSON actually changed. + - The poll does not rebuild while the mouse is over the waypoint list; the change is picked up + on the first poll after the pointer leaves. + - Rebuilds caused by your own edits (optimistic local updates) always resync on the next poll, + so a command the plugin rejected can't leave stale state on screen. + +## Not changed +- The ImGui Navigation window in the RynthAi plugin (`LegacyNavigationUi`) did not have this + problem (ImGui keeps the list-box scroll position itself). + +## Build +- `RynthCore.Engine`: `dotnet build -c Release` and NativeAOT `dotnet publish -c Release` succeed; + no new warnings. The engine version is stamped by the release build (`-p:Version=yyyy.m.d.n`). diff --git a/src/RynthCore.Engine/UI/Panels/NavPanel.cs b/src/RynthCore.Engine/UI/Panels/NavPanel.cs index 521560f..b1d9c11 100644 --- a/src/RynthCore.Engine/UI/Panels/NavPanel.cs +++ b/src/RynthCore.Engine/UI/Panels/NavPanel.cs @@ -229,9 +229,29 @@ internal static class NavPanel { e.Handled = true; picker.Close(); } }; + // Waypoint list controls live for the panel's lifetime. Rebuild() only refills + // waypointStack: a ScrollViewer recreated (or given a new Content) resets its + // offset to the top, which made the list jump back every poll and impossible to edit. + var waypointStack = new StackPanel { Spacing = 1 }; + var waypointScroll = new ScrollViewer + { + VerticalScrollBarVisibility = Avalonia.Controls.Primitives.ScrollBarVisibility.Auto, + HorizontalScrollBarVisibility = Avalonia.Controls.Primitives.ScrollBarVisibility.Disabled, + Content = waypointStack, + }; + var waypointHost = new Border { Height = 200, Child = waypointScroll }; + + // Last plugin JSON the panel was built from. A rebuild from a user action + // (optimistic local edit) clears it so the next poll always resyncs with the plugin. + string lastJson = string.Empty; + bool rebuildFromPoll = false; + void Rebuild() { + if (!rebuildFromPoll) lastJson = string.Empty; + Vector keepOffset = waypointScroll.Offset; content.Children.Clear(); + waypointStack.Children.Clear(); var d = state.Data; bool navActive = d.MacroRunning && d.NavigationEnabled; @@ -403,7 +423,6 @@ internal static class NavPanel FontSize = 10, }); - var waypointStack = new StackPanel { Spacing = 1 }; for (int i = 0; i < d.Points.Count; i++) { int ci = i; @@ -482,27 +501,29 @@ internal static class NavPanel waypointStack.Children.Add(row); } - content.Children.Add(new Border - { - Height = 200, - Child = new ScrollViewer - { - VerticalScrollBarVisibility = Avalonia.Controls.Primitives.ScrollBarVisibility.Auto, - HorizontalScrollBarVisibility = Avalonia.Controls.Primitives.ScrollBarVisibility.Disabled, - Content = waypointStack, - }, - }); + content.Children.Add(waypointHost); // same instance every rebuild — keeps scroll offset + // Re-apply after layout too: the re-attach / new row extent can coerce it to 0. + waypointScroll.Offset = keepOffset; + Dispatcher.UIThread.Post(() => waypointScroll.Offset = keepOffset, DispatcherPriority.Loaded); } // ── Poll timer ──────────────────────────────────────────────────────── + // Rebuilds only when the plugin's nav state actually changed, and never while the + // pointer is over the waypoint list (a rebuild between press and release eats the + // click on X / row select). Skipped polls leave lastJson alone, so the change is + // picked up on the first poll after the pointer leaves. var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) }; timer.Tick += (_, _) => { if (_getNavJson == null) TryBind(); if (picker.ActivePicker != null) return; - if (!TryFetch(out var fresh)) return; + if (waypointHost.IsPointerOver) return; + if (!TryFetch(out var fresh, out string json)) return; + if (json == lastJson) return; state.Data = fresh; - Rebuild(); + rebuildFromPoll = true; + try { Rebuild(); } finally { rebuildFromPoll = false; } + lastJson = json; }; timer.Start(); // Stop with the visual tree — a running DispatcherTimer roots the closed @@ -580,19 +601,23 @@ internal static class NavPanel } } - private static bool TryFetch(out Payload payload) + /// Polls the plugin's nav JSON. is the raw text, used by + /// the poll timer to skip rebuilding the panel when nothing changed. + private static bool TryFetch(out Payload payload, out string json) { payload = new Payload(); + json = string.Empty; if (_getNavJson == null) return false; try { IntPtr ptr = _getNavJson(); if (ptr == IntPtr.Zero) return false; - string? json = Marshal.PtrToStringAnsi(ptr); - if (string.IsNullOrEmpty(json)) return false; - var parsed = JsonSerializer.Deserialize(json, NavPanelJsonContext.Default.Payload); + string? raw = Marshal.PtrToStringAnsi(ptr); + if (string.IsNullOrEmpty(raw)) return false; + var parsed = JsonSerializer.Deserialize(raw, NavPanelJsonContext.Default.Payload); if (parsed == null) return false; payload = parsed; + json = raw; return true; } catch { return false; }