From 8c73feb0b38aa7eda7b4efcb3474c3ffcb0f1c44 Mon Sep 17 00:00:00 2001 From: Arlo Breault Date: Thu, 9 Mar 2023 14:40:19 -0500 Subject: [PATCH] Update gallery alt with caption when set as same Follow up to Idf297d8a98995971c5835b0cea56c3317a3626e2 Bug: T330842 Change-Id: Ia5e180f03a8199d8347558803336617472492a23 --- .../ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js index 892e9d46ec..204ad17d7d 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js @@ -517,7 +517,7 @@ ve.ui.MWGalleryDialog.prototype.getSetupProcess = function ( data ) { this.captionTarget.connect( this, { change: 'updateActions' } ); this.highlightedAltTextInput.connect( this, { change: 'updateActions' } ); this.altTextSameAsCaption.connect( this, { change: 'onAltTextSameAsCaptionChange' } ); - this.highlightedCaptionTarget.connect( this, { change: 'updateActions' } ); + this.highlightedCaptionTarget.connect( this, { change: 'onHighlightedCaptionTargetChange' } ); return this.imagesPromise; }, this ); @@ -839,12 +839,26 @@ ve.ui.MWGalleryDialog.prototype.onModeDropdownChange = function () { this.updateActions(); }; +/** + * Handle change event for this.highlightedCaptionTarget + */ +ve.ui.MWGalleryDialog.prototype.onHighlightedCaptionTargetChange = function () { + if ( this.altTextSameAsCaption.isSelected() ) { + var surfaceModel = this.highlightedCaptionTarget.getSurface().getModel(); + var caption = surfaceModel.getLinearFragment( + surfaceModel.getDocument().getDocumentRange() + ).getText(); + this.highlightedAltTextInput.setValue( caption ); + } + this.updateActions(); +}; + /** * Handle change event for this.altTextSameAsCaption */ ve.ui.MWGalleryDialog.prototype.onAltTextSameAsCaptionChange = function () { this.highlightedAltTextInput.setReadOnly( this.isReadOnly() || this.altTextSameAsCaption.isSelected() ); - this.updateActions(); + this.onHighlightedCaptionTargetChange(); }; /**