Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UndoManager #40

Merged
merged 11 commits into from
Mar 5, 2024
Merged

UndoManager #40

merged 11 commits into from
Mar 5, 2024

Conversation

Horusiath
Copy link
Contributor

@Horusiath Horusiath commented Feb 23, 2024

This PR is determined to provide a minimal implementation of UndoManager and expose it to the user API.

It's still work in progress.

/cc @embirico

@Horusiath Horusiath requested review from heckj and nugmanoff February 23, 2024 10:02
Copy link
Collaborator

@heckj heckj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking forward to seeing how you use the YUndoManager from the Swift side - what sequence calls need to be ordered, and how you wrap changes. All looks good here - mentioned Origin as a hard (opaque) type might be easier, but it totally works as an existential type as you've set it here too.

Sources/YSwift/Protocols.swift Outdated Show resolved Hide resolved
@embirico
Copy link

embirico commented Mar 1, 2024

Great stuff. I think the API makes sense to me.

My only question as far as usage goes:
If we have a block-based editor with a few NSTextViews tracking a few root-level YTexts, would we be able to / would it make sense to create YUndoManagers on demand, each tracking a single YText?

Probably obvious, but would be great to also have a test like test_undoLocalChangeAfterRemoteEdits, as that's really the main use case here. In Multi we currently use a native Swift UndoManager in NSTextViews that are connected to YSwift. We leave the UndoManager enabled as long as the local edit is the most recent change, but we have to disable it as soon as any more recent remote edits come in.

Let us know how we can help @Horusiath!

@Horusiath
Copy link
Contributor Author

@embirico Yes, it will be possible through use of transactions with origins, which can be used to describe the source of change. UndoManager can be narrowed to only track changes coming from specific origins, so that undo/redo don't operate on other people updates.

I'll add test cases that can serve as examples on how to use them.

@Horusiath
Copy link
Contributor Author

@heckj current branch passes build and tests on my machine using YSWIFT_LOCAL=true, however CI build produces weird compilation errors. Could that be somehow related to some difference in Swift versions or something?

@heckj
Copy link
Collaborator

heckj commented Mar 4, 2024

I'd suspect so - the complaints are about the code being compatible with an earlier version of swift. I'll take a look and see if I can get it updated.

That's got it 👍

Two commits when one would have done - walked it forward until it was using the latest version of Swift, which resolved the compilation complaints.

@Horusiath Horusiath marked this pull request as ready for review March 5, 2024 16:21
@Horusiath Horusiath merged commit 0a42fee into y-crdt:main Mar 5, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants