fix: allow command palette search results to open in new tab

This commit is contained in:
Vihar Kurama
2025-10-23 12:17:19 +01:00
parent e710f5b278
commit 7743e59fff

View File

@@ -3,6 +3,7 @@
import { Command } from "cmdk"; import { Command } from "cmdk";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { useParams } from "next/navigation"; import { useParams } from "next/navigation";
import type { MouseEvent } from "react";
// plane imports // plane imports
import type { IWorkspaceSearchResults } from "@plane/types"; import type { IWorkspaceSearchResults } from "@plane/types";
// hooks // hooks
@@ -35,28 +36,43 @@ export const CommandPaletteSearchResults: React.FC<Props> = observer((props) =>
if (section.length > 0) { if (section.length > 0) {
return ( return (
<Command.Group key={key} heading={`${currentSection.title} search`}> <Command.Group key={key} heading={`${currentSection.title} search`}>
{section.map((item: any) => ( {section.map((item: any) => {
<Command.Item const targetPath = currentSection.path(item, projectId);
key={item.id} const itemProjectId =
onSelect={() => { item?.project_id ||
closePalette(); (Array.isArray(item?.project_ids) && item?.project_ids?.length > 0
router.push(currentSection.path(item, projectId)); ? item?.project_ids[0]
const itemProjectId = : undefined);
item?.project_id ||
(Array.isArray(item?.project_ids) && item?.project_ids?.length > 0 const handleMetaClick = (event: MouseEvent<HTMLDivElement>) => {
? item?.project_ids[0] if (!event.metaKey && !event.ctrlKey) return;
: undefined);
if (itemProjectId) openProjectAndScrollToSidebar(itemProjectId); event.preventDefault();
}} event.stopPropagation();
value={`${key}-${item?.id}-${item.name}-${item.project__identifier ?? ""}-${item.sequence_id ?? ""}`}
className="focus:outline-none" closePalette();
> window.open(targetPath, "_blank", "noopener,noreferrer");
<div className="flex items-center gap-2 overflow-hidden text-custom-text-200"> };
{currentSection.icon}
<p className="block flex-1 truncate">{currentSection.itemName(item)}</p> return (
</div> <Command.Item
</Command.Item> key={item.id}
))} onMouseDown={handleMetaClick}
onSelect={() => {
closePalette();
router.push(targetPath);
if (itemProjectId) openProjectAndScrollToSidebar(itemProjectId);
}}
value={`${key}-${item?.id}-${item.name}-${item.project__identifier ?? ""}-${item.sequence_id ?? ""}`}
className="focus:outline-none"
>
<div className="flex items-center gap-2 overflow-hidden text-custom-text-200">
{currentSection.icon}
<p className="block flex-1 truncate">{currentSection.itemName(item)}</p>
</div>
</Command.Item>
);
})}
</Command.Group> </Command.Group>
); );
} }