Merge "Fix editable-label losing focus"
diff --git a/WORKSPACE b/WORKSPACE
index 8f1ff3e..aaccade 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -862,13 +862,13 @@
 maven_jar(
     name = "codemirror_minified",
     artifact = "org.webjars.npm:codemirror-minified:" + CM_VERSION,
-    sha1 = "f84c178b11a188f416b4380bfb2b24f126453d28",
+    sha1 = "36558ea3b8e30782e1e09c0e7bd781e09614f139",
 )
 
 maven_jar(
     name = "codemirror_original",
     artifact = "org.webjars.npm:codemirror:" + CM_VERSION,
-    sha1 = "5a1f6c10d5aef0b9d2ce513dcc1e2657e4af730d",
+    sha1 = "f1f8fbbc3e2d224fdccc43d2f4180658a92320f9",
 )
 
 maven_jar(
diff --git a/lib/codemirror/cm.bzl b/lib/codemirror/cm.bzl
index 54d60d5..a6b015d 100644
--- a/lib/codemirror/cm.bzl
+++ b/lib/codemirror/cm.bzl
@@ -55,11 +55,14 @@
     "eclipse",
     "elegant",
     "erlang-dark",
+    "gruvbox-dark",
     "hopscotch",
     "icecoder",
+    "idea",
     "isotope",
     "lesser-dark",
     "liquibyte",
+    "lucario",
     "material",
     "mbo",
     "mdn-like",
@@ -75,6 +78,7 @@
     "rubyblue",
     "seti",
     "solarized",
+    "ssms",
     "the-matrix",
     "tomorrow-night-bright",
     "tomorrow-night-eighties",
@@ -214,7 +218,7 @@
     "z80",
 ]
 
-CM_VERSION = "5.25.0"
+CM_VERSION = "5.37.0"
 
 TOP = "META-INF/resources/webjars/codemirror/%s" % CM_VERSION
 
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.html b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.html
index 431d56f4..f8c1ff4 100644
--- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.html
+++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.html
@@ -71,29 +71,30 @@
       #moreActions iron-icon {
         margin: 0;
       }
+      #moreMessage,
       .hidden {
         display: none;
       }
       @media screen and (max-width: 50em) {
-        #mainContent,
-        section,
-        gr-button,
-        gr-dropdown {
-          display: block;
-          flex: 1;
+        #mainContent {
+          flex-wrap: wrap;
+        }
+        gr-button {
+          --gr-button: {
+            padding: .5em;
+            white-space: nowrap;
+          }
         }
         gr-button,
         gr-dropdown {
-          /* px because don't have the same font size */
-          margin: 0 0 6px 0;
+          margin: 0;
         }
         #actionLoadingMessage {
-          display: block;
           margin: .5em;
           text-align: center;
         }
-        #mainContent.mobileOverlayOpened {
-          display: none;
+        #moreMessage {
+          display: inline;
         }
       }
     </style>
@@ -154,6 +155,7 @@
           disabled-ids="[[_disabledMenuActions]]"
           items="[[_menuActions]]">
           <iron-icon icon="gr-icons:more-vert"></iron-icon>
+          <span id="moreMessage">More</span>
         </gr-dropdown>
     </div>
     <gr-overlay id="overlay" with-backdrop>
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js
index 9104cbb..d9da343 100644
--- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js
+++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js
@@ -391,7 +391,7 @@
       '_actionsChanged(actions.*, revisionActions.*, _additionalActions.*)',
       '_changeChanged(change)',
       '_editStatusChanged(editMode, editPatchsetLoaded, ' +
-          'editBasedOnCurrentPatchSet, actions.*, change)',
+          'editBasedOnCurrentPatchSet, actions.*, change.*)',
     ],
 
     listeners: {
@@ -558,73 +558,63 @@
       }
     },
 
