diff options
Diffstat (limited to 'cgithub/views')
| -rw-r--r-- | cgithub/views/layout.eta | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/cgithub/views/layout.eta b/cgithub/views/layout.eta index 85f431c..dd523d1 100644 --- a/cgithub/views/layout.eta +++ b/cgithub/views/layout.eta @@ -21,7 +21,7 @@ git clone git@github.com:<%= it.repo.owner %>/<%= it.repo.name %>.git</code></pr <% } %> </nav> <form action="/<%= it.repo.owner %>/<%= it.repo.name %>/search" method="get"> - <input type="text" name="q" placeholder="Search…" value="<%= it.q ?? "" %>"> + <input id="search-input" type="text" name="q" placeholder="Search…" value="<%= it.q ?? "" %>"> <select name="type"> <option value="issues" <%= it.searchType === "issues" ? "selected" : "" %>>Issues</option> <option value="pullrequests" <%= it.searchType === "pullrequests" ? "selected" : "" %>>Pull requests</option> @@ -34,5 +34,29 @@ git clone git@github.com:<%= it.repo.owner %>/<%= it.repo.name %>.git</code></pr <%~ it.body %> <footer>Generated by cgithub</footer> + + <script> + document.addEventListener("keydown", function(e) { + let shortcut = ""; + if (e.ctrlKey || e.metaKey) shortcut += "C-"; + if (e.altKey) shortcut += "A-"; + if (e.shiftKey) shortcut += "S-"; + shortcut += e.key; + + if (shortcut === "Escape") { + document.activeElement.blur(); + return; + } + + if (["INPUT", "TEXTAREA", "SELECT"].includes(document.activeElement.tagName)) { + return; + } + + if (shortcut === "/") { + e.preventDefault(); + document.getElementById('search-input').select(); + } + }); + </script> </body> </html> |
