MDL-79501 tiny: Fix editing multiple videos

The selection gets lost while opening the modal dialogue to update an
embedded media. Caching the current selection allows us to update the
previously selected node instead of updating the first embedded media.

Signed-off-by: Gregor Eichelberger <gregor.eichelberger@tuwien.ac.at>
This commit is contained in:
Gregor Eichelberger 2023-09-29 13:06:06 +02:00
parent b660e6979a
commit 0b28c6a254
No known key found for this signature in database
GPG Key ID: 1F06F47F1E89263E
3 changed files with 10 additions and 5 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -49,6 +49,11 @@ export const MediaEmbed = class {
*/
isUpdating = false;
/**
* @property {Object} The currently selected media.
*/
selectedMedia = null;
constructor(editor) {
const permissions = getEmbedPermissions(editor);
this.canShowFilePicker = permissions.filepicker;
@ -96,6 +101,7 @@ export const MediaEmbed = class {
}
async displayDialogue() {
this.selectedMedia = this.getSelectedMedia();
const data = Object.assign({}, this.getCurrentEmbedData());
this.isUpdating = Object.keys(data).length !== 0;
@ -163,7 +169,7 @@ export const MediaEmbed = class {
};
const sources = [];
const medium = this.getSelectedMedia();
const medium = this.selectedMedia;
if (!medium) {
return null;
}
@ -425,8 +431,7 @@ export const MediaEmbed = class {
const {html} = await this.getMediaHTML(modal.getRoot()[0]);
if (html) {
if (this.isUpdating) {
const selectedNode = this.getSelectedMedia();
selectedNode.outerHTML = html;
this.selectedMedia.outerHTML = html;
this.isUpdating = false;
} else {
this.editor.insertContent(html);