mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 06:15:51 +00:00
* style(B1-1): 格式化 ink/buddy/cli/context/screens/tasks/services/keybindings/state (43 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 修复了 Box.tsx 和 ScrollBox.tsx 中无效的 global.d.ts import。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-2): 格式化 commands (79 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-3): 格式化 components/messages,permissions,mcp,sandbox,shell (104 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-4): 格式化 components/PromptInput,FeedbackSurvey,tasks,agents,skills,design-system,wizard (73 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-5): 格式化 components其余 + hooks + tools (232 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-6): 格式化 main/entrypoints/utils/moreright (21 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: 更新 README,新增 Run.ps1/TODO.md,删除 V6.md - README.md: 大幅重写,更详细版本历史和配置示例 - Run.ps1: 新增 Windows 启动脚本 - TODO.md: 新增包完成清单 - V6.md: 删除(架构重构规划已不适用) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: 修复以前的问题 * fix: 修复 login 面板的问题 --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
110 lines
4.1 KiB
TypeScript
110 lines
4.1 KiB
TypeScript
/**
|
|
* Overlay tracking for Escape key coordination.
|
|
*
|
|
* This solves the problem of escape key handling when overlays (like Select with onCancel)
|
|
* are open. The CancelRequestHandler needs to know when an overlay is active so it doesn't
|
|
* cancel requests when the user just wants to dismiss the overlay.
|
|
*
|
|
* Usage:
|
|
* 1. Call useRegisterOverlay() in any overlay component to automatically register it
|
|
* 2. Call useIsOverlayActive() to check if any overlay is currently active
|
|
*
|
|
* The hook automatically registers on mount and unregisters on unmount,
|
|
* so no manual cleanup or state management is needed.
|
|
*/
|
|
import { useContext, useEffect, useLayoutEffect } from 'react'
|
|
import instances from '../ink/instances.js'
|
|
import { AppStoreContext, useAppState } from '../state/AppState.js'
|
|
|
|
// Non-modal overlays that shouldn't disable TextInput focus
|
|
const NON_MODAL_OVERLAYS = new Set(['autocomplete'])
|
|
|
|
/**
|
|
* Hook to register a component as an active overlay.
|
|
* Automatically registers on mount and unregisters on unmount.
|
|
*
|
|
* @param id - Unique identifier for this overlay (e.g., 'select', 'multi-select')
|
|
* @param enabled - Whether to register (default: true). Use this to conditionally register
|
|
* based on component props, e.g., only register when onCancel is provided.
|
|
*
|
|
* @example
|
|
* // Conditional registration based on whether cancel is supported
|
|
* function useSelectInput({ state }) {
|
|
* useRegisterOverlay('select', !!state.onCancel)
|
|
* // ...
|
|
* }
|
|
*/
|
|
export function useRegisterOverlay(id: string, enabled = true): void {
|
|
// Use context directly so this is a no-op when rendered outside AppStateProvider
|
|
// (e.g., in isolated component tests that don't need the full app state tree).
|
|
const store = useContext(AppStoreContext)
|
|
const setAppState = store?.setState
|
|
useEffect(() => {
|
|
if (!enabled || !setAppState) return
|
|
setAppState(prev => {
|
|
if (prev.activeOverlays.has(id)) return prev
|
|
const next = new Set(prev.activeOverlays)
|
|
next.add(id)
|
|
return { ...prev, activeOverlays: next }
|
|
})
|
|
return () => {
|
|
setAppState(prev => {
|
|
if (!prev.activeOverlays.has(id)) return prev
|
|
const next = new Set(prev.activeOverlays)
|
|
next.delete(id)
|
|
return { ...prev, activeOverlays: next }
|
|
})
|
|
}
|
|
}, [id, enabled, setAppState])
|
|
|
|
// On overlay close, force the next render to full-damage diff instead
|
|
// of blit. A tall overlay (e.g. FuzzyPicker with a 20-line preview)
|
|
// shrinks the Ink-managed region on unmount; the blit fast path can
|
|
// copy stale cells from the overlay's previous frame into rows the
|
|
// shorter layout no longer reaches, leaving a ghost title/divider.
|
|
// useLayoutEffect so cleanup runs synchronously before the microtask-
|
|
// deferred onRender (scheduleRender queues a microtask from
|
|
// resetAfterCommit; passive-effect cleanup would land after it).
|
|
useLayoutEffect(() => {
|
|
if (!enabled) return
|
|
return () => instances.get(process.stdout)?.invalidatePrevFrame()
|
|
}, [enabled])
|
|
}
|
|
|
|
/**
|
|
* Hook to check if any overlay is currently active.
|
|
* This is reactive - the component will re-render when the overlay state changes.
|
|
*
|
|
* @returns true if any overlay is currently active
|
|
*
|
|
* @example
|
|
* function CancelRequestHandler() {
|
|
* const isOverlayActive = useIsOverlayActive()
|
|
* const isActive = !isOverlayActive && canCancelRunningTask
|
|
* useKeybinding('chat:cancel', handleCancel, { isActive })
|
|
* }
|
|
*/
|
|
export function useIsOverlayActive(): boolean {
|
|
return useAppState(s => s.activeOverlays.size > 0)
|
|
}
|
|
|
|
/**
|
|
* Hook to check if any modal overlay is currently active.
|
|
* Modal overlays are overlays that should capture all input (like Select dialogs).
|
|
* Non-modal overlays (like autocomplete) don't disable TextInput focus.
|
|
*
|
|
* @returns true if any modal overlay is currently active
|
|
*
|
|
* @example
|
|
* // Use for TextInput focus - allows typing during autocomplete
|
|
* focus: !isSearchingHistory && !isModalOverlayActive
|
|
*/
|
|
export function useIsModalOverlayActive(): boolean {
|
|
return useAppState(s => {
|
|
for (const id of s.activeOverlays) {
|
|
if (!NON_MODAL_OVERLAYS.has(id)) return true
|
|
}
|
|
return false
|
|
})
|
|
}
|