Skip to content

Commit b757ea1

Browse files
committed
refactor(ui): 移动并复用 isSkillSelected 函数
- 将 isSkillSelected 函数从 PromptInput.tsx 移动到 SlashCommandMenu.tsx - 在 PromptInput.tsx 中从 SlashCommandMenu 导入 isSkillSelected - 简化代码结构,避免函数重复定义 - 统一技能选择判断逻辑以提高代码复用性
1 parent 3111e10 commit b757ea1

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

src/ui/PromptInput.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export type { InputKey } from "./prompt";
4848
import { useTerminalInput } from "./prompt";
4949
import type { InputKey } from "./prompt";
5050
import { useHiddenTerminalCursor, useTerminalExtendedKeys, useTerminalFocusReporting } from "./prompt";
51-
import SlashCommandMenu from "./SlashCommandMenu";
51+
import SlashCommandMenu, { isSkillSelected } from "./SlashCommandMenu";
5252
import type { ModelConfigSelection } from "../settings";
5353
import { FileMentionMenu, ModelsDropdown, RawModelDropdown, SkillsDropdown } from "./components";
5454

@@ -818,10 +818,6 @@ export function formatSelectedSkillsStatus(skills: SkillInfo[]): string {
818818
return `⚡ ${names.join(", ")}`;
819819
}
820820

821-
export function isSkillSelected(skills: SkillInfo[], skill: SkillInfo): boolean {
822-
return skills.some((item) => item.name === skill.name);
823-
}
824-
825821
export function addUniqueSkill(skills: SkillInfo[], skill: SkillInfo): SkillInfo[] {
826822
if (isSkillSelected(skills, skill)) {
827823
return skills;

src/ui/SlashCommandMenu.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import type { SlashCommandItem } from "./slashCommands";
33
import { ARGS_SEPARATOR } from "./constants";
44
import React from "react";
55
import { Box, Text } from "ink";
6+
import type { SkillInfo } from "../session";
67

78
type SlashCommandMenuProps = {
89
items: SlashCommandItem[];
910
activeIndex: number;
1011
width: number;
1112
maxVisible?: number;
1213
};
13-
14+
export function isSkillSelected(skills: SkillInfo[], skill: SkillInfo): boolean {
15+
return skills.some((item) => item.name === skill.name);
16+
}
1417
const SlashCommandMenu = React.memo(function SlashCommandMenu({
1518
items,
1619
activeIndex,

0 commit comments

Comments
 (0)