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

Quill changes Delta after returning it in "text-change" event #296

Closed
calibr opened this issue Feb 18, 2015 · 8 comments
Closed

Quill changes Delta after returning it in "text-change" event #296

calibr opened this issue Feb 18, 2015 · 8 comments

Comments

@calibr
Copy link

calibr commented Feb 18, 2015

http://jsfiddle.net/ek464Lc3/
When type relatively fast, Quill changes a first returned Delta, I think is not normal behaviour, isn't it?

Steps:

  1. Just print "123" after "HelloWorld!" string
  2. First fired Delta ops values:
    When "1" typed - [{"retain":12},{"insert":"1"}]
    When "2" typed - [{"retain":12},{"insert":"12"}]
    When "3" typed - [{"retain":12},{"insert":"123"}]
@rocketraman
Copy link

@calibr Why are you saving and printing firstDelta and then not overwriting that value? Here is a version without that: http://jsfiddle.net/ho55brd3/. Seems to work fine:

[{"retain":12},{"insert":"12"}]
[{"retain":14},{"insert":"3"}]

@calibr
Copy link
Author

calibr commented Apr 15, 2015

@rocketraman it's just a test case which shows "delta changing" behaviour. sorry but I don't see any difference between my and yours fiddle.

@rocketraman
Copy link

I don't understand your problem then. The delta behavior seems perfectly fine.

@calibr
Copy link
Author

calibr commented Apr 16, 2015

I'm new to OT related things and maybe have wrong idea about working with deltas. In my project I save all deltas in an array which composed in one Delta when user clicks Save button, but composing generates wrong result because deltas in array have not their original values. It's not real problem for me because I create workaround by cloning "ops" array to preserve original values, but I found it strange that the object is changed after the user got it, I can provide more samples if it make sense..

@rocketraman
Copy link

I don't see any difference between my and yours fiddle.

Hah, I see that for some reason my changes didn't get saved in the fiddle.

Anyway, are you saying that the delta objects are being modified by quill after they are returned? That doesn't seem to be happening in this test case:

var editor = new Quill('#editor');

var res = document.getElementById("res");
var deltaOps = []

editor.on('text-change', function (delta, source) {
    deltaOps.push(delta.ops)
    res.innerHTML += "<br>" + JSON.stringify(deltaOps);
});
[[{"retain":12},{"insert":"1"}]]
[[{"retain":12},{"insert":"1"}],[{"retain":13},{"insert":"23"}]]
[[{"retain":12},{"insert":"1"}],[{"retain":13},{"insert":"23"}],[{"retain":15},{"insert":"4"}]]

(http://jsfiddle.net/h95zLuu6/)

@calibr
Copy link
Author

calibr commented Apr 16, 2015

Yes operations array is remains unchanged, but whole ops field is reassigned by new one for Delta object, in other words you store reference to old ops array.
I have checked Quill sources and found that my issue related to UndoManager timeout option, and if I set it to zero Delta's remains unchanged

Quill.modules["undo-manager"].DEFAULTS.delay = 0;

By default this value is 1000 and delta can be changed in this time interval.

@rocketraman
Copy link

Yes operations array is remains unchanged, but whole ops field is reassigned by new one for Delta object, in other words you store reference to old ops array

Ah interesting. Thanks for explaining the issue!

@igmcdowell
Copy link
Contributor

I also ran into this when doing client side-buffering before sending ops over the network. The result is duplicated data and a server-representation that differs from the client view. Like @calibr I'm working around it by cloning the ops before buffering, but it's definitely surprising that they're not treated as immutable by quill.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants