A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: move through list using arrow keys
thecodrr6b1c0d76360a
diff --git a/apps/web/src/components/list-container/index.js b/apps/web/src/components/list-container/index.jsindex 68ba98261..07bfb1117 100644--- a/apps/web/src/components/list-container/index.js+++ b/apps/web/src/components/list-container/index.js@@ -18,6 +18,8 @@ function ListContainer(props) {const shouldSelectAll = useSelectionStore((store) => store.shouldSelectAll);const setSelectedItems = useSelectionStore((store) => store.setSelectedItems);const listRef = useRef();+ const focusedItemIndex = useRef(-1);+ const listContainerRef = useRef();useEffect(() => {if (shouldSelectAll && window.currentViewKey === type)@@ -35,13 +37,55 @@ function ListContainer(props) {</>) : (<>- <Flex variant="columnFill" data-test-id="note-list">+ <Flex+ ref={listContainerRef}+ variant="columnFill"+ data-test-id="note-list"+ onFocus={(e) => {+ if (e.target.parentElement.dataset.index) {+ focusedItemIndex.current = parseInt(+ e.target.parentElement.dataset.index+ );+ }+ }}+ ><Virtuosoref={listRef}data={items}computeItemKey={(index) => items[index].id || items[index].title}defaultItemHeight={profile.estimatedItemHeight}totalCount={items.length}+ onKeyDown={(e) => {+ const isUp = e.code === "ArrowUp";+ const isDown = e.code === "ArrowDown";+ const isHeader = (i) => items && items[i]?.type === "header";+ const moveDown = (i) => (i < items.length - 1 ? ++i : 0);+ const moveUp = (i) => (i > 0 ? --i : items.length - 1);++ let i = focusedItemIndex.current;+ let nextIndex = i;++ if (nextIndex <= -1 && (isUp || isDown)) {+ nextIndex = 0;+ }++ if (isUp) {+ nextIndex = moveUp(i);+ if (isHeader(nextIndex)) nextIndex = moveUp(nextIndex);+ } else if (isDown) {+ nextIndex = moveDown(i);+ if (isHeader(nextIndex)) nextIndex = moveDown(nextIndex);+ }++ if (isUp || isDown) {+ listRef.current.scrollToIndex(nextIndex);+ const listItem = listContainerRef.current.querySelector(+ `[data-item-index="${nextIndex}"]`+ );+ if (!listItem) return;+ listItem.firstElementChild.focus();+ }+ }}// overscan={10}components={{Scroller: CustomScrollbarsVirtualList,diff --git a/apps/web/src/components/list-item/index.js b/apps/web/src/components/list-item/index.jsindex abdbf17e8..a205499fa 100644--- a/apps/web/src/components/list-item/index.js+++ b/apps/web/src/components/list-item/index.js@@ -146,7 +146,7 @@ function ListItem(props) {return (<Flex- bg={isSelected || isContextMenuOpen ? "bgSecondary" : background}+ bg={isSelected ? "bgSecondary" : background}onContextMenu={(e) => {e.preventDefault();openMenu(menuItems, {@@ -156,7 +156,7 @@ function ListItem(props) {}}p={2}py={isCompact ? 1 : 2}- tabIndex={0}+ tabIndex={-1}sx={{height: "inherit",cursor: "pointer",@@ -168,12 +168,10 @@ function ListItem(props) {":hover": {backgroundColor: "hover",},- ":focus": {+ ":focus,:focus-visible": {outline: "none",- },- ":focus-visible": {- border: "1px solid",- borderColor: primary,+ borderTop: `1px solid var(--${primary})`,+ borderBottom: `1px solid var(--${primary})`,},overflow: "hidden",maxWidth: "100%",