-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Maintain image selection in post after updateMedia #14328
Conversation
@@ -391,6 +392,21 @@ function mediaButton( editor ) { | |||
// edited and marked dirty, we can set the counter to correct number. | |||
numOfImagesToUpdate = null; | |||
} | |||
|
|||
// Re-select image node if one was selected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cause of the problem really isn't clear and this comment doesn't seem to explain it much either. Could we leave more context to indicate why this code exists?
@@ -393,6 +400,19 @@ function mediaButton( editor ) { | |||
} | |||
} ); | |||
|
|||
function reselectImage() { | |||
// Re-select image node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove this comment since the function is named aptly. If this needs further explication we can add jsDoc to the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @msmithgu this tests well for me
@@ -377,6 +378,12 @@ function mediaButton( editor ) { | |||
editor.fire( 'SetTextAreaContent', { content } ); | |||
} | |||
|
|||
// We have just replaced some image nodes, potentially losing selection/focus. | |||
// So if an image node was selected and one isn't now, re-select it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the comment update. I think it gets us closer but not fully to our ideal. if I read this I would have no idea that a duplication bug existed without it.
is duplicating the image directly related to losing selection? what would happen if we didn't reselect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.. there is other code that replaces or appends depending on whether an image is selected. That code is intended to match usability behavior of core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The duplication bug occurred because an edited image was getting deselected, then modified, and thusly appended rather than replaced.
This change fixes the cause of that issue: the deselection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an edited image was getting deselected, then modified, and thusly appended rather than replaced.
that sounds like the basis for a great comment in the code!
This addresses #14233
When an edited image didn't have a caption and was updated, it created a duplicate image in the post. This was because updateMedia would sometimes lose the current selection. This change fixes this issue.