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

Add tldraw undo/redo example #645

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LakHyeonKim
Copy link

@LakHyeonKim LakHyeonKim commented Sep 14, 2023

What this PR does / why we need it?

Hello ~ 👋

I've been working on a project that's very similar to tldraw. However, while the undo/redo functionality is essential, it's not an easy feature to implement.

I've tried adding the undo/redo feature to the tldraw example based on some considerations, even though I'm not very proficient with TypeScript. I'd like to share my idea and discuss it further.

Brief Explanation

  • The history is managed per client, similar to tools like Figma and Google Slides.
  • The onChangePage handler creates the history.
  • Each unit of work in the history is referred to as a "command".
  • However, the "onChangePage" handler gets called too often, leading to a bloated history. I've reduced the fps value of "useThrottleCallback" to mitigate this, but we might need to find a better solution.
  • Every time undo or redo is performed, a snapshot of the current state of the yorkie doc is first created. The command then applies its original snapshot content to the yorkie doc. This is done to incorporate changes made by other users.
  • The text does not undo/redo in the desired direction. This aspect needs further consideration.

I'd appreciate any feedback or suggestions.

Any background context you want to provide?

What are the relevant tickets?

Fixes #

Checklist

  • Added relevant tests or not required
  • Didn't break anything

@CLAassistant
Copy link

CLAassistant commented Sep 14, 2023

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Sep 15, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (2a49cfc) 88.88% compared to head (ade23a3) 88.88%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #645   +/-   ##
=======================================
  Coverage   88.88%   88.88%           
=======================================
  Files          80       80           
  Lines        8958     8958           
  Branches      825      825           
=======================================
  Hits         7962     7962           
  Misses        688      688           
  Partials      308      308           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@krapie
Copy link
Member

krapie commented Sep 16, 2023

Every interesting PR :)
FYI, undo/redo implementation is in progress at #635, so check it out.

@LakHyeonKim
Copy link
Author

I've checked it. 👍
After submitting the PR, I noticed it. I'm very pleased to see that Yorkie supports undo and redo.
Our project currently uses the undo and redo method as per the submitted PR, which makes the code very complex.
I'm really looking forward to it. 😄

@krapie
Copy link
Member

krapie commented Sep 18, 2023

@LakHyeonKim I will notice right away you when we implement undo/redo :)

@LakHyeonKim
Copy link
Author

@krapie Haha😁 thank you very much!

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.

None yet

3 participants