持ち主の探索結果を構造が変わるまで使い回す
このコミットが含まれているのは:
5ファイル変更
+113
-14
検索条件に一致するファイルはありません
@@ -274,19 +274,100 @@ public sealed class UndoTreeHistoryTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheOwnersAreBuiltOncePerVersionAndRebuiltAfterTheHistoryChanges()
|
||||
public async Task TheOwnersAreKeptWhileOnlyValuesChangeAndRebuiltWhenTheStructureChanges()
|
||||
{
|
||||
var (manager, document) = Histories.NewDocument();
|
||||
using var history = Track(manager, document);
|
||||
var part = new Part("p");
|
||||
Histories.Edit(manager, () => document.Parts.Add(part));
|
||||
|
||||
var first = history.Owners;
|
||||
|
||||
Assert.Same(first, history.Owners);
|
||||
Assert.Equal([document], first.OwnersOf(part));
|
||||
|
||||
Histories.Edit(manager, () => document.X = 1);
|
||||
Histories.Edit(manager, () => part.Value = 2);
|
||||
|
||||
Assert.Same(first, history.Owners);
|
||||
|
||||
var other = new Part("q");
|
||||
Histories.Edit(manager, () => document.Parts.Add(other));
|
||||
var second = history.Owners;
|
||||
|
||||
Assert.NotSame(first, second);
|
||||
Assert.Equal([document], second.OwnersOf(other));
|
||||
|
||||
await manager.UndoAsync();
|
||||
var third = history.Owners;
|
||||
|
||||
Assert.NotSame(second, third);
|
||||
Assert.Empty(third.OwnersOf(other));
|
||||
|
||||
await manager.UndoAsync();
|
||||
|
||||
Assert.Same(third, history.Owners);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReplacingAListOrAChildObjectRebuildsTheOwners()
|
||||
{
|
||||
var (manager, sheet) = Histories.NewSheet();
|
||||
using var history = Track(manager, sheet);
|
||||
var part = new Part("p");
|
||||
Histories.Edit(manager, () => sheet.Parts = sheet.Parts.Add(part));
|
||||
var first = history.Owners;
|
||||
|
||||
Histories.Edit(manager, () => sheet.X = 1);
|
||||
|
||||
Assert.Same(first, history.Owners);
|
||||
Assert.Equal([sheet], first.OwnersOf(part));
|
||||
|
||||
var replacement = new Part("r");
|
||||
Histories.Edit(manager, () => sheet.Parts = [replacement]);
|
||||
|
||||
Assert.NotSame(first, history.Owners);
|
||||
Assert.Equal([sheet], history.Owners.OwnersOf(replacement));
|
||||
Assert.Empty(history.Owners.OwnersOf(part));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task JumpingAcrossAStructuralStepRebuildsTheOwnersButNotAcrossValueSteps()
|
||||
{
|
||||
var (manager, document) = Histories.NewDocument();
|
||||
using var history = Track(manager, document);
|
||||
var root = history.Cursor;
|
||||
var part = new Part("p");
|
||||
Histories.Edit(manager, () => document.Parts.Add(part));
|
||||
var added = history.Cursor;
|
||||
Histories.Edit(manager, () => document.X = 1);
|
||||
var edited = history.Cursor;
|
||||
var owners = history.Owners;
|
||||
|
||||
await history.JumpAsync(added);
|
||||
|
||||
Assert.Same(owners, history.Owners);
|
||||
|
||||
await history.JumpAsync(root);
|
||||
|
||||
Assert.NotSame(owners, history.Owners);
|
||||
Assert.Empty(history.Owners.OwnersOf(part));
|
||||
|
||||
var afterRoot = history.Owners;
|
||||
await history.JumpAsync(edited);
|
||||
|
||||
Assert.NotSame(afterRoot, history.Owners);
|
||||
Assert.Equal([document], history.Owners.OwnersOf(part));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClearingTheManagerDropsTheOwners()
|
||||
{
|
||||
var (manager, document) = Histories.NewDocument();
|
||||
using var history = Track(manager, document);
|
||||
var part = new Part("p");
|
||||
Histories.Edit(manager, () => document.Parts.Add(part));
|
||||
var first = history.Owners;
|
||||
|
||||
manager.Clear();
|
||||
manager.Subscribe(document);
|
||||
|
||||
Assert.NotSame(first, history.Owners);
|
||||
}
|
||||
|
||||
@@ -77,9 +77,15 @@ internal sealed class UndoRedoCommandView
|
||||
_ => Command.GetType().Name,
|
||||
};
|
||||
var detail = Kind is CommandKind.Property or CommandKind.Indexer && IsReadable ? $"{TextOf(OldValue)} → {TextOf(NewValue)}" : string.Empty;
|
||||
return new UndoTreeCommandInfo(Kind, Target, targetLabel, member, detail, Key);
|
||||
return new UndoTreeCommandInfo(Kind, Target, targetLabel, member, detail, Key, ChangesOwnership);
|
||||
}
|
||||
|
||||
bool ChangesOwnership => Kind is CommandKind.Property or CommandKind.Indexer
|
||||
? !IsReadable || HoldsObject(OldValue) || HoldsObject(NewValue)
|
||||
: true;
|
||||
|
||||
static bool HoldsObject(object? value) => value is not null and not string && !value.GetType().IsValueType;
|
||||
|
||||
static UndoRedoCommandView ReadValueChange(IUndoRedoCommandBase command, CommandKind kind, string memberField)
|
||||
{
|
||||
var view = new UndoRedoCommandView(command, kind);
|
||||
|
||||
@@ -9,7 +9,7 @@ internal enum CommandKind
|
||||
Other,
|
||||
}
|
||||
|
||||
internal sealed record UndoTreeCommandInfo(CommandKind Kind, object? Target, string TargetLabel, string Member, string Detail, UndoTreeChangeKey? Key)
|
||||
internal sealed record UndoTreeCommandInfo(CommandKind Kind, object? Target, string TargetLabel, string Member, string Detail, UndoTreeChangeKey? Key, bool ChangesOwnership = false)
|
||||
{
|
||||
public string Text => TargetLabel.Length > 0 ? $"{TargetLabel} / {Member}" : Member;
|
||||
}
|
||||
@@ -25,7 +25,6 @@ internal class UndoTreeHistory : IDisposable
|
||||
UndoTreeRecorder? recorder;
|
||||
UndoTreeSaveWatcher? saveWatcher;
|
||||
UndoTreeOwners? owners;
|
||||
long ownersVersion;
|
||||
|
||||
internal UndoTreeHistory(UndoRedoManager manager, AsyncAwaitStatus asyncAwaitStatus, IReadOnlyList<IUndoRedoable> roots, int capacity, UndoRedoManagerReader? reader, Action<Exception>? report = null)
|
||||
{
|
||||
@@ -72,12 +71,7 @@ internal class UndoTreeHistory : IDisposable
|
||||
{
|
||||
get
|
||||
{
|
||||
if (owners is null || ownersVersion != Version)
|
||||
{
|
||||
owners = new UndoTreeOwners(Roots);
|
||||
ownersVersion = Version;
|
||||
}
|
||||
|
||||
owners ??= new UndoTreeOwners(Roots);
|
||||
return owners;
|
||||
}
|
||||
}
|
||||
@@ -482,6 +476,21 @@ internal class UndoTreeHistory : IDisposable
|
||||
redoNodes.Clear();
|
||||
Root = CreateRoot();
|
||||
Cursor = Root;
|
||||
owners = null;
|
||||
}
|
||||
|
||||
void MoveCursor(UndoTreeNodeViewModel next)
|
||||
{
|
||||
if (owners is not null && ChangesOwnershipBetween(Cursor, next))
|
||||
owners = null;
|
||||
|
||||
Cursor = next;
|
||||
}
|
||||
|
||||
bool ChangesOwnershipBetween(UndoTreeNodeViewModel from, UndoTreeNodeViewModel to)
|
||||
{
|
||||
var ancestor = CommonAncestor(from, to);
|
||||
return PathFromRoot(from).Skip(ancestor.Depth + 1).Concat(PathFromRoot(to).Skip(ancestor.Depth + 1)).Any(node => node.ChangesOwnership);
|
||||
}
|
||||
|
||||
bool Merge(IReadOnlyList<object> undo, IReadOnlyList<object> redo)
|
||||
@@ -523,7 +532,7 @@ internal class UndoTreeHistory : IDisposable
|
||||
|
||||
if (!ReferenceEquals(Cursor, node))
|
||||
{
|
||||
Cursor = node;
|
||||
MoveCursor(node);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ internal class UndoTreeNodeViewModel : Bindable
|
||||
Time = time;
|
||||
Visit = visit;
|
||||
Keys = commands.Select(command => command.Key).OfType<UndoTreeChangeKey>().Distinct().ToArray();
|
||||
ChangesOwnership = commands.Any(command => command.ChangesOwnership);
|
||||
}
|
||||
|
||||
public int Id { get; }
|
||||
@@ -31,6 +32,8 @@ internal class UndoTreeNodeViewModel : Bindable
|
||||
|
||||
public IReadOnlyList<UndoTreeChangeKey> Keys { get; }
|
||||
|
||||
public bool ChangesOwnership { get; }
|
||||
|
||||
public string Label { get; }
|
||||
|
||||
public DateTime Time { get; }
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする