Merge task: UI polish: ListBox Padding scroll clip, 4s log rebuild, ClassifyItems side effects

This commit is contained in:
mika kuns
2026-08-11 18:34:36 +02:00
6 changed files with 303 additions and 13 deletions
@@ -529,10 +529,11 @@ public sealed partial class TasksIslandViewModel : ViewModelBase, IDisposable
}
// Builds the hierarchy-aware flat ordering (top-level rows interleaved with visible children,
// orphans flagged so they render flat) and classifies it into Overdue/Open/Completed, exactly
// as Regroup renders it. Shared with callers that need "every completed row" independent of
// Rows/IsShowingCompleted (e.g. ClearCompletedAsync).
private (List<TaskRowViewModel> Overdue, List<TaskRowViewModel> Open, List<TaskRowViewModel> Completed) ClassifyItems()
// orphans flagged so they render flat) and partitions it into Overdue/Open/Completed. Pure
// with respect to chain state (ShowAsChainMember/ChainStep/ChainAfterLabel) — callers that
// only need section membership/counts (e.g. ClearCompletedAsync) should use this directly
// rather than ClassifyItems, which additionally mutates every row via ApplyChainGrouping.
private (List<TaskRowViewModel> Overdue, List<TaskRowViewModel> Open, List<TaskRowViewModel> Completed) PartitionItems()
{
// Items is already ordered by SortOrder from the DB query.
// Treat rows whose ParentTaskId is not in the current view as orphans -> top-level.
@@ -580,6 +581,17 @@ public sealed partial class TasksIslandViewModel : ViewModelBase, IDisposable
open.Add(r);
}
return (overdue, open, completed);
}
// ClassifyItems layers the chain-grouping mutation on top of PartitionItems, exactly as
// Regroup renders it — every row in the result has ShowAsChainMember/ChainStep/ChainAfterLabel
// written. Only call this from a path that actually renders the result; a caller that just
// needs section membership (e.g. a count) should call PartitionItems instead.
private (List<TaskRowViewModel> Overdue, List<TaskRowViewModel> Open, List<TaskRowViewModel> Completed) ClassifyItems()
{
var (overdue, open, completed) = PartitionItems();
// Dependency chains are resolved and pulled together per section (not on the
// pre-split `flat` list): a chain head might land in a different section than its
// dependent (e.g. a Done head in Completed, an open dependent in Open) — in that case
@@ -965,7 +977,7 @@ public sealed partial class TasksIslandViewModel : ViewModelBase, IDisposable
[RelayCommand]
private async Task ClearCompletedAsync()
{
var (_, _, completed) = ClassifyItems();
var (_, _, completed) = PartitionItems();
if (completed.Count == 0) return;
// Delete children before parents so the parent-child FK (Restrict) doesn't
@@ -54,8 +54,8 @@ public sealed partial class LogVisualizerViewModel : ViewModelBase
[RelayCommand]
public async Task RefreshAsync()
{
_all = await _worker.GetRecentLogsAsync();
Apply();
var latest = await _worker.GetRecentLogsAsync();
Reconcile(latest);
}
partial void OnWarnErrorOnlyChanged(bool value) => Apply();
@@ -68,10 +68,70 @@ public sealed partial class LogVisualizerViewModel : ViewModelBase
: _all;
foreach (var e in items.Reverse())
Rows.Add(new LogVisualizerRow(e.TimestampUtc.ToLocalTime().ToString("HH:mm:ss"), e.Message, e.Level));
UpdateStatusText();
}
// `_all` (oldest-first) mirrors the worker's LogRingBuffer: append-mostly, with the oldest
// entries falling off the front once they age past the 30-min window. A full Rows.Clear()
// on every 4s tick would reset the user's scroll position/selection while they're mid-read,
// so patch just the delta instead: entries still present keep their row, aged-out entries
// are trimmed off the (oldest) tail of Rows, new entries are inserted at the (newest) head.
private void Reconcile(IReadOnlyList<WorkerLogEntry> latest)
{
var previous = _all;
_all = latest;
if (previous.Count == 0)
{
Apply();
return;
}
var overlap = FindOverlap(previous, latest);
var evictedCount = previous.Count - overlap;
var added = latest.Skip(overlap).ToList();
if (evictedCount == 0 && added.Count == 0)
return; // nothing aged out, nothing new — leave Rows (and scroll/selection) untouched
if (evictedCount > 0)
{
var removeCount = WarnErrorOnly
? previous.Take(evictedCount).Count(e => e.Level is WorkerLogLevel.Warn or WorkerLogLevel.Error)
: evictedCount;
for (var i = 0; i < removeCount; i++)
Rows.RemoveAt(Rows.Count - 1);
}
foreach (var e in added)
{
if (WarnErrorOnly && e.Level is not (WorkerLogLevel.Warn or WorkerLogLevel.Error))
continue;
Rows.Insert(0, new LogVisualizerRow(e.TimestampUtc.ToLocalTime().ToString("HH:mm:ss"), e.Message, e.Level));
}
UpdateStatusText();
}
// The longest run of `previous`'s tail that reappears as `latest`'s head — i.e. how much of
// the old snapshot survived unevicted. 0 when nothing overlaps (e.g. right after opening).
private static int FindOverlap(IReadOnlyList<WorkerLogEntry> previous, IReadOnlyList<WorkerLogEntry> latest)
{
for (var k = Math.Min(previous.Count, latest.Count); k > 0; k--)
{
var matches = true;
for (var i = 0; i < k; i++)
{
if (!previous[previous.Count - k + i].Equals(latest[i])) { matches = false; break; }
}
if (matches) return k;
}
return 0;
}
private void UpdateStatusText() =>
StatusText = Rows.Count == 0
? Loc.T("modals.logVisualizer.empty")
: Loc.T("modals.logVisualizer.count", Rows.Count);
}
[RelayCommand]
private void Close()