From 3e8394ee33c01fa4996aa34831f223117b4b1ef6 Mon Sep 17 00:00:00 2001
From: Jonas Jenwald <jonas.jenwald@gmail.com>
Date: Sun, 21 Aug 2022 13:48:48 +0200
Subject: [PATCH] [api-major] Enable editing by default

Note that this patch *at least* shouldn't land until both [bug 1784272](https://bugzilla.mozilla.org/show_bug.cgi?id=1784272) and [bug 1785248](https://bugzilla.mozilla.org/show_bug.cgi?id=1785248) are fixed.
---
 extensions/chromium/preferences_schema.json | 8 +++++++-
 web/app.js                                  | 3 ++-
 web/app_options.js                          | 7 ++-----
 web/pdf_viewer.js                           | 6 +++---
 web/viewer.html                             | 5 ++---
 5 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/extensions/chromium/preferences_schema.json b/extensions/chromium/preferences_schema.json
index 798e32956..6716b4cbd 100644
--- a/extensions/chromium/preferences_schema.json
+++ b/extensions/chromium/preferences_schema.json
@@ -156,7 +156,13 @@
     },
     "annotationEditorMode": {
       "type": "integer",
-      "default": -1
+      "enum": [
+        -1,
+        0,
+        3,
+        15
+      ],
+      "default": 0
     },
     "enablePermissions": {
       "type": "boolean",
diff --git a/web/app.js b/web/app.js
index 63a68ce0d..6c40a3b86 100644
--- a/web/app.js
+++ b/web/app.js
@@ -585,11 +585,12 @@ const PDFViewerApplication = {
         appConfig.annotationEditorParams,
         eventBus
       );
+    } else {
       for (const element of [
         document.getElementById("editorModeButtons"),
         document.getElementById("editorModeSeparator"),
       ]) {
-        element.classList.remove("hidden");
+        element.hidden = true;
       }
     }
 
diff --git a/web/app_options.js b/web/app_options.js
index a8c5d84ec..0f09c490b 100644
--- a/web/app_options.js
+++ b/web/app_options.js
@@ -54,11 +54,8 @@ const OptionKind = {
  */
 const defaultOptions = {
   annotationEditorMode: {
-    /** @type {boolean} */
-    value:
-      typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || TESTING")
-        ? 0
-        : -1,
+    /** @type {number} */
+    value: 0,
     kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
   },
   annotationMode: {
diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js
index bbc40b51e..296d27cde 100644
--- a/web/pdf_viewer.js
+++ b/web/pdf_viewer.js
@@ -121,7 +121,7 @@ function isValidAnnotationEditorMode(mode) {
  *   The default value is `AnnotationMode.ENABLE_FORMS`.
  * @property {number} [annotationEditorMode] - Enables the creation and editing
  *   of new Annotations. The constants from {@link AnnotationEditorType} should
- *   be used. The default value is `AnnotationEditorType.DISABLE`.
+ *   be used. The default value is `AnnotationEditorType.NONE`.
  * @property {string} [imageResourcesPath] - Path for image resources, mainly
  *   mainly for annotation icons. Include trailing slash.
  * @property {boolean} [enablePrintAutoRotate] - Enables automatic rotation of
@@ -219,7 +219,7 @@ class PDFPageViewBuffer {
 class PDFViewer {
   #buffer = null;
 
-  #annotationEditorMode = AnnotationEditorType.DISABLE;
+  #annotationEditorMode = AnnotationEditorType.NONE;
 
   #annotationEditorUIManager = null;
 
@@ -277,7 +277,7 @@ class PDFViewer {
     this.#annotationMode =
       options.annotationMode ?? AnnotationMode.ENABLE_FORMS;
     this.#annotationEditorMode =
-      options.annotationEditorMode ?? AnnotationEditorType.DISABLE;
+      options.annotationEditorMode ?? AnnotationEditorType.NONE;
     this.imageResourcesPath = options.imageResourcesPath || "";
     this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
     if (
diff --git a/web/viewer.html b/web/viewer.html
index b58f80fd0..6ae10874d 100644
--- a/web/viewer.html
+++ b/web/viewer.html
@@ -316,7 +316,7 @@ See https://github.com/adobe-type-tools/cmap-resources
 
                 <div class="verticalToolbarSeparator hiddenMediumView"></div>
 
-                <div id="editorModeButtons" class="splitToolbarButton toggled hidden" role="radiogroup">
+                <div id="editorModeButtons" class="splitToolbarButton toggled" role="radiogroup">
                   <button id="editorFreeText" class="toolbarButton" disabled="disabled" title="Text" role="radio" aria-checked="false" tabindex="34" data-l10n-id="editor_free_text2">
                     <span data-l10n-id="editor_free_text2_label">Text</span>
                   </button>
@@ -325,8 +325,7 @@ See https://github.com/adobe-type-tools/cmap-resources
                   </button>
                 </div>
 
-                <!-- Should be visible when the "editorModeButtons" are visible. -->
-                <div id="editorModeSeparator" class="verticalToolbarSeparator hidden"></div>
+                <div id="editorModeSeparator" class="verticalToolbarSeparator"></div>
 
                 <button id="secondaryToolbarToggle" class="toolbarButton" title="Tools" tabindex="48" data-l10n-id="tools" aria-expanded="false" aria-controls="secondaryToolbar">
                   <span data-l10n-id="tools_label">Tools</span>