-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Set selection in Move Line Up after operation is finished #2731
Conversation
Actually, this is an okay fix (there's no CodeMirror bug). Updated description to explain why. |
Do you think we should add a comment explaining why the selection change shouldn't be inside the batch? I think normally the best practice is to do everything in the batch, including selection changes, to avoid extra DOM updates. Looks good otherwise. |
And actually, looks like there are several other places in EditorCommandHandlers alone where we set selection inside a batch. Do any of those have a similar bug? I'll try to do some testing... |
Yup, good idea. Done. |
Yup, looks like block comment, at least, suffers from the same thing:
Result: selection is shifted down one line from where it should be. Seems like we might need to do an audit of setSelection() calls to ferret out all cases of this... is that worth doing now? |
Yup, I just reproduced something similar for line comments as well. I'll look at fixes for these. I could imagine building some infrastructure around this (e.g. having |
…nside doc.batchOperation()
Other fixes pushed. EditorCommandHandlers unit tests still pass. |
I just checked this and it seems like line comment in CSS also has this problem when the selection ends on a ch 0 selecting content in at least 2 lines. |
@TomMalbran - do the fixes I just pushed to this pull request fix the issue you're seeing? |
I believe they will, since is the same problem as the ones before... but haven't tested it. |
Looks good -- merging |
Set selection in Move Line Up after operation is finished
Fixes #1343.
I believe the issue is that the actual edit is happening in the underlying "document" (which is actually the full editor), but the selection is being set in the inline editor (which is a different editor). So the selection is getting set in the inline editor, but then the change is synchronized back from the document when the operation ends, which modifies the selection we just set. The inline editor selection change really shouldn't be inside the document's batch.
So the fix is just to move the selection change (in the inline editor) outside of the operation.