MCPcopy
hub / github.com/sansan0/TrendRadar / updateTimelineSectionField

Function updateTimelineSectionField

docs/assets/script.js:4683–4711  ·  view source on GitHub ↗
(presetName, field, value)

Source from the content-addressed store, hash-verified

4681}
4682
4683function 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 行

Callers 1

script.jsFile · 0.85

Calls 6

resolveTimelineSectionFunction · 0.85
findChildKeyFunction · 0.85
findBlockEndFunction · 0.85
insertTimelineFieldFunction · 0.85
replaceLineValueFunction · 0.85

Tested by

no test coverage detected