hterm 1.34: Add ctrl-plus-minus-zero-zoom preference.

* In the default state (true) hterm works the same as before.  If set to
  false, ctrl-shift-plus/minus/zero controls zoom, and ctrl-minus sends ^_.

Change-Id: Ie35eee99173e8ba003e23008038689936c62d524
Reviewed-on: https://chromium-review.googlesource.com/190069
Reviewed-by: Marvelous Marius <mschilder@chromium.org>
Commit-Queue: Marvelous Marius <mschilder@chromium.org>
Tested-by: Robert Ginda <rginda@chromium.org>
diff --git a/hterm/doc/changelog.txt b/hterm/doc/changelog.txt
index a5e9b23..b111056 100644
--- a/hterm/doc/changelog.txt
+++ b/hterm/doc/changelog.txt
@@ -1,6 +1,7 @@
-1.33, 2014-03-14, Fix user-css merge lossage.
+1.34, 2014-03-14, Add ctrl-plus-minus-zero-zoom preference.
 
-* A previous merge lost the user-css pref changes to hterm_terminal.js.
+* In the default state (true) hterm works the same as before.  If set to
+  false, ctrl-shift-plus/minus/zero controls zoom, and ctrl-minus sends ^_.
 
 1.32, 2014-03-04, Disable local selection in all mouse reporting modes.
 
diff --git a/hterm/js/hterm_keyboard.js b/hterm/js/hterm_keyboard.js
index e52a4bb..71fece2 100644
--- a/hterm/js/hterm_keyboard.js
+++ b/hterm/js/hterm_keyboard.js
@@ -57,6 +57,13 @@
   this.pageKeysScroll = false;
 
   /**
+   * If true, Ctrl-Plus/Minus/Zero controls zoom.
+   * If false, Ctrl-Shift-Plus/Minus/Zero controls zoom, Ctrl-Minus sends ^_,
+   * Ctrl-Plus/Zero do nothing.
+   */
+  this.ctrlPlusMinusZeroZoom = true;
+
+  /**
    * If true, don't send Ctrl-V to the host, but instead paste the contents of
    * the clipboard. In that case, send a ^V to the host on Ctrl-Shift-V.
    */
diff --git a/hterm/js/hterm_keyboard_keymap.js b/hterm/js/hterm_keyboard_keymap.js
index 1fb56f1..dbb4c6d 100644
--- a/hterm/js/hterm_keyboard_keymap.js
+++ b/hterm/js/hterm_keyboard_keymap.js
@@ -230,9 +230,9 @@
     [55,  '7&', DEFAULT, c('onCtrlNum_'),    c('onAltNum_'), c('onMetaNum_')],
     [56,  '8*', DEFAULT, c('onCtrlNum_'),    c('onAltNum_'), c('onMetaNum_')],
     [57,  '9(', DEFAULT, c('onCtrlNum_'),    c('onAltNum_'), c('onMetaNum_')],
-    [48,  '0)', DEFAULT, c('onZoom_'),       c('onAltNum_'), c('onMetaNum_')],
-    [189, '-_', DEFAULT, sh(c('onZoom_'), ctl('_')),    DEFAULT,     DEFAULT],
-    [187, '=+', DEFAULT, c('onZoom_'),                  DEFAULT,     DEFAULT],
+    [48,  '0)', DEFAULT, c('onPlusMinusZero_'),c('onAltNum_'),c('onMetaNum_')],
+    [189, '-_', DEFAULT, c('onPlusMinusZero_'),         DEFAULT,     DEFAULT],
+    [187, '=+', DEFAULT, c('onPlusMinusZero_'),         DEFAULT,     DEFAULT],
     [8,   '[BKSP]', bs('\x7f', '\b'), bs('\b', '\x7f'), DEFAULT,     DEFAULT],
 
     // Third row.
@@ -587,7 +587,18 @@
  * We override the browser zoom keys to change the ScrollPort's font size to
  * avoid the issue.
  */
-hterm.Keyboard.KeyMap.prototype.onZoom_ = function(e, keyDef) {
+hterm.Keyboard.KeyMap.prototype.onPlusMinusZero_ = function(e, keyDef) {
+  if (!(this.keyboard.ctrlPlusMinusZeroZoom ^ e.shiftKey)) {
+    // If ctrl-PMZ controls zoom and the shift key is pressed, or
+    // ctrl-shift-PMZ controls zoom and this shift key is not pressed,
+    // then we want to send the control code instead of affecting zoom.
+    if (keyDef.keyCap == '-_')
+      return '\x1f';  // ^_
+
+    // Only ^_ is valid, the other sequences have no meaning.
+    return hterm.Keyboard.KeyActions.CANCEL;
+  }
+
   if (this.keyboard.terminal.getZoomFactor() != 1) {
     // If we're not at 1:1 zoom factor, let the Ctrl +/-/0 keys control the
     // browser zoom, so it's easier to for the user to get back to 100%.
diff --git a/hterm/js/hterm_preference_manager.js b/hterm/js/hterm_preference_manager.js
index 734568a..34ccc51 100644
--- a/hterm/js/hterm_preference_manager.js
+++ b/hterm/js/hterm_preference_manager.js
@@ -111,6 +111,13 @@
     ['copy-on-select', true],
 
     /**
+     * If true, Ctrl-Plus/Minus/Zero controls zoom.
+     * If false, Ctrl-Shift-Plus/Minus/Zero controls zoom, Ctrl-Minus sends ^_,
+     * Ctrl-Plus/Zero do nothing.
+     */
+    ['ctrl-plus-minus-zero-zoom', true],
+
+    /**
      * Ctrl+V pastes if true, sent to host if false.
      * Ctrl+Shift+V sends a ^V to host if true, pastes if false.
      */
diff --git a/hterm/js/hterm_terminal.js b/hterm/js/hterm_terminal.js
index bfaba22..8b62d93 100644
--- a/hterm/js/hterm_terminal.js
+++ b/hterm/js/hterm_terminal.js
@@ -261,6 +261,10 @@
       terminal.copyOnSelect = !!v;
     },
 
+    'ctrl-plus-minus-zero-zoom': function(v) {
+      terminal.keyboard.ctrlPlusMinusZeroZoom = v;
+    },
+
     'ctrl-v-paste': function(v) {
       terminal.keyboard.ctrlVPaste = v;
     },