mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 06:15:51 +00:00
fix: Battle 快捷键通过 inputRef 转发至主 Ink 上下文
BattleFlow 不再直接调用 useInput(外部包的 Ink 上下文可能不同), 改为暴露 handleInput 方法,由 BuddyPanel 中的 BattleTab 通过 useInput + ref 转发键盘事件,确保在正确的 StdinContext 中工作。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import * as React from 'react';
|
||||
import { useState } from 'react';
|
||||
import { useState, useRef } from 'react';
|
||||
import { Box, Text, Pane, Tab, Tabs, useInput, type Color } from '@anthropic/ink';
|
||||
import { useSetAppState } from '../../state/AppState.js';
|
||||
import { useKeybinding } from '../../keybindings/useKeybinding.js';
|
||||
@@ -22,6 +22,7 @@ import { getXpProgress } from '@claude-code-best/pokemon';
|
||||
import { getGenderSymbol } from '@claude-code-best/pokemon';
|
||||
import { StatBar, SpriteAnimator, getFallbackSprite, loadSprite } from '@claude-code-best/pokemon';
|
||||
import { BattleFlow, loadBuddyData } from '@claude-code-best/pokemon';
|
||||
import type { BattleFlowHandle } from '@claude-code-best/pokemon';
|
||||
import type { LocalJSXCommandOnDone } from '../../types/command.js';
|
||||
|
||||
const CYAN: Color = 'ansi:cyan';
|
||||
@@ -633,6 +634,13 @@ function BattleTab({
|
||||
onUpdate: (data: BuddyData) => void;
|
||||
}) {
|
||||
const [battleKey, setBattleKey] = useState(0);
|
||||
const inputRef = useRef<BattleFlowHandle | null>(null);
|
||||
|
||||
// Handle input here (in main app's Ink context) and forward to BattleFlow via ref
|
||||
useInput((input, key) => {
|
||||
if (!isActive) return;
|
||||
inputRef.current?.handleInput(input, key);
|
||||
});
|
||||
|
||||
const handleClose = async () => {
|
||||
const updated = await loadBuddyData();
|
||||
@@ -646,6 +654,7 @@ function BattleTab({
|
||||
buddyData={buddyData}
|
||||
onClose={handleClose}
|
||||
isActive={isActive}
|
||||
inputRef={inputRef}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user