]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: make expanded/hidden columns in GOSSAFUNC persist across
authorroot <2863768433@qq.com>
Mon, 17 Aug 2020 02:03:06 +0000 (10:03 +0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 18 Sep 2020 04:16:08 +0000 (04:16 +0000)
reloads

use pushState with updated state and read it on page load,so that state
can survive across reloads.

Change-Id: I6c5e80e9747576245b979a62cb96d231d8f27d57
Reviewed-on: https://go-review.googlesource.com/c/go/+/248687
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bradford Lamson-Scribner <brad.lamson@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Josh Bleecher Snyder <josharian@gmail.com>

src/cmd/compile/internal/ssa/html.go

index 1c70b64708d1adb90fc30d00caf2b89bd7977ea5..c781ca92ccc53e5d934740badb8507ee99d4c502 100644 (file)
@@ -358,6 +358,21 @@ body.darkmode ellipse.outline-black { outline: gray solid 2px; }
 </style>
 
 <script type="text/javascript">
+
+// Contains phase names which are expanded by default. Other columns are collapsed.
+let expandedDefault = [
+    "start",
+    "deadcode",
+    "opt",
+    "lower",
+    "late-deadcode",
+    "regalloc",
+    "genssa",
+];
+if (history.state === null) {
+    history.pushState({expandedDefault}, "", location.href);
+}
+
 // ordered list of all available highlight colors
 var highlights = [
     "highlight-aquamarine",
@@ -402,6 +417,9 @@ for (var i = 0; i < outlines.length; i++) {
 }
 
 window.onload = function() {
+    if (history.state !== null) {
+        expandedDefault = history.state.expandedDefault;
+    }
     if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
         toggleDarkMode();
         document.getElementById("dark-mode-button").checked = true;
@@ -410,9 +428,6 @@ window.onload = function() {
     var ssaElemClicked = function(elem, event, selections, selected) {
         event.stopPropagation();
 
-        // TODO: pushState with updated state and read it on page load,
-        // so that state can survive across reloads
-
         // find all values with the same name
         var c = elem.classList.item(0);
         var x = document.getElementsByClassName(c);
@@ -490,21 +505,18 @@ window.onload = function() {
         lines[i].addEventListener('click', ssaValueClicked);
     }
 
-    // Contains phase names which are expanded by default. Other columns are collapsed.
-    var expandedDefault = [
-        "start",
-        "deadcode",
-        "opt",
-        "lower",
-        "late-deadcode",
-        "regalloc",
-        "genssa",
-    ];
 
     function toggler(phase) {
         return function() {
             toggle_cell(phase+'-col');
             toggle_cell(phase+'-exp');
+            const i = expandedDefault.indexOf(phase);
+            if (i !== -1) {
+                expandedDefault.splice(i, 1);
+            } else {
+                expandedDefault.push(phase);
+            }
+            history.pushState({expandedDefault}, "", location.href);
         };
     }
 
@@ -532,9 +544,13 @@ window.onload = function() {
             const len = combined.length;
             if (len > 1) {
                 for (let i = 0; i < len; i++) {
-                    if (expandedDefault.indexOf(combined[i]) !== -1) {
-                        show = true;
-                        break;
+                    const num = expandedDefault.indexOf(combined[i]);
+                    if (num !== -1) {
+                        expandedDefault.splice(num, 1);
+                        if (expandedDefault.indexOf(phase) === -1) {
+                            expandedDefault.push(phase);
+                            show = true;
+                        }
                     }
                 }
             }