Skip to content

Commit e1c933b

Browse files
committed
feat:修改create操作行为,如果文件已有,则插入末尾
1 parent 5ae7633 commit e1c933b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/cvbManager.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ TCVB 格式规范:
492492
2. **创建操作(CREATE)**:
493493
- 创建一个新文件,后面直接给全文代码。
494494
- 新文件的全部内容应完整写入代码块中。
495-
- 如果文件已经存在,应该有GLOBAL-REPLACE来插入,而不是用CREATE
495+
- 如果文件已经存在,应该有GLOBAL-REPLACE来插入,而不是用CREATE。如果是已有的文件,会直接把内容插入末尾。
496496
497497
示例:
498498
## OPERATION:CREATE
@@ -637,12 +637,11 @@ export function mergeCvb(baseCvb: Cvb, tcvb: TCVB): Cvb {
637637
strContent = applyGlobalReplace(strContent, op);
638638
} else if (op instanceof CreateOperation) {
639639
if (mapMergedFiles.has(strFilePath)) {
640-
throw new Error(
641-
`${strFilePath} 已经存在,不可以使用 ## OPERATION:CREATE`
642-
);
640+
strContent = applyInsertTail(strContent, op);
641+
}
642+
else {
643+
strContent = op.m_strContent;
643644
}
644-
// CREATE 操作:直接以新内容覆盖原有内容
645-
strContent = op.m_strContent;
646645
}
647646
}
648647
mapMergedFiles.set(strFilePath, strContent);
@@ -840,6 +839,13 @@ export function applyGlobalReplace(
840839
}
841840
}
842841

842+
export function applyInsertTail(
843+
strContent: string,
844+
op: CreateOperation){
845+
strContent += "\n" + op.m_strContent;
846+
return strContent;
847+
}
848+
843849
// 根据前锚点、内容、后锚点构建正则表达式(dotall 模式)
844850
function buildPattern(
845851
strBefore: string,

0 commit comments

Comments
 (0)