(presetName, field, value)
| 4681 | } |
| 4682 | |
| 4683 | function updateTimelineSectionField(presetName, field, value) { |
| 4684 | const editor = document.getElementById('timeline-editor'); |
| 4685 | const lines = editor.value.split('\n'); |
| 4686 | const section = resolveTimelineSection(lines, presetName); |
| 4687 | if (!section) return; |
| 4688 | |
| 4689 | const { sectionStart, sectionEnd, sectionIndent } = section; |
| 4690 | const fieldParts = field.split('.'); |
| 4691 | let lineIdx = -1; |
| 4692 | |
| 4693 | if (fieldParts.length === 1) { |
| 4694 | lineIdx = findChildKey(lines, sectionStart, sectionEnd, sectionIndent, fieldParts[0]); |
| 4695 | } else { |
| 4696 | const parentLine = findChildKey(lines, sectionStart, sectionEnd, sectionIndent, fieldParts[0]); |
| 4697 | if (parentLine >= 0) { |
| 4698 | const parentIndent = lines[parentLine].search(/\S/); |
| 4699 | const parentEnd = findBlockEnd(lines, parentLine, parentIndent, sectionEnd); |
| 4700 | lineIdx = findChildKey(lines, parentLine, parentEnd, parentIndent, fieldParts[1]); |
| 4701 | } |
| 4702 | } |
| 4703 | |
| 4704 | if (lineIdx < 0) { |
| 4705 | insertTimelineField(lines, sectionStart, sectionEnd, sectionIndent, field, value, fieldParts); |
| 4706 | } else { |
| 4707 | replaceLineValue(lines, lineIdx, value); |
| 4708 | } |
| 4709 | |
| 4710 | applyTimelineEditorChanges(editor, lines); |
| 4711 | } |
| 4712 | |
| 4713 | /** |
| 4714 | * 查找子级 key 行 |
no test coverage detected