-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Delete->Undo will move cursor to the beginning of editor #2201
Comments
May be related to this? #2098 |
@ericedem You are right. The problem is about undo the selection... I just found some strange behavior in logs. It seems the the history does not batch operations in the right way. The slate editor undos all operations until the start state of the document. |
Perhaps we can set history stack barrier in these events: |
Has somebody found a workaround.. Undoing in the middle of a huge document will set the focus at the start of the document. You can try it in the Huge document example: https://www.slatejs.org/#/huge-document This is was not happening in older version of the editor. (0.3.*) thanks for your help |
@inkubux Two solutions
|
Thanks. I'm having a bit of difficulty finding if the previous change is not a undo inside of the onChange callback |
@inkubux
|
@zhujinxuan zhujinxuan After multiple hours trying to find the issue. I finally got it. The proposed workaround did not work unfortunately, but calling change.select with the last selection when it's not un undo worked (more or less) but created some other wierd bugs. I ended up digging in the slate core to find the issue When you call the change.snapshotSelection() it then call the applyOperation with
it tells the applyOperation to not merge BUT, the applyOperation method does not have a second parameter even though the comments says otherwise.
So the merge flag will be set to null because of the tmp check
and then in the history.save the After this the deletion comes in it check the the non-commital operations and set the merge flag to true.. because of the snapshot being attached to this.operations
` I was able to make it work by fixing the applyOperation to take the options in consideration like so `value: function applyOperation(operation, options={}) {
I'm putting this here since I might have broke something obvious. I can create a pull request , but I'm not sure of the guidelines to make it merged Thanks for your help |
@inkubux My pesudo code:
|
Thanks a lot again :) Sorry if I sound insistant.. The actual issue is that snapshotSelection is getting merged with the previous batch for the current change. This is causing multiple issues Example Insert text undo the undo will undo the insertion and the deletion in one batch. I created a pull request for the issue. Let me know if you need more informations |
@inkubux Oh, I did not notice that. I am using a different version, so I did not know that the snapshot has changed. Sorry that I did not catch that in my previous post. |
Great thanks |
Do you want to request a feature or report a bug?
bug
What's the current behavior?
See the gif below:
Delete a char and then undo will place the cursor to a wrong position.
What's the expected behavior?
Cursor shall be where the edit happens.
The text was updated successfully, but these errors were encountered: