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

Function removeTimelineField

docs/assets/script.js:4636–4681  ·  view source on GitHub ↗
(presetName, periodKey, field)

Source from the content-addressed store, hash-verified

4634}
4635
4636function removeTimelineField(presetName, periodKey, field) {
4637 const editor = document.getElementById('timeline-editor');
4638 const lines = editor.value.split('\n');
4639 const target = resolveTimelineTarget(lines, presetName, periodKey);
4640 if (!target) return;
4641
4642 const { targetStart, targetEnd, targetIndent } = target;
4643 const fieldParts = field.split('.');
4644
4645 if (fieldParts.length === 1) {
4646 const lineIdx = findChildKey(lines, targetStart, targetEnd, targetIndent, fieldParts[0]);
4647 if (lineIdx < 0) return;
4648 const lineIndent = lines[lineIdx].search(/\S/);
4649 const lineEnd = findBlockEnd(lines, lineIdx, lineIndent, targetEnd);
4650 lines.splice(lineIdx, lineEnd - lineIdx);
4651 applyTimelineEditorChanges(editor, lines);
4652 return;
4653 }
4654
4655 const parentLine = findChildKey(lines, targetStart, targetEnd, targetIndent, fieldParts[0]);
4656 if (parentLine < 0) return;
4657 const parentIndent = lines[parentLine].search(/\S/);
4658 const parentEnd = findBlockEnd(lines, parentLine, parentIndent, targetEnd);
4659 const childLine = findChildKey(lines, parentLine, parentEnd, parentIndent, fieldParts[1]);
4660 if (childLine < 0) return;
4661
4662 const childIndent = lines[childLine].search(/\S/);
4663 const childEnd = findBlockEnd(lines, childLine, childIndent, parentEnd);
4664 lines.splice(childLine, childEnd - childLine);
4665
4666 const parentEndAfter = findBlockEnd(lines, parentLine, parentIndent, targetEnd);
4667 let hasChild = false;
4668 for (let i = parentLine + 1; i < parentEndAfter; i++) {
4669 const line = lines[i];
4670 if (line.trim() === '' || line.trim().startsWith('#')) continue;
4671 if (line.search(/\S/) > parentIndent) {
4672 hasChild = true;
4673 break;
4674 }
4675 }
4676 if (!hasChild) {
4677 lines.splice(parentLine, 1);
4678 }
4679
4680 applyTimelineEditorChanges(editor, lines);
4681}
4682
4683function updateTimelineSectionField(presetName, field, value) {
4684 const editor = document.getElementById('timeline-editor');

Callers 1

script.jsFile · 0.85

Calls 4

resolveTimelineTargetFunction · 0.85
findChildKeyFunction · 0.85
findBlockEndFunction · 0.85

Tested by

no test coverage detected