Ned Batchelder avatar Ned Batchelder committed f7d2690

Hotkeys for the HTML report.

Comments (0)

Files changed (5)

 Version 3.5
 -----------
 
+- The HTML report now has hotkeys.  Try ``n``, ``s``, ``m``, ``x``, ``b``, 
+  ``p``, and ``c`` on the overview page to change the column sorting.
+  On a file page, ``r``, ``m``, ``x``, and ``p`` toggle the run, missing,
+  excluded, and partial line markings.
+
 - A little bit of Jython support: `coverage run` can now measure Jython
   execution by adapting when $py.class files are traced. Thanks, Adi Roiban.
 
             "style.css", 
             "jquery-1.4.3.min.js", 
             "jquery.tablesorter.min.js",
+            "jquery.hotkeys.js",
             "coverage_html.js",
             ]
 

coverage/htmlfiles/coverage_html.js

 
 coverage = {};
 
+// Find all the elements with shortkey_* class, and use them to assign a shotrtcut key.
+coverage.assign_shortkeys = function() {
+    $("*[class*='shortkey_']").each(function(i, e) {
+        console.log(i, e);
+        $.each($(e).attr("class").split(" "), function(i, c) {
+            if (/^shortkey_/.test(c)) {
+                $(document).bind('keydown', c.substr(9), function() {
+                    $(e).click();
+                });
+            }
+        });
+    });
+}
+
 // Loaded on index.html
 coverage.index_ready = function($) {
     // Look for a cookie containing previous sort settings:
         headers: headers
     });
 
+    coverage.assign_shortkeys();
+
     // Watch for page unload events so we can save the final sort settings:
     $(window).unload(function() {
         document.cookie = cookie_name + "=" + sort_list.toString() + "; path=/"
     if (frag.length > 2 && frag[1] == 'n') {
         $(frag).addClass('highlight');
     }
+
+    coverage.assign_shortkeys();
 }
 
 coverage.toggle_lines = function(btn, cls) {

coverage/htmlfiles/index.html

     <link rel='stylesheet' href='style.css' type='text/css'>
     <script type='text/javascript' src='jquery-1.4.3.min.js'></script>
     <script type='text/javascript' src='jquery.tablesorter.min.js'></script>
+    <script type='text/javascript' src='jquery.hotkeys.js'></script>
     <script type='text/javascript' src='coverage_html.js'></script>
     <script type='text/javascript' charset='utf-8'>
         jQuery(document).ready(coverage.index_ready);
         <thead>
             {# The title='' attr doesn't work in Safari. #}
             <tr class='tablehead' title='Click to sort'>
-                <th class='name left headerSortDown'>Module</th>
-                <th>statements</th>
-                <th>missing</th>
-                <th>excluded</th>
+                <th class='name left headerSortDown shortkey_n'>Module</th>
+                <th class='shortkey_s'>statements</th>
+                <th class='shortkey_m'>missing</th>
+                <th class='shortkey_x'>excluded</th>
                 {% if arcs %}
-                <th>branches</th>
-                <th>partial</th>
+                <th class='shortkey_b'>branches</th>
+                <th class='shortkey_p'>partial</th>
                 {% endif %}
-                <th class='right'>coverage</th>
+                <th class='right shortkey_c'>coverage</th>
             </tr>
         </thead>
         {# HTML syntax requires thead, tfoot, tbody #}

coverage/htmlfiles/pyfile.html

     <title>Coverage for {{cu.name|escape}}: {{nums.pc_covered_str}}%</title>
     <link rel='stylesheet' href='style.css' type='text/css'>
     <script type='text/javascript' src='jquery-1.4.3.min.js'></script>
+    <script type='text/javascript' src='jquery.hotkeys.js'></script>
     <script type='text/javascript' src='coverage_html.js'></script>
     <script type='text/javascript' charset='utf-8'>
         jQuery(document).ready(coverage.pyfile_ready);
         </h1>
         <h2 class='stats'>
             {{nums.n_statements}} statements
-            <span class='{{c_run}}' onclick='coverage.toggle_lines(this, "run")'>{{nums.n_executed}} run</span>
-            <span class='{{c_mis}}' onclick='coverage.toggle_lines(this, "mis")'>{{nums.n_missing}} missing</span>
-            <span class='{{c_exc}}' onclick='coverage.toggle_lines(this, "exc")'>{{nums.n_excluded}} excluded</span>
+            <span class='{{c_run}} shortkey_r' onclick='coverage.toggle_lines(this, "run")'>{{nums.n_executed}} run</span>
+            <span class='{{c_mis}} shortkey_m' onclick='coverage.toggle_lines(this, "mis")'>{{nums.n_missing}} missing</span>
+            <span class='{{c_exc}} shortkey_x' onclick='coverage.toggle_lines(this, "exc")'>{{nums.n_excluded}} excluded</span>
             {% if arcs %}
-                <span class='{{c_par}}' onclick='coverage.toggle_lines(this, "par")'>{{n_par}} partial</span>
+                <span class='{{c_par}} shortkey_p' onclick='coverage.toggle_lines(this, "par")'>{{n_par}} partial</span>
             {% endif %}
         </h2>
     </div>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.