diff --git a/apps/desktop/layer/renderer/src/lib/features.tsx b/apps/desktop/layer/renderer/src/lib/features.tsx index 7de933ade..f218f0a41 100644 --- a/apps/desktop/layer/renderer/src/lib/features.tsx +++ b/apps/desktop/layer/renderer/src/lib/features.tsx @@ -3,10 +3,9 @@ import type { FC } from "react" import { useFeature } from "~/hooks/biz/useFeature" -export const featureConfigMap: Record> = - { - ai: "AI_CHAT_ENABLED", - } +export const featureConfigMap = { + ai: "AI_CHAT_ENABLED", +} satisfies Record> export const withFeature = (feature: keyof typeof featureConfigMap) => diff --git a/apps/desktop/layer/renderer/src/modules/entry-content/components/entry-content/EntryContent.ai.tsx b/apps/desktop/layer/renderer/src/modules/entry-content/components/entry-content/EntryContent.ai.tsx index 3ef0075f1..24501c7f6 100644 --- a/apps/desktop/layer/renderer/src/modules/entry-content/components/entry-content/EntryContent.ai.tsx +++ b/apps/desktop/layer/renderer/src/modules/entry-content/components/entry-content/EntryContent.ai.tsx @@ -97,9 +97,11 @@ const EntryContentImpl: Component = ({ }, [addOrUpdateBlock, entryId, removeBlock]) const animationController = useAnimationControls() + const focusableRef = useRef(null) useEffect(() => { animationController.set(contentVariants.exit) animationController.start(contentVariants.animate) + focusableRef.current?.focus() return () => { animationController.stop() } @@ -116,6 +118,7 @@ const EntryContentImpl: Component = ({
diff --git a/apps/desktop/layer/renderer/src/modules/entry-content/components/entry-content/EntryScrollingAndNavigationHandler.tsx b/apps/desktop/layer/renderer/src/modules/entry-content/components/entry-content/EntryScrollingAndNavigationHandler.tsx index 2cbfd8794..5ee76327b 100644 --- a/apps/desktop/layer/renderer/src/modules/entry-content/components/entry-content/EntryScrollingAndNavigationHandler.tsx +++ b/apps/desktop/layer/renderer/src/modules/entry-content/components/entry-content/EntryScrollingAndNavigationHandler.tsx @@ -11,9 +11,13 @@ import type { JSAnimation } from "motion/react" import { AnimatePresence, m } from "motion/react" import * as React from "react" import { useEffect, useRef, useState } from "react" +import { useHotkeys } from "react-hotkeys-hook" import { useEventCallback } from "usehooks-ts" +import { useIsZenMode } from "~/atoms/settings/ui" import { FocusablePresets } from "~/components/common/Focusable" +import { useFeature } from "~/hooks/biz/useFeature" +import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry" import { COMMAND_ID } from "~/modules/command/commands/id" import { useCommandBinding } from "~/modules/command/hooks/use-command-binding" import { useCommandHotkey } from "~/modules/command/hooks/use-register-hotkey" @@ -50,12 +54,27 @@ export const EntryScrollingAndNavigationHandler = ({ when, }) + const isZenMode = useIsZenMode() + // TODO: Here, do not rely on the AI switch, but should be deps on the new layout. + const isAiEnabled = useFeature("ai") + + const useBackHandler = isZenMode || isAiEnabled + useCommandHotkey({ commandId: COMMAND_ID.layout.focusToTimeline, - when, + when: when && !useBackHandler, shortcut: "Backspace, Escape", }) + const navigateToTimeline = useNavigateEntry() + useHotkeys( + "Escape", + () => { + navigateToTimeline({ entryId: null }) + }, + { enabled: when && useBackHandler }, + ) + const { highlightBoundary } = useFocusActions() const smoothScrollTo = useSmoothScroll() const navigateToNext = useEventCallback(() => {