瀏覽代碼

PG - Added a 'format code' button

Temechon 8 年之前
父節點
當前提交
4e94065b8c
共有 2 個文件被更改,包括 8 次插入0 次删除
  1. 1 0
      Playground/index.html
  2. 7 0
      Playground/js/index.js

+ 1 - 0
Playground/index.html

@@ -124,6 +124,7 @@
                     <div class="option checked" id="editorButton">Editor <i class="fa fa-check-square" aria-hidden="true"></i>
                     </div>
                     <div class="option" id="fullscreenButton">Fullscreen</div>
+                    <div class="option" id="formatButton">Format code</div>
                 </div>
             </div>
 

+ 7 - 0
Playground/js/index.js

@@ -598,6 +598,12 @@
             document.getElementById("saveLayer").style.display = "block";
         }
 
+        var formatCode = function () {
+            jsEditor.getAction('editor.action.format').run();
+            var actions = jsEditor.getActions();
+            console.table(actions);
+        }
+
         // UI
         document.getElementById("runButton").addEventListener("click", compileAndRun);
         document.getElementById("zipButton").addEventListener("click", getZip);
@@ -609,6 +615,7 @@
         document.getElementById("metadataButton").addEventListener("click", toggleMetadata);
         document.getElementById("darkTheme").addEventListener("click", toggleTheme.bind(this, 'dark'));
         document.getElementById("lightTheme").addEventListener("click", toggleTheme.bind(this, 'light'));
+        document.getElementById("formatButton").addEventListener("click", formatCode);
 
         // Restore theme
         var theme = localStorage.getItem("bjs-playground-theme") || 'light';