Comments (7)
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.
You should set trackedOrigins
or call stopCapturing()
manually
from yjs.
How would that help? Then the state diff to select my shape would not be captured and not reverted
from yjs.
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.
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.
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.
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)
- Is it possible to read uintarray update data? HOT 1
- Misordered updates result in temporarily missing Y.Map keys HOT 5
- Mistake in documentation? Property 'set' does not exist on type 'YArray<unknown>'
- Logo as SVG? HOT 4
- RangeError Invalid typed array length: 110 & TypeError: contentRefs[(info & binary.BITS5)] is not a function HOT 2
- Support for TypeScript NodeNext HOT 4
- Inconsistent Y.XmlText.format behavior HOT 1
- support double linked list as a shared data type HOT 1
- Ace binding HOT 1
- y-loopback HOT 2
- UndoManager doesn't persist meta HOT 4
- Froala Editor support HOT 1
- UndoManager stack cleared after a removal on remote side HOT 1
- docs: duplicate Y.Event page entry HOT 1
- Ability to reference UndoManager StackItem inside Type observers
- yText delta attributes is not correct when undo
- Support build for nuxt 2 HOT 1
- Impossible to save a Y.Map when deleted from a Y.Array HOT 5
- Global document undo manager HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yjs.