Bug 963937 - Add a pref to disable automatic bracket closing in source editor. r=anton
authorDagger <dagger.bugzilla+patch@gmail.com>
Thu, 30 Jan 2014 20:21:00 -0800
changeset 182252 7ca82e5818737429e0c587a3e1d152dbdfa6780d
parent 182251 54d9feac4e7a997a33ca657c125dd5bea04437d5
child 182253 f90200fac3cb5ee964cecd978b667cb264f9f376
child 182349 796764d8c4bfc963a88b338a1681c9808192d9ce
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersanton
bugs963937
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 963937 - Add a pref to disable automatic bracket closing in source editor. r=anton
browser/app/profile/firefox.js
browser/devtools/sourceeditor/editor.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1231,19 +1231,21 @@ pref("devtools.hud.loglimit.network", 20
 pref("devtools.hud.loglimit.cssparser", 200);
 pref("devtools.hud.loglimit.exception", 200);
 pref("devtools.hud.loglimit.console", 200);
 
 // The developer tools editor configuration:
 // - tabsize: how many spaces to use when a Tab character is displayed.
 // - expandtab: expand Tab characters to spaces.
 // - keymap: which keymap to use (can be 'default', 'emacs' or 'vim')
+// - autoclosebrackets: whether to permit automatic bracket/quote closing.
 pref("devtools.editor.tabsize", 4);
 pref("devtools.editor.expandtab", true);
 pref("devtools.editor.keymap", "default");
+pref("devtools.editor.autoclosebrackets", true);
 
 // Enable the Font Inspector
 pref("devtools.fontinspector.enabled", true);
 
 // Pref to store the browser version at the time of a telemetry ping for an
 // opened developer tool. This allows us to ping telemetry just once per browser
 // version for each user.
 pref("devtools.telemetry.tools.opened.version", "{}");
--- a/browser/devtools/sourceeditor/editor.js
+++ b/browser/devtools/sourceeditor/editor.js
@@ -5,16 +5,17 @@
 
 "use strict";
 
 const { Cu, Cc, Ci, components } = require("chrome");
 
 const TAB_SIZE    = "devtools.editor.tabsize";
 const EXPAND_TAB  = "devtools.editor.expandtab";
 const KEYMAP      = "devtools.editor.keymap";
+const AUTO_CLOSE  = "devtools.editor.autoclosebrackets";
 const L10N_BUNDLE = "chrome://browser/locale/devtools/sourceeditor.properties";
 const XUL_NS      = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
 // Maximum allowed margin (in number of lines) from top or bottom of the editor
 // while shifting to a line which was initially out of view.
 const MAX_VERTICAL_OFFSET = 3;
 
 const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
@@ -127,29 +128,31 @@ Editor.modes = {
  * This object is also an event emitter.
  *
  * CodeMirror docs: http://codemirror.net/doc/manual.html
  */
 function Editor(config) {
   const tabSize = Services.prefs.getIntPref(TAB_SIZE);
   const useTabs = !Services.prefs.getBoolPref(EXPAND_TAB);
   const keyMap = Services.prefs.getCharPref(KEYMAP);
+  const useAutoClose = Services.prefs.getBoolPref(AUTO_CLOSE);
 
   this.version = null;
   this.config = {
     value:             "",
     mode:              Editor.modes.text,
     indentUnit:        tabSize,
     tabSize:           tabSize,
     contextMenu:       null,
     matchBrackets:     true,
     extraKeys:         {},
     indentWithTabs:    useTabs,
     styleActiveLine:   true,
-    autoCloseBrackets: true,
+    autoCloseBrackets: "()[]{}''\"\"",
+    autoCloseEnabled:  useAutoClose,
     theme:             "mozilla"
   };
 
   // Additional shortcuts.
   this.config.extraKeys[Editor.keyFor("jumpToLine")] = () => this.jumpToLine();
   this.config.extraKeys[Editor.keyFor("moveLineUp")] = () => this.moveLineUp();
   this.config.extraKeys[Editor.keyFor("moveLineDown")] = () => this.moveLineDown();
   this.config.extraKeys[Editor.keyFor("toggleComment")] = "toggleComment";
@@ -182,16 +185,20 @@ function Editor(config) {
     this.config.foldGutter = true;
 
     if (!this.config.gutters) {
       this.config.gutters = this.config.lineNumbers ? ["CodeMirror-linenumbers"] : [];
       this.config.gutters.push("CodeMirror-foldgutter");
     }
   }
 
+  // Configure automatic bracket closing.
+  if (!this.config.autoCloseEnabled)
+    this.config.autoCloseBrackets = false;
+
   // Overwrite default tab behavior. If something is selected,
   // indent those lines. If nothing is selected and we're
   // indenting with tabs, insert one tab. Otherwise insert N
   // whitespaces where N == indentUnit option.
   this.config.extraKeys.Tab = (cm) => {
     if (cm.somethingSelected()) {
       cm.indentSelection("add");
       return;