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:
9 files changed
+357
-33
No files matched your search
@@ -98,6 +98,77 @@ public sealed class EditorSessionTests
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnEditMadeBeforeInsertedFramesWereReadIsSavedOnTheFramesItNamed()
|
||||
{
|
||||
var (session, source) = OpenShort();
|
||||
await using (session)
|
||||
{
|
||||
Assert.True(session.SetExcluded([3], true));
|
||||
Assert.True(await session.FlushAsync());
|
||||
// Two earlier photos are inserted (a download, an import, a scan): the stored exclusion moved with its frame.
|
||||
var frames = session.Content.Frames;
|
||||
InsertEarlier(source, 2);
|
||||
source.Stored = source.Stored with { ExcludedFrames = [5] };
|
||||
source.FailNextSave = new FramesChangedException("frames changed");
|
||||
|
||||
// The editor still shows the frames it read when the user excludes another one.
|
||||
Assert.True(session.SetExcluded([6], true));
|
||||
Assert.True(await session.FlushAsync());
|
||||
|
||||
Assert.Equal(frames.Count + 2, session.Content.Count, "the frames were read again");
|
||||
Assert.SequenceEqual([5, 8], source.Stored.ExcludedFrames);
|
||||
Assert.SequenceEqual([frames[3].Id, frames[6].Id], session.Project.ExcludedFrames.Select(i => session.Content.Frames[i].Id));
|
||||
Assert.True(session.Undo());
|
||||
Assert.SequenceEqual([5], session.Project.ExcludedFrames, "undo steps name the same frames");
|
||||
Assert.True(session.Undo());
|
||||
Assert.Empty(session.Project.ExcludedFrames);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AReadAfterFramesWereInsertedMovesTheOpenProjectWithThem()
|
||||
{
|
||||
var (session, source) = OpenShort();
|
||||
await using (session)
|
||||
{
|
||||
Assert.True(session.SetExcluded([3], true));
|
||||
Assert.True(session.SetHero(4));
|
||||
Assert.True(await session.FlushAsync());
|
||||
InsertEarlier(source, 2);
|
||||
source.Stored = source.Stored with { ExcludedFrames = [5], HeroFrame = 6 };
|
||||
|
||||
await session.ReloadAsync();
|
||||
|
||||
Assert.SequenceEqual([5], session.Project.ExcludedFrames);
|
||||
Assert.Equal(6, session.Project.HeroFrame);
|
||||
Assert.True(session.Undo());
|
||||
Assert.Null(session.Project.HeroFrame);
|
||||
Assert.SequenceEqual([5], session.Project.ExcludedFrames, "the step before Set hero names the same frame");
|
||||
Assert.True(await session.FlushAsync());
|
||||
Assert.SequenceEqual([5], source.Stored.ExcludedFrames);
|
||||
Assert.Null(source.Stored.HeroFrame);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A short sequence without its analysis, whose frame ids are all different (the synthetic ids repeat every 64 frames).</summary>
|
||||
private static (EditorSession Session, FakeSequenceSource Source) OpenShort()
|
||||
{
|
||||
var sequence = EditorFixture.Sequence(12);
|
||||
var content = EditorFixture.Content(sequence, deep: false);
|
||||
var source = new FakeSequenceSource(sequence, content);
|
||||
return (new EditorSession(source, content, [], TimeSpan.FromMilliseconds(20)), source);
|
||||
}
|
||||
|
||||
/// <summary>Photos captured before the first frame join the source's sequence, as an insertion renumbers it.</summary>
|
||||
private static void InsertEarlier(FakeSequenceSource source, int count)
|
||||
{
|
||||
var first = source.Content.Frames[0];
|
||||
var early = Enumerable.Range(0, count).Select(i => first with { Id = Guid.CreateVersion7(), CapturedAt = first.CapturedAt!.Value.AddMinutes(i - count) });
|
||||
IReadOnlyList<Frame> frames = [.. early.Concat(source.Content.Frames).Select((f, i) => f with { Index = i })];
|
||||
source.Content = source.Content with { Frames = frames, Light = LightAnalyzer.Analyze(frames) };
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AFailedSaveStaysPendingUntilItIsStored()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user