From d5936d9a153039e92f67206b3fe48d582a6f7248 Mon Sep 17 00:00:00 2001
From: Calixte Denizet <calixte.denizet@gmail.com>
Date: Fri, 22 Sep 2023 19:35:01 +0200
Subject: [PATCH] [Editor] Let the Save button always enabled in the alt-text
 dialog

---
 src/display/editor/editor.js |  3 +++
 web/alt_text_manager.js      | 13 +------------
 web/viewer.html              |  2 +-
 3 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/src/display/editor/editor.js b/src/display/editor/editor.js
index 2898b293a..ecea8664a 100644
--- a/src/display/editor/editor.js
+++ b/src/display/editor/editor.js
@@ -932,6 +932,9 @@ class AnnotationEditor {
   }
 
   set altTextData({ altText, decorative }) {
+    if (this.#altText === altText && this.#altTextDecorative === decorative) {
+      return;
+    }
     this.#altText = altText;
     this.#altTextDecorative = decorative;
     this.#setAltTextButtonState();
diff --git a/web/alt_text_manager.js b/web/alt_text_manager.js
index 0975ca0df..dad87d3c1 100644
--- a/web/alt_text_manager.js
+++ b/web/alt_text_manager.js
@@ -52,8 +52,6 @@ class AltTextManager {
 
   #container;
 
-  #previousDecorative = null;
-
   constructor(
     {
       dialog,
@@ -82,7 +80,6 @@ class AltTextManager {
     saveButton.addEventListener("click", this.#save.bind(this));
     optionDescription.addEventListener("change", this.#boundUpdateUIState);
     optionDecorative.addEventListener("change", this.#boundUpdateUIState);
-    textarea.addEventListener("input", this.#boundUpdateUIState);
 
     this.#overlayManager.register(dialog);
   }
@@ -151,7 +148,6 @@ class AltTextManager {
       this.#optionDescription.checked = true;
     }
     this.#previousAltText = this.#textarea.value = altText?.trim() || "";
-    this.#previousDecorative = decorative;
     this.#updateUIState();
 
     this.#currentEditor = editor;
@@ -268,14 +264,7 @@ class AltTextManager {
   }
 
   #updateUIState() {
-    const altText = this.#textarea.value.trim();
-    const decorative = this.#optionDecorative.checked;
-
-    this.#textarea.disabled = decorative;
-    this.#saveButton.disabled = !(
-      this.#previousDecorative !== decorative ||
-      this.#previousAltText !== altText
-    );
+    this.#textarea.disabled = this.#optionDecorative.checked;
   }
 
   #save() {
diff --git a/web/viewer.html b/web/viewer.html
index e2d886733..327efd365 100644
--- a/web/viewer.html
+++ b/web/viewer.html
@@ -522,7 +522,7 @@ See https://github.com/adobe-type-tools/cmap-resources
             </div>
             <div id="buttons">
               <button id="altTextCancel" tabindex="0"><span data-l10n-id="editor_alt_text_cancel_button">Cancel</span></button>
-              <button id="altTextSave" tabindex="0" disabled><span data-l10n-id="editor_alt_text_save_button">Save</span></button>
+              <button id="altTextSave" tabindex="0"><span data-l10n-id="editor_alt_text_save_button">Save</span></button>
             </div>
           </div>
         </dialog>