Update previousHotkeyScopeState to be a family state (#11270)

Fixes #11259
This commit is contained in:
Raphaël Bosi
2025-03-28 17:59:05 +01:00
committed by GitHub
parent 3e20134676
commit 352cf3d38e
8 changed files with 31 additions and 21 deletions

View File

@ -4,19 +4,19 @@ import { DEBUG_HOTKEY_SCOPE } from '@/ui/utilities/hotkey/hooks/useScopedHotkeyC
import { logDebug } from '~/utils/logDebug';
import { currentHotkeyScopeState } from '../states/internal/currentHotkeyScopeState';
import { previousHotkeyScopeState } from '../states/internal/previousHotkeyScopeState';
import { previousHotkeyScopeFamilyState } from '../states/internal/previousHotkeyScopeFamilyState';
import { CustomHotkeyScopes } from '../types/CustomHotkeyScope';
import { useSetHotkeyScope } from './useSetHotkeyScope';
export const usePreviousHotkeyScope = () => {
export const usePreviousHotkeyScope = (memoizeKey = 'global') => {
const setHotkeyScope = useSetHotkeyScope();
const goBackToPreviousHotkeyScope = useRecoilCallback(
({ snapshot, set }) =>
() => {
const previousHotkeyScope = snapshot
.getLoadable(previousHotkeyScopeState)
.getLoadable(previousHotkeyScopeFamilyState(memoizeKey))
.getValue();
if (!previousHotkeyScope) {
@ -32,9 +32,9 @@ export const usePreviousHotkeyScope = () => {
previousHotkeyScope.customScopes,
);
set(previousHotkeyScopeState, null);
set(previousHotkeyScopeFamilyState(memoizeKey), null);
},
[setHotkeyScope],
[setHotkeyScope, memoizeKey],
);
const setHotkeyScopeAndMemorizePreviousScope = useRecoilCallback(
@ -53,9 +53,10 @@ export const usePreviousHotkeyScope = () => {
}
setHotkeyScope(scope, customScopes);
set(previousHotkeyScopeState, currentHotkeyScope);
set(previousHotkeyScopeFamilyState(memoizeKey), currentHotkeyScope);
},
[setHotkeyScope],
[setHotkeyScope, memoizeKey],
);
return {

View File

@ -0,0 +1,11 @@
import { createFamilyState } from '@/ui/utilities/state/utils/createFamilyState';
import { HotkeyScope } from '../../types/HotkeyScope';
export const previousHotkeyScopeFamilyState = createFamilyState<
HotkeyScope | null,
string
>({
key: 'previousHotkeyScopeFamilyState',
defaultValue: null,
});

View File

@ -1,8 +0,0 @@
import { createState } from '@ui/utilities/state/utils/createState';
import { HotkeyScope } from '../../types/HotkeyScope';
export const previousHotkeyScopeState = createState<HotkeyScope | null>({
key: 'previousHotkeyScopeState',
defaultValue: null,
});