fix: Search takes too much priority from cmd+k trigger

This commit is contained in:
Tom Moor
2022-02-26 11:47:48 -08:00
parent 7f05fe0127
commit 6cbc30172c
7 changed files with 26 additions and 20 deletions

View File

@@ -42,8 +42,10 @@ function CommandBar() {
t("Type a command or search")
}`}
/>
<CommandBarResults />
{ui.showModKHint && (
<CommandBarResults
prioritizeSearchResults={ui.commandBarOpenedFromSidebar}
/>
{ui.commandBarOpenedFromSidebar && (
<Hint size="small" type="tertiary">
<QuestionMarkIcon size={18} color="currentColor" />
{t(
@@ -77,14 +79,10 @@ const Hint = styled(Text)`
display: flex;
align-items: center;
gap: 4px;
background: ${(props) => props.theme.secondaryBackground};
border-top: 1px solid ${(props) => props.theme.background};
margin: 1px 0 0;
padding: 6px 16px;
width: 100%;
position: absolute;
bottom: 0;
`;
const Positioner = styled(KBarPositioner)`

View File

@@ -3,15 +3,24 @@ import { orderBy } from "lodash";
import * as React from "react";
import styled from "styled-components";
import CommandBarItem from "~/components/CommandBarItem";
import { NoSection } from "~/actions/sections";
import { SearchSection } from "~/actions/sections";
export default function CommandBarResults() {
type Props = {
prioritizeSearchResults: boolean;
};
export default function CommandBarResults(props: Props) {
const { results, rootActionId } = useMatches();
return (
<KBarResults
items={orderBy(results, (item) =>
typeof item !== "string" && item.section === NoSection ? -1 : 1
// this is an unfortunate hack until kbar supports priority internally
typeof item !== "string" &&
item.section === SearchSection &&
props.prioritizeSearchResults
? -1
: 1
)}
maxHeight={400}
onRender={({ item, active }) =>

View File

@@ -64,7 +64,7 @@ function AppSidebar() {
if (isSearching) {
history.push(searchPath());
} else {
ui.enableModKHint();
ui.commandBarOpened();
query.toggle();
}
}, [ui, location, history, query]);