Files
Netcatty/application/state/terminalLayoutSuppressStore.ts
T
陈大猫 ad3d0cfeda refactor: streamline codebase, unify duplicated modules, and consolidate test suite (#4307)
* refactor: streamline codebase, unify duplicated modules, and consolidate tests

* fix(test): batch discovered test files into Windows-safe command lines
2026-11-23 11:00:14 +08:00

33 lines
779 B
TypeScript

import { useSyncExternalStore } from 'react';
import { createListenerRegistry } from './createExternalStore';
let suppressDepth = 0;
const registry = createListenerRegistry();
export const terminalLayoutSuppressStore = {
getActive: () => suppressDepth > 0,
subscribe: registry.subscribe,
begin: () => {
suppressDepth += 1;
registry.scheduleNotify();
},
end: () => {
const wasActive = suppressDepth > 0;
suppressDepth = Math.max(0, suppressDepth - 1);
if (wasActive) {
registry.scheduleNotify();
}
},
};
export function useTerminalLayoutSuppressActive(): boolean {
return useSyncExternalStore(
terminalLayoutSuppressStore.subscribe,
terminalLayoutSuppressStore.getActive,
terminalLayoutSuppressStore.getActive,
);
}