fix(link): Navigate between item and fix Enter keybind (#165)

* feat: add item scroll to active

* fix: reset enterkey and scroll to view

* fix: link item displayName
This commit is contained in:
Aslam
2024-09-19 21:11:52 +07:00
committed by GitHub
parent 8871a8959c
commit afaef5d3c5
5 changed files with 167 additions and 129 deletions

View File

@@ -24,6 +24,7 @@ import { commandPaletteOpenAtom } from "@/components/custom/command-palette/comm
import { useConfirm } from "@omit/react-confirm-dialog"
import { useLinkActions } from "./hooks/use-link-actions"
import { isDeleteConfirmShownAtom } from "./LinkRoute"
import { useActiveItemScroll } from "@/hooks/use-active-item-scroll"
interface LinkListProps {
activeItemIndex: number | null
@@ -77,12 +78,6 @@ const LinkList: React.FC<LinkListProps> = ({ activeItemIndex, setActiveItemIndex
})
)
useKey("Escape", () => {
if (editId) {
setEditId(null)
}
})
useKey(
event => (event.metaKey || event.ctrlKey) && event.key === "Backspace",
async () => {
@@ -245,6 +240,8 @@ const LinkList: React.FC<LinkListProps> = ({ activeItemIndex, setActiveItemIndex
setDraggingId(null)
}
const setElementRef = useActiveItemScroll<HTMLLIElement>({ activeIndex: activeItemIndex })
return (
<Primitive.div
className="mb-11 flex w-full flex-1 flex-col overflow-y-auto outline-none [scrollbar-gutter:stable]"
@@ -271,6 +268,7 @@ const LinkList: React.FC<LinkListProps> = ({ activeItemIndex, setActiveItemIndex
isActive={activeItemIndex === index}
setActiveItemIndex={setActiveItemIndex}
index={index}
ref={el => setElementRef(el, index)}
/>
)
)}