(regions)
| 2721 | |
| 2722 | // 更新 YAML 中的 display.regions 和 display.region_order |
| 2723 | function updateDisplayRegionsInYaml(regions) { |
| 2724 | const editor = document.getElementById('yaml-editor'); |
| 2725 | let yaml = editor.value; |
| 2726 | const lines = yaml.split('\n'); |
| 2727 | |
| 2728 | let regionOrderStart = -1; |
| 2729 | let regionOrderEnd = -1; |
| 2730 | let regionsStart = -1; |
| 2731 | let regionsEnd = -1; |
| 2732 | let inDisplay = false; |
| 2733 | let regionOrderIndent = 0; |
| 2734 | let regionsIndent = 0; |
| 2735 | |
| 2736 | for (let i = 0; i < lines.length; i++) { |
| 2737 | const line = lines[i]; |
| 2738 | const trimmed = line.trim(); |
| 2739 | |
| 2740 | if (line.match(/^display:/)) { |
| 2741 | inDisplay = true; |
| 2742 | continue; |
| 2743 | } |
| 2744 | |
| 2745 | if (!inDisplay) continue; |
| 2746 | |
| 2747 | // 查找 region_order 数组 |
| 2748 | if (trimmed.startsWith('region_order:')) { |
| 2749 | regionOrderStart = i + 1; |
| 2750 | regionOrderIndent = line.search(/\S/) + 2; |
| 2751 | // 找到 region_order 的结束位置 |
| 2752 | for (let j = i + 1; j < lines.length; j++) { |
| 2753 | const nextLine = lines[j]; |
| 2754 | const nextTrimmed = nextLine.trim(); |
| 2755 | if (nextTrimmed && !nextTrimmed.startsWith('#') && !nextTrimmed.startsWith('-')) { |
| 2756 | const nextIndent = nextLine.search(/\S/); |
| 2757 | if (nextIndent < regionOrderIndent) { |
| 2758 | regionOrderEnd = j; |
| 2759 | break; |
| 2760 | } |
| 2761 | } |
| 2762 | } |
| 2763 | if (regionOrderEnd === -1) regionOrderEnd = lines.length; |
| 2764 | continue; |
| 2765 | } |
| 2766 | |
| 2767 | // 查找 regions 对象 |
| 2768 | if (trimmed.startsWith('regions:')) { |
| 2769 | regionsStart = i + 1; |
| 2770 | regionsIndent = line.search(/\S/) + 2; |
| 2771 | // 找到 regions 的结束位置(遇到同级或更高级的键) |
| 2772 | for (let j = i + 1; j < lines.length; j++) { |
| 2773 | const nextLine = lines[j]; |
| 2774 | const nextTrimmed = nextLine.trim(); |
| 2775 | if (nextTrimmed && !nextTrimmed.startsWith('#')) { |
| 2776 | const nextIndent = nextLine.search(/\S/); |
| 2777 | // 检查是否是同级或更高级的键(如 standalone:) |
| 2778 | if (nextIndent <= line.search(/\S/)) { |
| 2779 | regionsEnd = j; |
| 2780 | break; |
no test coverage detected