Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

docs: Allow navigating search results with arrow keys (#50901)

Abinashcbb7982989cb
diff --git a/docs/theme/css/chrome.css b/docs/theme/css/chrome.css
index 3f4fa40bc41..8f5b40cc19e 100644
--- a/docs/theme/css/chrome.css
+++ b/docs/theme/css/chrome.css
@@ -368,7 +368,10 @@ mark.fade-out {
.searchbar-outer {
margin-inline-start: auto;
margin-inline-end: auto;
+ width: 100%;
max-width: var(--content-max-width);
+ box-sizing: border-box;
+ padding: 16px;
}
#searchbar {
@@ -394,21 +397,21 @@ mark.fade-out {
.searchresults-header {
font-weight: bold;
font-size: 1em;
- padding-block-start: 18px;
+ padding-block-start: 0;
padding-block-end: 0;
- padding-inline-start: 5px;
- padding-inline-end: 0;
color: var(--searchresults-header-fg);
}
ul#searchresults {
list-style: none;
padding-inline-start: 0;
+ margin-block-end: 0;
}
ul#searchresults li {
margin: 10px 0px;
padding: 2px;
border-radius: 2px;
+ scroll-margin-block-end: 10px;
}
ul#searchresults li.focus {
background-color: var(--searchresults-li-bg);
@@ -794,8 +797,7 @@ ul#searchresults span.teaser em {
max-height: 600px;
display: flex;
flex-direction: column;
- padding: 16px;
- overflow-y: auto;
+ overflow-y: hidden;
border-radius: 8px;
background: var(--popover-bg);
@@ -803,8 +805,11 @@ ul#searchresults span.teaser em {
box-shadow: var(--popover-shadow);
}
-.searchbar-outer {
- width: 100%;
+.searchresults-outer {
+ flex: 1;
+ min-height: 0;
+ overflow-y: auto;
+ padding: 0px 22px 22px 22px;
}
#searchbar {
diff --git a/docs/theme/index.hbs b/docs/theme/index.hbs
index 1c833ee94d4..24378bcca69 100644
--- a/docs/theme/index.hbs
+++ b/docs/theme/index.hbs
@@ -424,6 +424,31 @@
<script src="{{ path_to_root }}elasticlunr.min.js"></script>
<script src="{{ path_to_root }}mark.min.js"></script>
<script src="{{ path_to_root }}searcher.js"></script>
+
+ <script>
+ (function () {
+ // Check for focused search result and bring into the view
+ const ensureVisible = () => {
+ const focused = document.querySelector("#searchresults li.focus");
+
+ if (focused) {
+ focused.scrollIntoView({
+ block: "nearest",
+ inline: "nearest"
+ });
+ }
+ };
+
+ // 1. Listen for arrow key events
+ // 2. Wait for DOM to update
+ // 3. Call envsureVisible
+ document.addEventListener("keydown", function (e) {
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
+ requestAnimationFrame(ensureVisible);
+ }
+ });
+ })();
+ </script>
{{/if}}
<script src="{{ path_to_root }}clipboard.min.js"></script>