Bug 913060 - Pretty print should use devtools.editor.tabsize. r=fitzgen
authorSunny <indiasuny000@gmail.com>
Sun, 15 Sep 2013 16:05:35 -0400
changeset 160171 5cfd1ce18d07928318e201174e568ee945513246
parent 160170 e13b2b7c34a444a32889f1c52479e2cdabf19c17
child 160172 91b7634a29d7a199894a60c05579c6688a975d69
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfitzgen
bugs913060
milestone26.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 913060 - Pretty print should use devtools.editor.tabsize. r=fitzgen
browser/devtools/scratchpad/scratchpad.js
browser/devtools/scratchpad/test/Makefile.in
browser/devtools/scratchpad/test/browser_scratchpad_pprint-02.js
--- a/browser/devtools/scratchpad/scratchpad.js
+++ b/browser/devtools/scratchpad/scratchpad.js
@@ -524,19 +524,26 @@ var Scratchpad = {
     return deferred.promise;
   },
 
   /**
    * Pretty print the source text inside the scratchpad.
    */
   prettyPrint: function SP_prettyPrint() {
     const uglyText = this.getText();
+    const tabsize = Services.prefs.getIntPref("devtools.editor.tabsize");
     try {
       const ast = Reflect.parse(uglyText);
-      const prettyText = escodegen.generate(ast);
+      const prettyText = escodegen.generate(ast, {
+        format: {
+          indent: {
+            style: " ".repeat(tabsize)
+          }
+        }
+      });
       this.setText(prettyText);
     } catch (e) {
       this.writeAsErrorComment(DevToolsUtils.safeErrorString(e));
     }
   },
 
   /**
    * Writes out a primitive value as a comment. This handles values which are
--- a/browser/devtools/scratchpad/test/Makefile.in
+++ b/browser/devtools/scratchpad/test/Makefile.in
@@ -27,12 +27,13 @@ MOCHITEST_BROWSER_FILES = \
 		browser_scratchpad_bug_751744_revert_to_saved.js \
 		browser_scratchpad_bug740948_reload_and_run.js \
 		browser_scratchpad_bug_661762_wrong_window_focus.js \
 		browser_scratchpad_bug_644413_modeline.js \
 		browser_scratchpad_bug807924_cannot_convert_to_string.js \
 		browser_scratchpad_long_string.js \
 		browser_scratchpad_open_error_console.js \
 		browser_scratchpad_pprint.js \
+		browser_scratchpad_pprint-02.js\
 		head.js \
 
 # Disable test due to bug 807234 becoming basically permanent
 #		browser_scratchpad_bug_653427_confirm_close.js \
new file mode 100644
--- /dev/null
+++ b/browser/devtools/scratchpad/test/browser_scratchpad_pprint-02.js
@@ -0,0 +1,32 @@
+/* vim: set ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function test()
+{
+  waitForExplicitFinish();
+
+  gBrowser.selectedTab = gBrowser.addTab();
+  gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
+    gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
+    openScratchpad(runTests);
+  }, true);
+
+  content.location = "data:text/html;charset=utf8,test Scratchpad pretty print.";
+}
+
+function runTests(sw)
+{
+  const tabsize = Services.prefs.getIntPref("devtools.editor.tabsize");
+  Services.prefs.setIntPref("devtools.editor.tabsize", 6);
+  const space = " ".repeat(6);
+
+  const sp = sw.Scratchpad;
+  sp.setText("function main() { console.log(5); }");
+  sp.prettyPrint();
+  const prettyText = sp.getText();
+  ok(prettyText.contains(space));
+
+  Services.prefs.setIntPref("devtools.editor.tabsize", tabsize);
+  finish();
+}