]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cover: allow part selection to be retained across page refreshes
authorShenghou Ma <minux@golang.org>
Thu, 26 Nov 2015 22:45:09 +0000 (17:45 -0500)
committerMinux Ma <minux@golang.org>
Fri, 27 Nov 2015 06:13:12 +0000 (06:13 +0000)
Usually, you are primarily interested to see the coverage of a particular
file (e.g. when you're changing tests that affects a given source file),
it is very valuable if you can just refresh the page and immediately see
changes to the part you're already looking at (without selecting from the
selector again.)

Change-Id: I615207c9be6713f436e444771134fceaf4600ff3
Reviewed-on: https://go-review.googlesource.com/17238
Run-TryBot: Minux Ma <minux@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
src/cmd/cover/html.go

index bb0a495ae7214acc3f8734f6b2d3a9df1f5bf3fa..d0ac4476ba64b4eddb2e632c4c86e1dc49776480 100644 (file)
@@ -258,21 +258,35 @@ const tmplHTML = `
                </div>
                <div id="content">
                {{range $i, $f := .Files}}
-               <pre class="file" id="file{{$i}}" {{if $i}}style="display: none"{{end}}>{{$f.Body}}</pre>
+               <pre class="file" id="file{{$i}}" style="display: none">{{$f.Body}}</pre>
                {{end}}
                </div>
        </body>
        <script>
        (function() {
                var files = document.getElementById('files');
-               var visible = document.getElementById('file0');
+               var visible;
                files.addEventListener('change', onChange, false);
-               function onChange() {
-                       visible.style.display = 'none';
-                       visible = document.getElementById(files.value);
+               function select(part) {
+                       if (visible)
+                               visible.style.display = 'none';
+                       visible = document.getElementById(part);
+                       if (!visible)
+                               return;
+                       files.value = part;
                        visible.style.display = 'block';
+                       location.hash = part;
+               }
+               function onChange() {
+                       select(files.value);
                        window.scrollTo(0, 0);
                }
+               if (location.hash != "") {
+                       select(location.hash.substr(1));
+               }
+               if (!visible) {
+                       select("file0");
+               }
        })();
        </script>
 </html>