Skip to content

Commit

Permalink
fix: use pointers to read the event data manually instead of receivin…
Browse files Browse the repository at this point in the history
…g it in the callback
  • Loading branch information
LSViana committed Dec 3, 2023
1 parent af217a1 commit d36f1c4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 3 additions & 2 deletions YDotNet/Document/UndoManagers/UndoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using YDotNet.Document.UndoManagers.Events;
using YDotNet.Infrastructure;
using YDotNet.Native.UndoManager;
using YDotNet.Native.UndoManager.Events;

namespace YDotNet.Document.UndoManagers;

Expand Down Expand Up @@ -31,7 +32,7 @@ public UndoManager(Doc doc, Branch branch, UndoManagerOptions? options = null)
(_, action) =>
{
UndoManagerChannel.ObserveAddedCallback callback =
(_, undoEvent) => action(new UndoEvent(undoEvent));
(_, handle) => action(new UndoEvent(MemoryReader.ReadStruct<UndoEventNative>(handle)));
return (UndoManagerChannel.ObserveAdded(Handle, nint.Zero, callback), callback);
},
Expand All @@ -43,7 +44,7 @@ public UndoManager(Doc doc, Branch branch, UndoManagerOptions? options = null)
(_, action) =>
{
UndoManagerChannel.ObservePoppedCallback callback =
(_, undoEvent) => action(new UndoEvent(undoEvent));
(_, handle) => action(new UndoEvent(MemoryReader.ReadStruct<UndoEventNative>(handle)));
return (UndoManagerChannel.ObservePopped(Handle, nint.Zero, callback), callback);
},
Expand Down
5 changes: 2 additions & 3 deletions YDotNet/Native/UndoManager/UndoManagerChannel.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System.Runtime.InteropServices;
using YDotNet.Native.UndoManager.Events;

namespace YDotNet.Native.UndoManager;

internal static class UndoManagerChannel
{
public delegate void ObserveAddedCallback(nint state, UndoEventNative undoEvent);
public delegate void ObserveAddedCallback(nint state, nint eventHandle);

public delegate void ObservePoppedCallback(nint state, UndoEventNative undoEvent);
public delegate void ObservePoppedCallback(nint state, nint eventHandle);

[DllImport(
ChannelSettings.NativeLib,
Expand Down

0 comments on commit d36f1c4

Please sign in to comment.