GithubHelp home page GithubHelp logo

Comments (7)

SebastianStehle avatar SebastianStehle commented on May 27, 2024 1

It could be an idea to move the selection to the awareness store, but I am not sure if it makes my life easier.

I use redux for my application and bind the redux store to yjs models with a custom binding that I have built: https://github.com/SebastianStehle/yjs-redux. The yjs stuff is just a recent addition and the redux store has existed way before that.

Many operations also require the selection state to be changed. For example, when you add a new item you want this to be selected. When you ungroup a group you want to children to be selected. Therefore it was easy to move this to the main state and just implement it in the reducer. Ofc it could be also modeled in a middleware and then synced to awareness state or something like that, but anyway. Some other operations like deletion are also simpler with the current setup. So there are a wide range of reasons not to put the selection into the awareness state.

No idea how deleteFilter would help.

from yjs.

himself65 avatar himself65 commented on May 27, 2024

You should set trackedOrigins or call stopCapturing() manually

from yjs.

SebastianStehle avatar SebastianStehle commented on May 27, 2024

How would that help? Then the state diff to select my shape would not be captured and not reverted

from yjs.

himself65 avatar himself65 commented on May 27, 2024

Sorry for my misunderstood.

First of all, the selection state should be in the awarenessStore, not in CRDT.

In the undoManager, there is a deleteFilter field that you can control whether to undo the item, that is similar to what you expected of the transactions.

from yjs.

dmonad avatar dmonad commented on May 27, 2024

As @himself65 said, with trackedOrigins, stopCapturing, and deleteFilter, you have a rich palette of tools to achieve almost all desired behaviors. https://docs.yjs.dev/api/undo-manager

I am using yjs for a diagram editor or I am working on the integration of yjs into this editor. In my editor the selection state is also part of the model and I would like to ignore that in the undo redo operations, or to be more precise, it should not be added to the stack.

Lets consider a very basic example with 2 transactions and the initial state 0:

0. Diagram has item A and B, B is selected.

1. User selects A now

2. User adds item C, which gets selected automatically.

Describe the solution you'd like If I just ignore transaction, then A would be selected after undo operation, which is not the same state as before. Therefore what I would like to achieve is that the transaction 1 is ignored but added to the undo stack after transaction 2 is completed.

Describe alternatives you've considered I think I can also implement it on top of the undo manager or implement it by adding additional metadata to the stack item as described in the docs, but I think this makes the most sense for me

Now, do you want to ignore the selection state (In my editor the selection state is also part of the model and I would like to ignore that in the undo redo operations) or not (If I just ignore transaction, then A would be selected after undo operation, which is not the same state as before.)?

If you manipulate the selection state in a different transaction, using an origin that is not tracked, then the selection should not change when performing undo/redo. See https://docs.yjs.dev/api/undo-manager

I guess that what you are asking is that there should be a configuration option to disable tracking of all fields that are named selection. I don't know yet how I would implement that in practice.

Maybe there could be an option isInScope: (item) => boolean that allows you to configure scope more granularity.

However, I agree with @himself65 that the selection state should be tracked using the awareness. 1. every user should be able to have a different selection. 2. you probably don't want to persist the selection state across sessions (e.g. when you reload the window).

from yjs.

SebastianStehle avatar SebastianStehle commented on May 27, 2024

Perhaps my description was not precise and confusing. I want to "ignore" selection changes in a way that it does not add something to the undo stack but it gets merged with the next update.

I have achieved it the following way: https://github.com/mydraft-cc/ui/blob/collaboration/src/wireframes/collaboration/services/extended-undo-manager.ts#L33

I don't see how I could implement it in another way.

from yjs.

dmonad avatar dmonad commented on May 27, 2024

Ah okay, then you need to do something like you did. It is also possible to merge stack-items in Y.UndoManager. But currently this can only be done via startCapturing & stopCapturing or using the captureInterval.

If your solution works, then I'd like to close this ticket. I don't think we can cover really all use-cases in a single UndoManager, so it's nice to see that the current API helped to implement the desired behavior.

from yjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.