+      /**
+       * @param {string=} actionName
+       */
+    _deleteAndNotify(actionName) {
+      if (this.actions[actionName]) {
+        delete this.actions[actionName];
+        this.notifyPath('actions.' + actionName);
+      }
+    },
+
     _editStatusChanged(editMode, editPatchsetLoaded,
         editBasedOnCurrentPatchSet) {
-      const changeActions = this.actions;
-
       if (editPatchsetLoaded) {
         // Only show actions that mutate an edit if an actual edit patch set
         // is loaded.
         if (this.changeIsOpen(this.change.status)) {
           if (editBasedOnCurrentPatchSet) {
-            if (!changeActions.publishEdit) {
+            if (!this.actions.publishEdit) {
               this.set('actions.publishEdit', PUBLISH_EDIT);
             }
-            if (changeActions.rebaseEdit) {
-              delete this.actions.rebaseEdit;
-              this.notifyPath('actions.rebaseEdit');
-            }
+            this._deleteAndNotify('rebaseEdit');
           } else {
-            if (!changeActions.rebaseEdit) {
+            if (!this.actions.rebaseEdit) {
               this.set('actions.rebaseEdit', REBASE_EDIT);
             }
-            if (changeActions.publishEdit) {
-              delete this.actions.publishEdit;
-              this.notifyPath('actions.publishEdit');
-            }
+            this._deleteAndNotify('publishEdit');
           }
         }
-        if (!changeActions.deleteEdit) {
+        if (!this.actions.deleteEdit) {
           this.set('actions.deleteEdit', DELETE_EDIT);
         }
       } else {
-        if (changeActions.publishEdit) {
-          delete this.actions.publishEdit;
-          this.notifyPath('actions.publishEdit');
-        }
-        if (changeActions.rebaseEdit) {
-          delete this.actions.rebaseEdit;
-          this.notifyPath('actions.rebaseEdit');
-        }
-        if (changeActions.deleteEdit) {
-          delete this.actions.deleteEdit;
-          this.notifyPath('actions.deleteEdit');
-        }
+        this._deleteAndNotify('publishEdit');
+        this._deleteAndNotify('rebaseEdit');
+        this._deleteAndNotify('deleteEdit');
       }
 
       if (this.changeIsOpen(this.change.status)) {
         // Only show edit button if there is no edit patchset loaded and the
         // file list is not in edit mode.
         if (editPatchsetLoaded || editMode) {
-          if (changeActions.edit) {
-            delete this.actions.edit;
-            this.notifyPath('actions.edit');
-          }
+          this._deleteAndNotify('edit');
         } else {
-          if (!changeActions.edit) { this.set('actions.edit', EDIT); }
+          if (!this.actions.edit) { this.set('actions.edit', EDIT); }
         }
         // Only show STOP_EDIT if edit mode is enabled, but no edit patch set
         // is loaded.
         if (editMode && !editPatchsetLoaded) {
-          if (!changeActions.stopEdit) {
+          if (!this.actions.stopEdit) {
             this.set('actions.stopEdit', STOP_EDIT);
           }
         } else {
-          if (changeActions.stopEdit) {
-            delete this.actions.stopEdit;
-            this.notifyPath('actions.stopEdit');
-          }
+          this._deleteAndNotify('stopEdit');
         }
+      } else {
+        // Remove edit button.
+        this._deleteAndNotify('edit');
       }
     },
 
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html
index 15284ec..1c841f1 100644
--- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html
+++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html
@@ -503,6 +503,11 @@
 
         assert.isNotOk(element.$$('gr-button[data-action-key="edit"]'));
         assert.isOk(element.$$('gr-button[data-action-key="stopEdit"]'));
+        element.change = {status: 'MERGED'};
+        flushAsynchronousOperations();
+
+        assert.isNotOk(element.$$('gr-button[data-action-key="edit"]'));
+        element.change = {status: 'NEW'};
         element.set('editMode', false);
         flushAsynchronousOperations();