fix: Search takes too much priority from cmd+k trigger
This commit is contained in:
@@ -25,7 +25,7 @@ import KeyboardShortcuts from "~/scenes/KeyboardShortcuts";
|
||||
import { createAction } from "~/actions";
|
||||
import {
|
||||
NavigationSection,
|
||||
NoSection,
|
||||
SearchSection,
|
||||
RecentSearchesSection,
|
||||
} from "~/actions/sections";
|
||||
import history from "~/utils/history";
|
||||
@@ -60,7 +60,7 @@ export const navigateToRecentSearchQuery = (searchQuery: SearchQuery) =>
|
||||
export const navigateToSearchQuery = (searchQuery: string) =>
|
||||
createAction({
|
||||
id: "search",
|
||||
section: NoSection,
|
||||
section: SearchSection,
|
||||
name: ({ t }) =>
|
||||
t(`Search documents for "{{searchQuery}}"`, { searchQuery }),
|
||||
icon: <SearchIcon />,
|
||||
|
||||
@@ -15,4 +15,4 @@ export const UserSection = ({ t }: ActionContext) => t("People");
|
||||
export const RecentSearchesSection = ({ t }: ActionContext) =>
|
||||
t("Recent searches");
|
||||
|
||||
export const NoSection = "";
|
||||
export const SearchSection = "";
|
||||
|
||||
@@ -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)`
|
||||
|
||||
@@ -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 }) =>
|
||||
|
||||
@@ -64,7 +64,7 @@ function AppSidebar() {
|
||||
if (isSearching) {
|
||||
history.push(searchPath());
|
||||
} else {
|
||||
ui.enableModKHint();
|
||||
ui.commandBarOpened();
|
||||
query.toggle();
|
||||
}
|
||||
}, [ui, location, history, query]);
|
||||
|
||||
@@ -58,8 +58,7 @@ const commandBarOptions = {
|
||||
exitMs: 200,
|
||||
},
|
||||
callbacks: {
|
||||
onClose: () => stores.ui.disableModKHint(),
|
||||
onQueryChange: () => stores.ui.disableModKHint(),
|
||||
onClose: () => stores.ui.commandBarClosed(),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class UiStore {
|
||||
observingUserId: string | undefined;
|
||||
|
||||
@observable
|
||||
showModKHint = false;
|
||||
commandBarOpenedFromSidebar = false;
|
||||
|
||||
@observable
|
||||
progressBarVisible = false;
|
||||
@@ -215,13 +215,13 @@ class UiStore {
|
||||
};
|
||||
|
||||
@action
|
||||
enableModKHint = () => {
|
||||
this.showModKHint = true;
|
||||
commandBarOpened = () => {
|
||||
this.commandBarOpenedFromSidebar = true;
|
||||
};
|
||||
|
||||
@action
|
||||
disableModKHint = () => {
|
||||
this.showModKHint = false;
|
||||
commandBarClosed = () => {
|
||||
this.commandBarOpenedFromSidebar = false;
|
||||
};
|
||||
|
||||
@action
|
||||
|
||||
Reference in New Issue
Block a user