refactor: restore default cursor movement with meta + arrow keys (#951)

This commit is contained in:
ayangweb
2025-10-27 10:10:14 +08:00
committed by GitHub
parent fa9656bfd7
commit e5860f63c7
3 changed files with 5 additions and 61 deletions

View File

@@ -41,7 +41,8 @@ export const SearchSource: React.FC<SearchSourceProps> = ({
defaultIcon={isDark ? source_default_dark_img : source_default_img}
className="w-4 h-4"
/>
{sourceName} {isTauri && items[0]?.source?.name && `- ${items[0].source.name}`}
{sourceName}{" "}
{isTauri && items[0]?.source?.name && `- ${items[0].source.name}`}
<div className="flex-1 border-b border-b-[#e6e6e6] dark:border-b-[#272626]"></div>
{!hideArrow && (
<>
@@ -56,7 +57,7 @@ export const SearchSource: React.FC<SearchSourceProps> = ({
</IconWrapper>
{showIndex && sourceName === selectedName && (
<div className="absolute top-1 right-4">
<VisibleKey shortcut="" />
<VisibleKey shortcut="Tab" shortcutClassName="w-8" />
</div>
)}
</>

View File

@@ -1,53 +1,9 @@
import { useCallback, useEffect } from "react";
import { useEffect } from "react";
import { useSearchStore } from "@/stores/searchStore";
import { useShortcutsStore } from "@/stores/shortcutsStore";
export function useKeyboardHandlers() {
const {
setSourceData,
visibleExtensionStore,
setVisibleExtensionStore,
visibleExtensionDetail,
setVisibleExtensionDetail,
} = useSearchStore();
const { modifierKey } = useShortcutsStore();
const getModifierKeyPressed = (event: KeyboardEvent) => {
const metaKeyPressed = event.metaKey && modifierKey === "meta";
const ctrlKeyPressed = event.ctrlKey && modifierKey === "ctrl";
const altKeyPressed = event.altKey && modifierKey === "alt";
return metaKeyPressed || ctrlKeyPressed || altKeyPressed;
};
const handleKeyDown = useCallback(
(e: KeyboardEvent) => {
// Handle ArrowLeft with meta key
if (e.code === "ArrowLeft" && getModifierKeyPressed(e)) {
e.preventDefault();
if (visibleExtensionDetail) {
return setVisibleExtensionDetail(false);
}
if (visibleExtensionStore) {
return setVisibleExtensionStore(false);
}
return setSourceData(void 0);
}
},
[setSourceData, modifierKey, visibleExtensionDetail]
);
useEffect(() => {
window.addEventListener("keydown", handleKeyDown);
return () => {
window.removeEventListener("keydown", handleKeyDown);
};
}, [handleKeyDown]);
const { setSourceData, setVisibleExtensionStore } = useSearchStore();
useEffect(() => {
return () => {

View File

@@ -28,7 +28,6 @@ export function useKeyboardNavigation({
setShowIndex,
setSelectedName,
globalItemIndexMap,
handleItemAction,
isChatMode,
formatUrl,
searchData,
@@ -144,18 +143,6 @@ export function useKeyboardNavigation({
setShowIndex(true);
}
if (
modifierKeyPressed &&
e.key === "ArrowRight" &&
selectedIndex !== null
) {
e.preventDefault();
const item = globalItemIndexMap[selectedIndex];
handleItemAction(item);
}
if (e.key === "Enter" && !e.shiftKey && selectedIndex !== null) {
const item = globalItemIndexMap[selectedIndex];