Merge branch 'stable-3.4'

* stable-3.4:
  Stop propagation for all keys but exempt the save button
  Stop propagation for all keys but exempt the save button

Change-Id: Ia8d0a88db7d8d438e2f744f4433f566714d01fcb
diff --git a/.gitignore b/.gitignore
index 0f55ddc..e164b25 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,6 +9,5 @@
 npm-debug.log
 dist
 fonts
-bower_components
 .tmp
-.vscode
\ No newline at end of file
+.vscode
diff --git a/BUILD b/BUILD
index 7e2c5c6..ea55eaf 100644
--- a/BUILD
+++ b/BUILD
@@ -1,5 +1,5 @@
 load("//tools/bzl:genrule2.bzl", "genrule2")
-load("//tools/bzl:js.bzl", "bundle_assets", "polygerrit_plugin")
+load("//tools/bzl:js.bzl", "polygerrit_plugin")
 load("//tools/bzl:plugin.bzl", "gerrit_plugin")
 
 gerrit_plugin(
@@ -28,16 +28,35 @@
     ]),
 )
 
-bundle_assets(
+genrule(
     name = "codemirror-element",
     srcs = [
         "gr-editor/codemirror-element.css",
         "gr-editor/codemirror-element.html",
         "gr-editor/codemirror-element.js",
+        "@ui_npm//codemirror-minified",
     ],
-    app = "gr-editor/codemirror-element.html",
-    split = False,
-    deps = ["//lib/js:codemirror-minified"],
+    outs = ["codemirror-element.html"],
+    cmd = " ".join([
+        "p=$$PWD &&",
+        "mkdir $(@D)/destdir &&",
+        "tar -cf - $(SRCS) | tar -C $(@D)/destdir -xf - &&",
+        "cd $(@D)/destdir/plugins/codemirror-editor &&",
+        "ln -s ../../external/ui_npm/node_modules . &&",
+        "cd ../.. &&",
+        "$$p/$(location @tools_npm//polymer-bundler/bin:polymer-bundler)",
+        "--inline-scripts",
+        "--inline-css",
+        "--sourcemaps",
+        "--strip-comments",
+        "--root",
+        "plugins/codemirror-editor",
+        "--out-file",
+        "$$p/$@",
+        "/gr-editor/codemirror-element.html &&",
+        "rm -rf $(@D)/destdir",
+    ]),
+    tools = ["@tools_npm//polymer-bundler/bin:polymer-bundler"],
 )
 
 polygerrit_plugin(
diff --git a/bower.json b/bower.json
deleted file mode 100644
index f932829..0000000
--- a/bower.json
+++ /dev/null
@@ -1,21 +0,0 @@
-{
-  "name": "codemirror-editor",
-  "authors": [
-    "kaspern@google.com"
-  ],
-  "license": "http://www.apache.org/licenses/LICENSE-2.0",
-  "dependencies": {
-    "codemirror-minified": "^5.59.1"
-  },
-  "devDependencies": {
-    "es6-promise": "^3.3.1",
-    "chai": "^4.2.0",
-    "mocha": "^6.2.2",
-    "web-component-tester": "^6.5.1"
-  },
-  "private": true,
-  "resolutions": {
-    "chai": "^3.2.0",
-    "mocha": "^3.1.2"
-  }
-}
diff --git a/gr-editor/codemirror-element.css b/gr-editor/codemirror-element.css
index 0a328b7..97787c7 100644
--- a/gr-editor/codemirror-element.css
+++ b/gr-editor/codemirror-element.css
@@ -4,7 +4,6 @@
 }
 .CodeMirror {
   font-family: 'Roboto Mono', 'SF Mono', 'Lucida Console', Monaco, monospace;
-  height: auto;
   /* CodeMirror has a default z-index of 4. Set to 0 to avoid collisions with fixed header. */
   z-index: 0;
 }
diff --git a/gr-editor/codemirror-element.html b/gr-editor/codemirror-element.html
index 87a28b9..54aacd8 100644
--- a/gr-editor/codemirror-element.html
+++ b/gr-editor/codemirror-element.html
@@ -18,26 +18,29 @@
 
 <dom-module id="codemirror-element">
   <template>
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/lib/codemirror.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/ambiance.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/ambiance-mobile.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/blackboard.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/cobalt.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/eclipse.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/elegant.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/erlang-dark.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/lesser-dark.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/midnight.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/monokai.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/neat.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/night.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/rubyblue.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/solarized.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/twilight.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/vibrant-ink.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/xq-dark.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/theme/xq-light.css">
-    <link rel="stylesheet" type="css" href="../bower_components/codemirror-minified/addon/fold/foldgutter.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/lib/codemirror.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/ambiance.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/ambiance-mobile.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/blackboard.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/cobalt.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/eclipse.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/elegant.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/erlang-dark.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/lesser-dark.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/midnight.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/monokai.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/neat.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/night.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/rubyblue.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/solarized.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/twilight.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/vibrant-ink.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/xq-dark.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/theme/xq-light.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/addon/dialog/dialog.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/addon/fold/foldgutter.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/addon/scroll/simplescrollbars.css">
+    <link rel="stylesheet" type="css" href="../node_modules/codemirror-minified/addon/search/matchesonscrollbar.css">
 
     <link rel="stylesheet" type="css" href="./codemirror-element.css" />
     <div id="wrapper"></div>
@@ -45,61 +48,69 @@
   <script src="./codemirror-element.js"></script>
 </dom-module>
 
-<script src="../bower_components/codemirror-minified/lib/codemirror.js"></script>
-<script src="../bower_components/codemirror-minified/addon/display/rulers.js"></script>
-<script src="../bower_components/codemirror-minified/addon/edit/closebrackets.js"></script>
-<script src="../bower_components/codemirror-minified/addon/edit/closetag.js"></script>
-<script src="../bower_components/codemirror-minified/addon/edit/matchbrackets.js"></script>
-<script src="../bower_components/codemirror-minified/addon/edit/matchtags.js"></script>
-<script src="../bower_components/codemirror-minified/addon/edit/trailingspace.js"></script>
-<script src="../bower_components/codemirror-minified/addon/mode/simple.js"></script>
-<script src="../bower_components/codemirror-minified/addon/mode/multiplex.js"></script>
-<script src="../bower_components/codemirror-minified/mode/meta.js"></script>
-<script src="../bower_components/codemirror-minified/mode/clike/clike.js"></script>
-<script src="../bower_components/codemirror-minified/mode/clojure/clojure.js"></script>
-<script src="../bower_components/codemirror-minified/mode/coffeescript/coffeescript.js"></script>
-<script src="../bower_components/codemirror-minified/mode/commonlisp/commonlisp.js"></script>
-<script src="../bower_components/codemirror-minified/mode/css/css.js"></script>
-<script src="../bower_components/codemirror-minified/mode/d/d.js"></script>
-<script src="../bower_components/codemirror-minified/mode/dart/dart.js"></script>
-<script src="../bower_components/codemirror-minified/mode/diff/diff.js"></script>
-<script src="../bower_components/codemirror-minified/mode/django/django.js"></script>
-<script src="../bower_components/codemirror-minified/mode/dockerfile/dockerfile.js"></script>
-<script src="../bower_components/codemirror-minified/mode/erlang/erlang.js"></script>
-<script src="../bower_components/codemirror-minified/mode/go/go.js"></script>
-<script src="../bower_components/codemirror-minified/mode/groovy/groovy.js"></script>
-<script src="../bower_components/codemirror-minified/mode/haml/haml.js"></script>
-<script src="../bower_components/codemirror-minified/mode/handlebars/handlebars.js"></script>
-<script src="../bower_components/codemirror-minified/mode/haskell/haskell.js"></script>
-<script src="../bower_components/codemirror-minified/mode/htmlembedded/htmlembedded.js"></script>
-<script src="../bower_components/codemirror-minified/mode/htmlmixed/htmlmixed.js"></script>
-<script src="../bower_components/codemirror-minified/mode/javascript/javascript.js"></script>
-<script src="../bower_components/codemirror-minified/mode/jinja2/jinja2.js"></script>
-<script src="../bower_components/codemirror-minified/mode/jsx/jsx.js"></script>
-<script src="../bower_components/codemirror-minified/mode/julia/julia.js"></script>
-<script src="../bower_components/codemirror-minified/mode/lua/lua.js"></script>
-<script src="../bower_components/codemirror-minified/mode/markdown/markdown.js"></script>
-<script src="../bower_components/codemirror-minified/mode/mllike/mllike.js"></script>
-<script src="../bower_components/codemirror-minified/mode/nginx/nginx.js"></script>
-<script src="../bower_components/codemirror-minified/mode/perl/perl.js"></script>
-<script src="../bower_components/codemirror-minified/mode/php/php.js"></script>
-<script src="../bower_components/codemirror-minified/mode/powershell/powershell.js"></script>
-<script src="../bower_components/codemirror-minified/mode/properties/properties.js"></script>
-<script src="../bower_components/codemirror-minified/mode/protobuf/protobuf.js"></script>
-<script src="../bower_components/codemirror-minified/mode/puppet/puppet.js"></script>
-<script src="../bower_components/codemirror-minified/mode/python/python.js"></script>
-<script src="../bower_components/codemirror-minified/mode/rpm/rpm.js"></script>
-<script src="../bower_components/codemirror-minified/mode/ruby/ruby.js"></script>
-<script src="../bower_components/codemirror-minified/mode/sass/sass.js"></script>
-<script src="../bower_components/codemirror-minified/mode/scheme/scheme.js"></script>
-<script src="../bower_components/codemirror-minified/mode/shell/shell.js"></script>
-<script src="../bower_components/codemirror-minified/mode/soy/soy.js"></script>
-<script src="../bower_components/codemirror-minified/mode/sparql/sparql.js"></script>
-<script src="../bower_components/codemirror-minified/mode/sql/sql.js"></script>
-<script src="../bower_components/codemirror-minified/mode/swift/swift.js"></script>
-<script src="../bower_components/codemirror-minified/mode/tcl/tcl.js"></script>
-<script src="../bower_components/codemirror-minified/mode/velocity/velocity.js"></script>
-<script src="../bower_components/codemirror-minified/mode/verilog/verilog.js"></script>
-<script src="../bower_components/codemirror-minified/mode/vb/vb.js"></script>
-<script src="../bower_components/codemirror-minified/mode/xml/xml.js"></script>
-<script src="../bower_components/codemirror-minified/mode/yaml/yaml.js"></script>
+<script src="../node_modules/codemirror-minified/lib/codemirror.js"></script>
+<script src="../node_modules/codemirror-minified/addon/dialog/dialog.js"></script>
+<script src="../node_modules/codemirror-minified/addon/display/rulers.js"></script>
+<script src="../node_modules/codemirror-minified/addon/edit/closebrackets.js"></script>
+<script src="../node_modules/codemirror-minified/addon/edit/closetag.js"></script>
+<script src="../node_modules/codemirror-minified/addon/edit/matchbrackets.js"></script>
+<script src="../node_modules/codemirror-minified/addon/edit/matchtags.js"></script>
+<script src="../node_modules/codemirror-minified/addon/edit/trailingspace.js"></script>
+<script src="../node_modules/codemirror-minified/addon/scroll/annotatescrollbar.js"></script>
+<script src="../node_modules/codemirror-minified/addon/scroll/simplescrollbars.js"></script>
+<script src="../node_modules/codemirror-minified/addon/search/matchesonscrollbar.js"></script>
+<script src="../node_modules/codemirror-minified/addon/search/jump-to-line.js"></script>
+<script src="../node_modules/codemirror-minified/addon/search/matchesonscrollbar.js"></script>
+<script src="../node_modules/codemirror-minified/addon/search/searchcursor.js"></script>
+<script src="../node_modules/codemirror-minified/addon/search/search.js"></script>
+<script src="../node_modules/codemirror-minified/addon/mode/simple.js"></script>
+<script src="../node_modules/codemirror-minified/addon/mode/multiplex.js"></script>
+<script src="../node_modules/codemirror-minified/mode/meta.js"></script>
+<script src="../node_modules/codemirror-minified/mode/clike/clike.js"></script>
+<script src="../node_modules/codemirror-minified/mode/clojure/clojure.js"></script>
+<script src="../node_modules/codemirror-minified/mode/coffeescript/coffeescript.js"></script>
+<script src="../node_modules/codemirror-minified/mode/commonlisp/commonlisp.js"></script>
+<script src="../node_modules/codemirror-minified/mode/css/css.js"></script>
+<script src="../node_modules/codemirror-minified/mode/d/d.js"></script>
+<script src="../node_modules/codemirror-minified/mode/dart/dart.js"></script>
+<script src="../node_modules/codemirror-minified/mode/diff/diff.js"></script>
+<script src="../node_modules/codemirror-minified/mode/django/django.js"></script>
+<script src="../node_modules/codemirror-minified/mode/dockerfile/dockerfile.js"></script>
+<script src="../node_modules/codemirror-minified/mode/erlang/erlang.js"></script>
+<script src="../node_modules/codemirror-minified/mode/go/go.js"></script>
+<script src="../node_modules/codemirror-minified/mode/groovy/groovy.js"></script>
+<script src="../node_modules/codemirror-minified/mode/haml/haml.js"></script>
+<script src="../node_modules/codemirror-minified/mode/handlebars/handlebars.js"></script>
+<script src="../node_modules/codemirror-minified/mode/haskell/haskell.js"></script>
+<script src="../node_modules/codemirror-minified/mode/htmlembedded/htmlembedded.js"></script>
+<script src="../node_modules/codemirror-minified/mode/htmlmixed/htmlmixed.js"></script>
+<script src="../node_modules/codemirror-minified/mode/javascript/javascript.js"></script>
+<script src="../node_modules/codemirror-minified/mode/jinja2/jinja2.js"></script>
+<script src="../node_modules/codemirror-minified/mode/jsx/jsx.js"></script>
+<script src="../node_modules/codemirror-minified/mode/julia/julia.js"></script>
+<script src="../node_modules/codemirror-minified/mode/lua/lua.js"></script>
+<script src="../node_modules/codemirror-minified/mode/markdown/markdown.js"></script>
+<script src="../node_modules/codemirror-minified/mode/mllike/mllike.js"></script>
+<script src="../node_modules/codemirror-minified/mode/nginx/nginx.js"></script>
+<script src="../node_modules/codemirror-minified/mode/perl/perl.js"></script>
+<script src="../node_modules/codemirror-minified/mode/php/php.js"></script>
+<script src="../node_modules/codemirror-minified/mode/powershell/powershell.js"></script>
+<script src="../node_modules/codemirror-minified/mode/properties/properties.js"></script>
+<script src="../node_modules/codemirror-minified/mode/protobuf/protobuf.js"></script>
+<script src="../node_modules/codemirror-minified/mode/puppet/puppet.js"></script>
+<script src="../node_modules/codemirror-minified/mode/python/python.js"></script>
+<script src="../node_modules/codemirror-minified/mode/rpm/rpm.js"></script>
+<script src="../node_modules/codemirror-minified/mode/ruby/ruby.js"></script>
+<script src="../node_modules/codemirror-minified/mode/sass/sass.js"></script>
+<script src="../node_modules/codemirror-minified/mode/scheme/scheme.js"></script>
+<script src="../node_modules/codemirror-minified/mode/shell/shell.js"></script>
+<script src="../node_modules/codemirror-minified/mode/soy/soy.js"></script>
+<script src="../node_modules/codemirror-minified/mode/sparql/sparql.js"></script>
+<script src="../node_modules/codemirror-minified/mode/sql/sql.js"></script>
+<script src="../node_modules/codemirror-minified/mode/swift/swift.js"></script>
+<script src="../node_modules/codemirror-minified/mode/tcl/tcl.js"></script>
+<script src="../node_modules/codemirror-minified/mode/velocity/velocity.js"></script>
+<script src="../node_modules/codemirror-minified/mode/verilog/verilog.js"></script>
+<script src="../node_modules/codemirror-minified/mode/vb/vb.js"></script>
+<script src="../node_modules/codemirror-minified/mode/xml/xml.js"></script>
+<script src="../node_modules/codemirror-minified/mode/yaml/yaml.js"></script>
diff --git a/gr-editor/codemirror-element.js b/gr-editor/codemirror-element.js
index c49d6a1..94ee213 100644
--- a/gr-editor/codemirror-element.js
+++ b/gr-editor/codemirror-element.js
@@ -62,9 +62,10 @@
     this.scopeSubtree(this.$.wrapper, true);
     // eslint-disable-next-line new-cap
     this._nativeMirror = window.CodeMirror(this.$.wrapper, this._params);
-    this.async(() => {
+    setTimeout(() => {
       this._nativeMirror.refresh();
       this._nativeMirror.focus();
+      this._nativeMirror.setSize(null, window.screen.height);
       if (this.lineNum) {
         // We have to take away one from the line number,
         // ... because CodeMirror's line count is zero-based.
diff --git a/gr-editor/gr-editor.js b/gr-editor/gr-editor.js
index c88e2a8..1052df5 100644
--- a/gr-editor/gr-editor.js
+++ b/gr-editor/gr-editor.js
@@ -95,12 +95,6 @@
   return link;
 }
 
-// we need to be on codemirror 5.33.0+ to get the support for
-// text/x-php in CodeMirror.findModeByMIME
-const LANGUAGE_MAP = {
-  'text/x-php': 'php',
-};
-
 class GrEditor extends Polymer.Element {
   /**
    * Fired when the content of the editor changes.
@@ -193,7 +187,9 @@
    * @returns {Object}
    */
   getCodeMirrorParams(type, value, prefs) {
-    const params = {value, viewportMargin: Infinity};
+    const params = {value};
+
+    params.scrollbarStyle = 'overlay';
 
     if (prefs) {
       // TODO: Add gerrit's customizations from java codemirror to javascript
@@ -233,7 +229,7 @@
    * @returns {string}
    */
   _mapFileType(type) {
-    return LANGUAGE_MAP[type] || type || '';
+    return type || '';
   }
 }
 
diff --git a/package-lock.json b/package-lock.json
index f7f5734..36929d6 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -163,12 +163,6 @@
             "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
             "dev": true
         },
-        "bower": {
-            "version": "1.8.8",
-            "resolved": "https://registry.npmjs.org/bower/-/bower-1.8.8.tgz",
-            "integrity": "sha512-1SrJnXnkP9soITHptSO+ahx3QKp3cVzn8poI6ujqc5SeOkg5iqM1pK9H+DSc2OQ8SnO0jC/NG4Ur/UIwy7574A==",
-            "dev": true
-        },
         "brace-expansion": {
             "version": "1.1.11",
             "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
diff --git a/package.json b/package.json
index e298b9c..9823436 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,6 @@
         "@polymer/iron-test-helpers": "^3.0.1",
         "@webcomponents/shadycss": "^1.9.2",
         "@webcomponents/webcomponentsjs": "^1.3.3",
-        "bower": "^1.8.8",
         "es6-promise": "^3.3.1",
         "eslint": "^6.6.0",
         "eslint-config-google": "^0.13.0",