Skip to content

Conversation

@peyerluk
Copy link
Member

When splitting a block and then merge it back, the cursor is restored in the wrong position (gets moved at the beginning of a block). The console logs Marker element has been removed. Cannot restore selection..

@matteoagosti
Copy link
Contributor Author

When using rangy's native save/restore selection the problem disappears. @peyerluk the problem is within rangeSaveRestore I guess

@matteoagosti
Copy link
Contributor Author

I found the issue, it is related to normalizeTags function that removes empty tags, thus the range save/restore marker is removed as well.

@matteoagosti
Copy link
Contributor Author

Nope, is not that

@peyerluk
Copy link
Member

I got it. pushing my solution in a few minutes

@matteoagosti
Copy link
Contributor Author

There was an error that got fixed here a34f83dc674af502c7b808ec7b79592db1d28c7b, however the problem persists

In order to add functionality to save a Cursor we need a convenient way to get the host of an element, so the Cursor can make sure its host is always correct even if the Cursor is moved to another block (like for example in the case of block merge).
I got errors in the console when moving around with the cursor. So I just added this conditional to get rid of the errors.
Add RangeSaveRestore functionality directly to the Cursor class. To get this to work the cursor must also update its host if someone moves the cursor. For that I added the #setHost method that should be called whenever the host could have changed. I also store the host when saving a cursor, so it becomes possible to move the cursor to another block and then restore it to the previous block.

On top of that I added the convenience methods #moveAtBeginning() and #moveAtEnd() which I wanted to use in the specs. While at it I also refactored the #moveAfter() and #moveBefore() so they use the rangy methods and set the range more where one would expect it.
The bug itself was more a matter of calling restore with the right container and then setting the selection again. But with the new Cursor#restore() method one does not need to think about these details anymore :)
@ghost ghost assigned peyerluk Sep 23, 2013
The new #moveAtBeginning and #moveAtEnd are the correct methods to place the cursor at the beginning or end of a container.
@peyerluk
Copy link
Member

How about setUserSelection or updateUserSelection?

@matteoagosti
Copy link
Contributor Author

Mhh, better setSelection than setUserSelection. What about refresh?

@peyerluk
Copy link
Member

Then maybe better go back to update :) I don't have a strong opinion. But refresh sounds more like setting the cursor to the current user selection than the other way around...

What about this pull request? The naming issue can be handled separately and if you feel like it feel free to change the setSelection method name :)

@matteoagosti
Copy link
Contributor Author

It's good to merge 👍

peyerluk added a commit that referenced this pull request Sep 23, 2013
Bug: wrong cursor position when merging
@peyerluk peyerluk merged commit 2901f66 into master Sep 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants