{
e.preventDefault();
}}
@@ -421,36 +627,63 @@ const selectedModule = selectedModuleIndex !== null && currentModules.length > s
const moduleType = e.dataTransfer.getData("moduleType");
if (moduleType) {
// 添加新模块
- const currentTheme = statusLineConfig.currentStyle as keyof StatusLineConfig;
+ const currentTheme =
+ statusLineConfig.currentStyle as keyof StatusLineConfig;
const themeConfig = statusLineConfig[currentTheme];
- const modules = themeConfig && typeof themeConfig === 'object' && 'modules' in themeConfig
- ? [...((themeConfig as StatusLineThemeConfig).modules || [])]
- : [];
-
+ const modules =
+ themeConfig &&
+ typeof themeConfig === "object" &&
+ "modules" in themeConfig
+ ? [
+ ...((themeConfig as StatusLineThemeConfig)
+ .modules || []),
+ ]
+ : [];
+
// 根据模块类型设置默认值
let newModule: StatusLineModuleConfig;
switch (moduleType) {
case "workDir":
- newModule = { type: "workDir", icon: "", text: "{{workDirName}}", color: "bright_blue" };
+ newModule = {
+ type: "workDir",
+ icon: "",
+ text: "{{workDirName}}",
+ color: "bright_blue",
+ };
break;
case "gitBranch":
- newModule = { type: "gitBranch", icon: "🌿", text: "{{gitBranch}}", color: "bright_green" };
+ newModule = {
+ type: "gitBranch",
+ icon: "🌿",
+ text: "{{gitBranch}}",
+ color: "bright_green",
+ };
break;
case "model":
- newModule = { type: "model", icon: "🤖", text: "{{model}}", color: "bright_yellow" };
+ newModule = {
+ type: "model",
+ icon: "🤖",
+ text: "{{model}}",
+ color: "bright_yellow",
+ };
break;
case "usage":
- newModule = { type: "usage", icon: "📊", text: "{{inputTokens}} → {{outputTokens}}", color: "bright_magenta" };
+ newModule = {
+ type: "usage",
+ icon: "📊",
+ text: "{{inputTokens}} → {{outputTokens}}",
+ color: "bright_magenta",
+ };
break;
default:
newModule = { ...DEFAULT_MODULE, type: moduleType };
}
-
+
modules.push(newModule);
-
- setStatusLineConfig(prev => ({
+
+ setStatusLineConfig((prev) => ({
...prev,
- [currentTheme]: { modules }
+ [currentTheme]: { modules },
}));
}
}}
@@ -461,8 +694,14 @@ const selectedModule = selectedModuleIndex !== null && currentModules.length > s
setSelectedModuleIndex(index)}
draggable
onDragStart={(e) => {
@@ -473,24 +712,41 @@ const selectedModule = selectedModuleIndex !== null && currentModules.length > s
}}
onDrop={(e) => {
e.preventDefault();
- const dragIndex = parseInt(e.dataTransfer.getData("dragIndex"));
+ const dragIndex = parseInt(
+ e.dataTransfer.getData("dragIndex")
+ );
if (!isNaN(dragIndex) && dragIndex !== index) {
// 重新排序模块
- const currentTheme = statusLineConfig.currentStyle as keyof StatusLineConfig;
+ const currentTheme =
+ statusLineConfig.currentStyle as keyof StatusLineConfig;
const themeConfig = statusLineConfig[currentTheme];
- const modules = themeConfig && typeof themeConfig === 'object' && 'modules' in themeConfig
- ? [...((themeConfig as StatusLineThemeConfig).modules || [])]
- : [];
-
- if (dragIndex >= 0 && dragIndex < modules.length && index >= 0 && index <= modules.length) {
- const [movedModule] = modules.splice(dragIndex, 1);
+ const modules =
+ themeConfig &&
+ typeof themeConfig === "object" &&
+ "modules" in themeConfig
+ ? [
+ ...((themeConfig as StatusLineThemeConfig)
+ .modules || []),
+ ]
+ : [];
+
+ if (
+ dragIndex >= 0 &&
+ dragIndex < modules.length &&
+ index >= 0 &&
+ index <= modules.length
+ ) {
+ const [movedModule] = modules.splice(
+ dragIndex,
+ 1
+ );
modules.splice(index, 0, movedModule);
-
- setStatusLineConfig(prev => ({
+
+ setStatusLineConfig((prev) => ({
...prev,
- [currentTheme]: { modules }
+ [currentTheme]: { modules },
}));
-
+
// 更新选中项的索引
if (selectedModuleIndex === dragIndex) {
setSelectedModuleIndex(index);
@@ -501,16 +757,30 @@ const selectedModule = selectedModuleIndex !== null && currentModules.length > s
}
}}
>
- {renderModulePreview(module, statusLineConfig.currentStyle === 'powerline')}
+ {renderModulePreview(
+ module,
+ statusLineConfig.currentStyle === "powerline"
+ )}
))}