From 6dcd07ce40f5c39b841446b92148de91d3be8cd8 Mon Sep 17 00:00:00 2001 From: oxdc <29519076+oxdc@users.noreply.github.com> Date: Mon, 30 Dec 2024 16:18:14 +0800 Subject: [PATCH] added tab index view cue --- src/components/Group.tsx | 6 ++++++ src/components/NavigationContainer.tsx | 15 +++++++++++++-- src/components/NavigationContent.tsx | 19 +++++++++++++++---- src/components/NavigationTreeItem.tsx | 12 ++++++++++++ src/components/Tab.tsx | 6 +++++- src/styles.scss | 1 + src/styles/TabIndexViewCue.scss | 21 +++++++++++++++++++++ 7 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 src/styles/TabIndexViewCue.scss diff --git a/src/components/Group.tsx b/src/components/Group.tsx index 7b432cb..72121b8 100644 --- a/src/components/Group.tsx +++ b/src/components/Group.tsx @@ -99,12 +99,18 @@ export const Group = ({ type, children, group }: GroupProps) => { onBlur={handleTitleChange} /> ); + + const lastActiveLeaf = useViewState((state) => state.latestActiveLeaf); + const isActiveGroup = group?.id === lastActiveLeaf?.parent.id; + const props = { icon: "right-triangle", isCollapsed: isCollapsed && !isSingleGroup, // Single group should not be collapsed isSidebar, isSingleGroup, + isActiveGroup, }; + const toolbar = ( {!isSidebar && !isEditing && ( diff --git a/src/components/NavigationContainer.tsx b/src/components/NavigationContainer.tsx index 957ea46..e67ae27 100644 --- a/src/components/NavigationContainer.tsx +++ b/src/components/NavigationContainer.tsx @@ -27,6 +27,7 @@ import { iterateRootOrFloatingLeaves } from "src/services/GetTabs"; export const NavigationContainer = () => { const plugin = usePlugin(); const app = plugin.app; + const ref = useRef(null); const { refresh, sort } = useTabCache(); const { setLatestActiveLeaf, @@ -122,6 +123,18 @@ export const NavigationContainer = () => { } }) ); + plugin.registerDomEvent(window, "keydown", (event) => { + if (event.ctrlKey || event.metaKey) { + if (ref.current) { + ref.current.toggleClass("tab-index-view-cue", true); + } + } + }); + plugin.registerDomEvent(window, "keyup", () => { + if (ref.current) { + ref.current.toggleClass("tab-index-view-cue", false); + } + }); plugin.addCommand({ id: "toggle-zen-mode", name: "Toggle zen mode", @@ -171,8 +184,6 @@ export const NavigationContainer = () => { if (event.button === 1) event.preventDefault(); }; - const ref = useRef(null); - return (
{ const isOverTab = (over.data.current as any).isTab; if (isActiveTab) { - let movedTab : WorkspaceLeaf | null = null; + let movedTab: WorkspaceLeaf | null = null; if (isOverTab) { movedTab = moveTab(app, activeID, overID); } else { @@ -122,9 +122,20 @@ export const NavigationContent = () => { group={entryOf(groupID).group} > - {entryOf(groupID).leaves.map((leaf) => ( - - ))} + {entryOf(groupID).leaves.map( + (leaf, index, array) => { + const isLast = + index === array.length - 1; + return ( + + ); + } + )} diff --git a/src/components/NavigationTreeItem.tsx b/src/components/NavigationTreeItem.tsx index c354b1d..1592a00 100644 --- a/src/components/NavigationTreeItem.tsx +++ b/src/components/NavigationTreeItem.tsx @@ -7,6 +7,7 @@ import { Identifier } from "src/models/VTWorkspace"; interface NavigationTreeItemProps { id: Identifier | null; + index?: number; ref?: React.RefObject; title: string | React.ReactNode; icon: string; @@ -16,11 +17,13 @@ interface NavigationTreeItemProps { isGroupSlot?: boolean; isSingleGroup?: boolean; isActive?: boolean; + isActiveGroup?: boolean; isRenaming?: boolean; isPinned?: boolean; isCollapsed?: boolean; isSidebar?: boolean; isHighlighted?: boolean; + isLast?: boolean; children?: React.ReactNode; toolbar?: React.ReactNode; onClick?: (event?: React.MouseEvent) => void; @@ -38,6 +41,13 @@ interface NavigationTreeItemProps { dataId?: string; } +function mapIndex(index?: number, isLast?: boolean): number | undefined { + if (index === undefined) return undefined; + const userIndex = index + 1; + if (0 <= userIndex && userIndex <= 8) return userIndex; + if (isLast) return 9; +} + export const NavigationTreeItem = (props: NavigationTreeItemProps) => { const { attributes, listeners, setNodeRef, isDragging, isOver } = useSortable({ @@ -63,6 +73,7 @@ export const NavigationTreeItem = (props: NavigationTreeItemProps) => { "is-tab-slot": props.isTabSlot, "is-group-slot": props.isGroupSlot, "is-single-group": props.isSingleGroup, + "is-active-group": props.isActiveGroup, "is-slot": props.isTabSlot || props.isGroupSlot, "is-highlighted": props.isHighlighted, }; @@ -144,6 +155,7 @@ export const NavigationTreeItem = (props: NavigationTreeItemProps) => { onAuxClick={props.onAuxClick} onDoubleClick={props.onDoubleClick} onContextMenu={props.onContextMenu} + data-index={mapIndex(props.index, props.isLast)} ref={props.id ? setNodeRef : null} {...attributes} {...listeners} diff --git a/src/components/Tab.tsx b/src/components/Tab.tsx index f45bd11..700955c 100644 --- a/src/components/Tab.tsx +++ b/src/components/Tab.tsx @@ -27,9 +27,11 @@ import { HistoryBrowserModal } from "src/HistoryBrowserModal"; interface TabProps { leaf: WorkspaceLeaf; + index: number; + isLast: boolean; } -export const Tab = ({ leaf }: TabProps) => { +export const Tab = ({ leaf, index, isLast }: TabProps) => { const plugin = usePlugin(); const app = plugin.app; const workspace = app.workspace; @@ -442,6 +444,8 @@ export const Tab = ({ leaf }: TabProps) => {