fix(editor): move a local editor's positions with frames inserted under it

An editor open on a sequence of this PC while earlier photos arrived (a
sync download, an import, a scan) kept its frames and positions in the old
order, while the index moved the stored positions with their frames. The
next edit of exclusions, the hero or keyframes was merged as the editor's
own value and stored in the old order, so other photos were excluded and
the Library's hero and the project's named different frames.

LocalSequenceSource records the frames version it read the frames at (row
and frames read as one state) and refuses a save under the sequence lease
when the row's frames version moved (FramesChangedException); the index
edit also names that version. EditorSession then reads the sequence again
and moves its project, its basis and every undo and redo step the way the
index moved the stored copy (ProjectSettings.FollowFrames: by frame id when
frames were only inserted, otherwise unchanged; waiting photos placed),
and saves in the new order. A read after a job follows the frames the same
way, and saves wait for a read under way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 19:13:55 +00:00
1 parent f2ce806d56
commit 31dea66270
9 files changed
+357 -33

No files matched your search

@@ -1,6 +1,7 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using Titano.Core.Model;
namespace Titano.Core.Project;
@@ -324,6 +325,39 @@ public sealed record ProjectSettings
}
}
/// <summary>
/// A project written against the frames <paramref name="before"/> (frame ids, by index) moved to the frames
/// <paramref name="after"/> (in index order) the way the archive index moves its own copy when it takes them
/// (ProjectPositions in Titano.Data): while every frame of <paramref name="before"/> is still there, its positions
/// move with their frames (<see cref="MoveFramePositions"/>), otherwise they stay; either way pending frames whose
/// photos are now there take their place (<see cref="TranslateFramePositions"/>). An editor that read the frames
/// before frames were inserted saves its edit in the new order this way. Null when nothing changes.
/// </summary>
public static string? FollowFrames(string json, IReadOnlyList<Guid> before, IReadOnlyList<Frame> after)
{
ArgumentNullException.ThrowIfNull(before);
ArgumentNullException.ThrowIfNull(after);
var now = new Dictionary<Guid, int>(after.Count);
for (var i = 0; i < after.Count; i++) now[after[i].Id] = i;
Dictionary<int, int>? moves = [];
for (var i = 0; i < before.Count; i++)
{
if (!now.TryGetValue(before[i], out var index))
{
moves = null;
break;
}
if (index != i) moves[i] = index;
}
var moved = moves is null ? null : MoveFramePositions(json, moves);
var current = moved ?? json;
// Most projects wait for no photo: the frames' photos are gathered only for those that do.
var placed = current.Contains("pendingFrames", StringComparison.OrdinalIgnoreCase)
? TranslateFramePositions(current, null, new FramePhotos(after.Select((f, i) => (i, new FramePhoto(f.Sha256, f.Size, f.CapturedAt)))))
: null;
return placed ?? moved;
}
private static bool Move(JsonNode? position, Action<JsonNode> replace, IReadOnlyDictionary<int, int> moves)
{
if (position is not JsonValue value || !value.TryGetValue<int>(out var old) || !moves.TryGetValue(old, out var now) || now == old) return false;