Files
paseo/packages/app/src/composer/keyboard-scope.tsx
T
Mohamed Boudra 6017706cc1 fix(app): avoid restoring composer focus on touch navigation (#7130)
Limit implicit pane and remount focus replay to the existing fine-pointer policy. Fullscreen keeps one editor mounted, so touch navigation does not need the restoration introduced for the former portal handoff.
2026-10-16 17:27:06 +07:00

47 lines
1.3 KiB
TypeScript

import {
createContext,
useContext,
useMemo,
type PropsWithChildren,
type ReactElement,
} from "react";
interface ComposerKeyboardScopeValue {
/**
* The pane this composer sits in is the user's pane. Mouse-driven focus
* restoration follows it; touch navigation does not restore editor focus.
*/
isPaneFocused: boolean;
/**
* The composer takes input right now: keyboard actions, shortcuts, autocomplete,
* and the fullscreen exit action. False while a compact overlay panel covers the
* pane, which does not take pane focus.
*/
isActiveComposer: boolean;
}
const ComposerKeyboardScopeContext = createContext<ComposerKeyboardScopeValue>({
isPaneFocused: false,
isActiveComposer: false,
});
export function ComposerKeyboardScopeProvider({
isPaneFocused,
isActiveComposer,
children,
}: PropsWithChildren<ComposerKeyboardScopeValue>): ReactElement {
const value = useMemo(
() => ({ isPaneFocused, isActiveComposer }),
[isPaneFocused, isActiveComposer],
);
return (
<ComposerKeyboardScopeContext.Provider value={value}>
{children}
</ComposerKeyboardScopeContext.Provider>
);
}
export function useComposerKeyboardScope(): ComposerKeyboardScopeValue {
return useContext(ComposerKeyboardScopeContext);
}