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

Local undo state #179

Open
hellocatfood opened this issue Oct 15, 2023 · 2 comments
Open

Local undo state #179

hellocatfood opened this issue Oct 15, 2023 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@hellocatfood
Copy link

Is it possible to disable the global undo state? Currently it seems that when I press Ctrl + Z it will undo text input including whatever any other connected user has typed. This has caused confusion at times when we start to wonder where our text has gone!

Can undo states just be local to the user?

@munshkr
Copy link
Owner

munshkr commented Jan 6, 2024

Hey! I missed this issue.. it's a good question. I think it can be fixed, probably need to handle Undo/Redo shortcuts manually and only apply these actions on the focused editor. I'll take a look.

@munshkr munshkr self-assigned this Jan 6, 2024
@munshkr munshkr modified the milestones: Flok 1.0, Version 1.0, Version 1.1 Jan 8, 2024
@munshkr munshkr added bug Something isn't working and removed flok-next labels Jan 8, 2024
@tmhglnd
Copy link
Contributor

tmhglnd commented Apr 23, 2024

I tried to look into this and found some potential answers, but it is unclear to me how this can be applied in the Flok environment.

Answers I found:
https://discuss.yjs.dev/t/how-is-undomanager-being-used/1851/4
https://docs.yjs.dev/api/undo-manager#example-specify-tracked-origins

It seems we have to specify trackedOrigins in the UndoManager by for example adding the user id or user name as an Origin, so when undo-ing the UndoManager only tracks the edits from the user:

  const undoManager = new UndoManager(text, {
    trackedOrigins: new Set([doc.session.awareness.getLocalState()?.user.name])
  });

But then we have to add the origin to the "transaction" made by the User. And for this they give the example to use the beforeTransaction listener with a callback function:

doc.on('beforeTransaction', (tr, doc) => {
  if (!tr.origin) tr.origin = 'the origin for UndoManager';
});

I tried this but it seems you implemented the y-codemirror.next a bit differently so this .on() is not available in the doc.session. That is where I got stuck, if you have pointers I'm happy to continue (or maybe this already helps you to implement the feature?

Update:
I was able to get 'beforeTransaction' working, but it seems this is not what we need and this is called for all users. It has to be an extra argument to .transaction I guess.

Some other user reported that ReactCodemirror's history feature was in the way: https://discuss.yjs.dev/t/how-is-undomanager-being-used/1851/9

I tried disabling by setting history: false to see if that helped but that actually made the history not work anymore so I don't think this is the fix.

On the y-codermirror.next github they do mention that individual undo/redo-history is a separate plugin, but is not clear what that plugin is, or maybe they mean the UndoManager with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

3 participants