(platforms)
| 2500 | |
| 2501 | // 更新 YAML 中的平台配置(保留注释) |
| 2502 | function updatePlatformsInYaml(platforms) { |
| 2503 | const editor = document.getElementById('yaml-editor'); |
| 2504 | let yaml = editor.value; |
| 2505 | const lines = yaml.split('\n'); |
| 2506 | |
| 2507 | // 找到 platforms.sources 的位置 |
| 2508 | let sourcesStart = -1; |
| 2509 | let sourcesEnd = -1; |
| 2510 | let inPlatforms = false; |
| 2511 | let inSources = false; |
| 2512 | let baseIndent = 0; |
| 2513 | let lastDataLineIndex = -1; // 记录最后一个数据行的位置 |
| 2514 | |
| 2515 | for (let i = 0; i < lines.length; i++) { |
| 2516 | const line = lines[i]; |
| 2517 | const trimmed = line.trim(); |
| 2518 | |
| 2519 | if (line.match(/^platforms:/)) { |
| 2520 | inPlatforms = true; |
| 2521 | continue; |
| 2522 | } |
| 2523 | |
| 2524 | if (inPlatforms && !inSources && trimmed.startsWith('sources:')) { |
| 2525 | sourcesStart = i + 1; |
| 2526 | inSources = true; |
| 2527 | baseIndent = line.search(/\S/) + 2; // sources 下一级的缩进 |
| 2528 | continue; |
| 2529 | } |
| 2530 | |
| 2531 | if (inSources) { |
| 2532 | const currentIndent = line.search(/\S/); |
| 2533 | |
| 2534 | // 如果是数据行(以 - 开头或是数据项的属性) |
| 2535 | if (trimmed.startsWith('-')) { |
| 2536 | lastDataLineIndex = i; |
| 2537 | } else if (trimmed && !trimmed.startsWith('#') && currentIndent >= baseIndent) { |
| 2538 | // 数据项的属性行(如 name:, id:) |
| 2539 | lastDataLineIndex = i; |
| 2540 | } else if (trimmed && !trimmed.startsWith('#') && currentIndent < baseIndent) { |
| 2541 | // 遇到缩进更小的非注释行,说明离开了 sources 区域 |
| 2542 | sourcesEnd = lastDataLineIndex + 1; |
| 2543 | break; |
| 2544 | } |
| 2545 | } |
| 2546 | |
| 2547 | // 检查是否进入下一个顶级模块 |
| 2548 | if (inPlatforms && line.match(/^[a-z_]+:/) && !line.match(/^platforms:/)) { |
| 2549 | if (lastDataLineIndex >= 0) { |
| 2550 | sourcesEnd = lastDataLineIndex + 1; |
| 2551 | } else { |
| 2552 | sourcesEnd = i; |
| 2553 | } |
| 2554 | break; |
| 2555 | } |
| 2556 | } |
| 2557 | |
| 2558 | // 如果没有找到结束位置,使用最后一个数据行的下一行 |
| 2559 | if (sourcesEnd === -1) { |
no test coverage detected