Skip to content

Commit d67d664

Browse files
authored
feat: automatically selects the first entry after searching (#411)
* feat: automatically selects the first entry after searching * docs: update changelog * refactor: remove debug log statements
1 parent 6329354 commit d67d664

4 files changed

Lines changed: 13 additions & 13 deletions

File tree

docs/content.en/docs/release-notes/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Information about release notes of Coco Server is provided here.
2626
- feat: add error notification #386
2727
- feat: add support for AI assistant #394
2828
- feat: add support for calculator function #399
29+
- feat: auto selects the first item after searching #411
2930

3031
### Bug fix
3132

src/components/Common/Icons/TypeIcon.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ function TypeIcon({
1717
className = "w-5 h-5 flex-shrink-0",
1818
onClick = () => {},
1919
}: TypeIconProps) {
20-
console.log("item", item);
2120
const endpoint_http = useAppStore((state) => state.endpoint_http);
2221
const connectorSource = useFindConnectorIcon(item);
2322

src/components/Search/ContextMenu.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
useClickAway,
3-
useCreation,
4-
useEventListener,
5-
useReactive,
6-
} from "ahooks";
1+
import { useClickAway, useCreation, useReactive } from "ahooks";
72
import clsx from "clsx";
83
import { isNil, noop } from "lodash-es";
94
import { Copy, Link, SquareArrowOutUpRight } from "lucide-react";
@@ -15,6 +10,7 @@ import { useSearchStore } from "@/stores/searchStore";
1510
import { copyToClipboard, OpenURLWithBrowser } from "@/utils";
1611
import { isMac } from "@/utils/platform";
1712
import { CONTEXT_MENU_PANEL_ID } from "@/constants";
13+
import { useShortcutsStore } from "@/stores/shortcutsStore";
1814

1915
interface State {
2016
activeMenuIndex: number;
@@ -36,6 +32,7 @@ const ContextMenu = ({ hideCoco }: ContextMenuProps) => {
3632
const setVisibleContextMenu = useSearchStore((state) => {
3733
return state.setVisibleContextMenu;
3834
});
35+
const setOpenPopover = useShortcutsStore((state) => state.setOpenPopover);
3936

4037
const selectedSearchContent = useSearchStore((state) => {
4138
return state.selectedSearchContent;
@@ -157,11 +154,9 @@ const ContextMenu = ({ hideCoco }: ContextMenuProps) => {
157154
handleClick(item?.clickEvent);
158155
});
159156

160-
useEventListener("keydown", (event) => {
161-
if (!visibleContextMenu) return;
162-
163-
event.stopImmediatePropagation();
164-
});
157+
useEffect(() => {
158+
setOpenPopover(visibleContextMenu);
159+
}, [visibleContextMenu]);
165160

166161
const handleClick = (click = noop) => {
167162
click?.();

src/components/Search/DropdownList.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ function DropdownList({
7575
}
7676
}, [isChatMode]);
7777

78+
useEffect(() => {
79+
setSelectedItem(0);
80+
}, [suggests]);
81+
7882
const openPopover = useShortcutsStore((state) => state.openPopover);
7983

8084
const handleKeyDown = useCallback(
@@ -85,6 +89,7 @@ function DropdownList({
8589
// showIndex,
8690
// e.key >= "0" && e.key <= "9" && showIndex
8791
// );
92+
8893
if (!suggests.length || openPopover) return;
8994

9095
if (e.key === "ArrowUp") {
@@ -141,7 +146,7 @@ function DropdownList({
141146
}
142147
}
143148
},
144-
[suggests, selectedItem, showIndex, globalItemIndexMap]
149+
[suggests, selectedItem, showIndex, globalItemIndexMap, openPopover]
145150
);
146151

147152
const handleKeyUp = useCallback((e: KeyboardEvent) => {

0 commit comments

Comments
 (0)