Skip to content

Commit

Permalink
Update to 0.19 (#100)
Browse files Browse the repository at this point in the history
* Update binaries.

* Migrate to 0.19.1

* Update version.
  • Loading branch information
SebastianStehle authored Jul 11, 2024
1 parent ec06bcf commit 14bc13d
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

env:
YRS_REPO: https://github.com/y-crdt/y-crdt
YRS_BRANCH: release-v0.18.8
YRS_BRANCH: release-v0.19.1
CARGO_TERM_COLOR: always

jobs:
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>0.4.0</Version>
<Version>0.4.1</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
Expand Down
29 changes: 29 additions & 0 deletions Tests/YDotNet.Tests.Unit/Maps/InsertTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,35 @@ public void InsertDifferentTypeOnExistingKey()
Assert.That(length, Is.EqualTo(expected: 1));
}

[Test]
public void InsertNestedMap()
{
// Arrange
var doc = new Doc();
var map = doc.Map("map");

// Act
var transaction = doc.WriteTransaction();

var innerMap = Input.Map(new Dictionary<string, Input>
{
{ "text", Input.String("Nested data") }
});

var outerMap = Input.Map(new Dictionary<string, Input>
{
{ "innerMap", innerMap }
});

map.Insert(transaction, "outerMap", outerMap);
var length = map.Length(transaction);

transaction.Commit();

// Assert
Assert.That(length, Is.EqualTo(expected: 1));
}

private (Doc, Map) ArrangeDoc()
{
var doc = new Doc();
Expand Down
31 changes: 31 additions & 0 deletions Tests/YDotNet.Tests.Unit/UndoManagers/AddScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,35 @@ public void StartsTrackingAfterAddingScope()
// Assert
Assert.That(undoEvent, Is.Not.Null);
}

[Test]
public void StartsTrackingAfterAddingScopeWithoutDefaultScope()
{
// Arrange
var doc = new Doc();
var array = doc.Array("array");
var undoManager = new UndoManager(doc, new UndoManagerOptions { CaptureTimeoutMilliseconds = 0 });

UndoEvent? undoEvent = null;
undoManager.ObserveAdded(e => undoEvent = e);

// Act
undoEvent = null;
var transaction = doc.WriteTransaction();
array.InsertRange(transaction, index: 0, new[] { Input.Long(value: 2469L) });
transaction.Commit();

// Assert
Assert.That(undoEvent, Is.Null);

// Act
undoEvent = null;
undoManager.AddScope(array);
transaction = doc.WriteTransaction();
array.InsertRange(transaction, index: 1, new[] { Input.Boolean(value: false) });
transaction.Commit();

// Assert
Assert.That(undoEvent, Is.Not.Null);
}
}
25 changes: 21 additions & 4 deletions YDotNet/Document/UndoManagers/UndoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,23 @@ public class UndoManager : UnmanagedResource
private readonly EventSubscriber<UndoEvent> onAdded;
private readonly EventSubscriber<UndoEvent> onPopped;

/// <summary>
/// Initializes a new instance of the <see cref="UndoManager" /> class without a scope.
/// </summary>
/// <param name="doc">The <see cref="Doc" /> to operate over.</param>
/// <param name="options">The options to initialize the <see cref="UndoManager" />.</param>
public UndoManager(Doc doc, UndoManagerOptions? options = null)
: this(doc, null, options)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="UndoManager" /> class.
/// </summary>
/// <param name="doc">The <see cref="Doc" /> to operate over.</param>
/// <param name="branch">The shared type in the <see cref="Doc" /> to operate over.</param>
/// <param name="branch">The shared type in the <see cref="Doc" /> to operate over. To be added as a default scope..</param>
/// <param name="options">The options to initialize the <see cref="UndoManager" />.</param>
public UndoManager(Doc doc, Branch branch, UndoManagerOptions? options = null)
public UndoManager(Doc doc, Branch? branch, UndoManagerOptions? options = null)
: base(Create(doc, branch, options))
{
onAdded = new EventSubscriber<UndoEvent>(
Expand Down Expand Up @@ -186,10 +196,17 @@ protected override void DisposeCore(bool disposing)
UndoManagerChannel.Destroy(Handle);
}

private static nint Create(Doc doc, Branch branch, UndoManagerOptions? options)
private static nint Create(Doc doc, Branch? branch, UndoManagerOptions? options)
{
var unsafeOptions = MemoryWriter.WriteStruct(options?.ToNative() ?? default);

return UndoManagerChannel.NewWithOptions(doc.Handle, branch.Handle, unsafeOptions.Handle);
var handle = UndoManagerChannel.NewWithOptions(doc.Handle, unsafeOptions.Handle);

if (branch != null)
{
UndoManagerChannel.AddScope(handle, branch.Handle);
}

return handle;
}
}
2 changes: 1 addition & 1 deletion YDotNet/Native/UndoManager/UndoManagerChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static class UndoManagerChannel
ChannelSettings.NativeLib,
CallingConvention = CallingConvention.Cdecl,
EntryPoint = "yundo_manager")]
public static extern nint NewWithOptions(nint doc, nint branch, nint options);
public static extern nint NewWithOptions(nint doc, nint options);

[DllImport(
ChannelSettings.NativeLib,
Expand Down

0 comments on commit 14bc13d

Please sign in to comment.