Skip to content

Commit 26c9df5

Browse files
committed
add visual indication for search shortcut
1 parent 41a8826 commit 26c9df5

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

docs/_static/custom.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ div.admonition.admonition-todo>.admonition-title::before {
177177

178178
/* Search */
179179

180+
#search-shortcut-page {
181+
position: absolute;
182+
right: 9.375rem;
183+
top: 0.1875rem;
184+
border-radius: 0.25em;
185+
background: #d9eef9;
186+
padding: 0.2em;
187+
color: #4a4a4a;
188+
}
189+
180190
/* Show search form. It is hidden by default. */
181191
#search-documentation,
182192
#search-documentation~form,
@@ -305,13 +315,26 @@ div.sidebar:not(.margin) .admonition {
305315
margin-right: .5em;
306316
background-color: #ffffff;
307317
}
318+
#search-shortcut-sidebar {
319+
position: absolute;
320+
right: 1.25rem;
321+
border-radius: 0.25em;
322+
background: #d9eef9;
323+
padding: 0.2em;
324+
color: #4a4a4a;
325+
font-size: 1rem;
326+
}
308327

309328
@media (min-width:768px) {
310329
div.sidebar:not(.margin) {
311330
width: 50%;
312331
margin-left: 1.5em;
313332
margin-right: -28%;
314333
}
334+
335+
#search-shortcut-sidebar {
336+
font-size: inherit;
337+
}
315338
}
316339

317340

docs/_templates/page.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
$('#search-input').focus();
2020
}
2121
});
22+
if (navigator.platform.indexOf('Mac') === -1) $('#search-shortcut-sidebar').html("^K"); // if OS isn't Mac change Visual indication of search field
2223
</script>
2324

2425
{% endblock %}

docs/_templates/search-field.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<form class="bd-search d-flex align-items-center" action="{{ pathto('search') }}" method="get">
2+
<i class="icon fas fa-search"></i>
3+
<input type="search" class="form-control" name="q" id="search-input" placeholder="{{ _(theme_search_bar_text) }}" aria-label="{{ theme_search_bar_text }}" autocomplete="off" >
4+
<span id="search-shortcut-sidebar">⌘K</span>
5+
</form>

docs/_templates/search.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ <h1 id="search-documentation">{{ _('Search') }}</h1>
5353
class="form-control"
5454
placeholder="Search the docs…"
5555
aria-labelledby="search-documentation" value="" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
56+
<span id="search-shortcut-page">⌘K</span>
5657
<label for="q" class="sr-only">Search string</label>
5758
<div class="input-group-append">
5859
<button type="submit" class="btn btn-primary">{{ _('search') }}</button>
@@ -122,6 +123,15 @@ <h1 id="search-documentation">{{ _('Search') }}</h1>
122123
$(".topbar-contents .bd-toc").css("visibility", "hidden");
123124
}
124125
});
126+
127+
$('form.bd-search').css('visibility','hidden'); // Hide Sidebar Search field
128+
if (navigator.platform.indexOf('Mac') === -1) $('#search-shortcut-page').html("^K"); // if OS isn't Mac change Visual indication of search field
129+
$(document).keydown(function(event) {
130+
if ((event.ctrlKey || event.metaKey) && event.key == "k") {
131+
event.preventDefault();
132+
$('#q').focus();
133+
}
134+
});
125135
</script>
126136

127137
{% endblock %}

0 commit comments

Comments
 (0)