Comments (1)
Yes, this is the expected behavior. I'll try to explain what is happening internally so you can understand it better. Below is a fix to get consistent behavior.
In Yjs we can't undo deletions (as in undeleting the internal item representation). Instead, we re-insert content. The advantage is that we can perform very aggressive garbage-collection. This means that after performing undo/redo, relative positions are not always placed at the position where they intuitively should be. This is a tradeoff - but I think it's worth it.
Intuitively, the relative position should be at index 2 after performing undo. We can't ensure that.
When you insert ab|cde
, and point the relative position to the character c
, the relative position will still point to the deleted character c
, even though it is not visible anymore. After undoing the deletion, a new character c
will be inserted: abc|cde
(note that the second character c
is basically invisible now).
The correct relative position in your scenario (at least technically) is position 3.
Now, to the weird part. We can restore the intuitively correct position if we have access to the UndoManager that performed the undo operation. The client that performed undo knows more about the document state. It knows that the second c
character is "redone" by the first c
insertion. So it "follows" the "redo-path" and figures out that position 2 is more accurate. However, the "redo-path" is not persisted in the Yjs document and will eventually be lost.
Since relative positions are mainly used to restore the cursor state after a client performs an undo, this is the default behavior. In your case, I recommend not following the redo path to achieve consistent behavior.
TLDR:
Add false
to createAbsolutePositionFromRelativePosition(rpos, doc, false)
to get consistent behavior across all clients. This disables "following the redo-path". This feature is available in the latest Yjs release.
Feel free to ping me to chat more about a commenting solution based on relative positions.
from yjs.
Related Issues (20)
- 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
- Undo manager without origin doesn't catch updates with origin HOT 7
- How to use YJS in a server written in Java language? HOT 3
- Delta embeds support HOT 2
- Regression in v13.6.13 and up HOT 2
- Is there a way to actively trigger garbage collection or actively discard some data HOT 1
- Allow subscribing to only updates with a specific origin on doc.on('update', () => {}) HOT 2
- @kangc/v-md-editor
- UndoManager: Undoing combination of Y.Map#set and deleting that Y.Map from parent Y.Array results in 1 client with invalid Y.Map HOT 4
- yjs v13.6.13 breaks `y-utility/y-multidoc-undomanager` HOT 1
- Cannot undo a change made from y-crdt in Yjs HOT 7
- `y-codemirror.next` stops syncing because `y-indexeddb` throws exception
- RangeError: Maximum call stack size exceeded
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.