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

@@ -167,6 +167,47 @@ public sealed class ProjectSettingsTests
Assert.Null(ProjectSettings.MoveFramePositions("""{ "heroFrame": 1, "HeroFrame": 1 }""", new Dictionary<int, int> { [1] = 2 }));
}
[Test]
public void AnEditorsPositionsFollowFramesInsertedUnderItAsTheIndexMovedTheStoredOnes()
{
// An editor read four frames; a download then inserted two earlier photos, one of which an exclusion waited for.
var photos = Enumerable.Range(0, 6).Select(Photo).ToList();
var ids = Enumerable.Range(0, 6).Select(_ => Guid.CreateVersion7()).ToList();
IReadOnlyList<Guid> before = ids[2..];
var after = ids.Select((id, i) => new Titano.Core.Model.Frame
{
Id = id,
SequenceId = Guid.Empty,
Index = i,
RelativePath = $"s/IMG_{i}.JPG",
FileName = $"IMG_{i}.JPG",
Sha256 = photos[i].Sha256,
Size = photos[i].Size,
CapturedAt = photos[i].CapturedAt,
}).ToList();
var project = new ProjectSettings
{
ExcludedFrames = [1, 3],
HeroFrame = 0,
Camera = new CameraSettings { Keyframes = [new CameraKey(2, 0.5, 0.5, 1, 0)] },
Exposure = new ExposureSettings { DeflickerWindow = new Auto<int>().WithManual(41) },
PendingFrames = [new PendingFrame { Sha256 = photos[1].Sha256, Size = photos[1].Size, Excluded = true }],
};
var followed = ProjectSettings.FromJson(Assert.NotNull(ProjectSettings.FollowFrames(project.ToJson(), before, after)));
Assert.SequenceEqual([1, 3, 5], followed.ExcludedFrames);
Assert.Equal(2, followed.HeroFrame);
Assert.SequenceEqual([4], followed.Camera.Keyframes.Select(k => k.Frame));
Assert.Equal(41, followed.Exposure.DeflickerWindow.Manual);
Assert.Null(followed.PendingFrames);
// The same frames: nothing moves. A frame the editor read that is gone: positions stay, as the index leaves them.
Assert.Null(ProjectSettings.FollowFrames(new ProjectSettings { ExcludedFrames = [1] }.ToJson(), ids, after));
var removed = after.Where(f => f.Id != ids[3]).Select((f, i) => f with { Index = i }).ToList();
Assert.Null(ProjectSettings.FollowFrames(new ProjectSettings { ExcludedFrames = [1, 3] }.ToJson(), before, removed));
}
[Test]
public void PositionsCrossToAnotherCopyByPhotoAndWaitForPhotosItLacks()
{