removeSection method

Future<MemoryFile?> removeSection(
  1. String path,
  2. String heading
)

Remove a section from a memory file by heading.

Implementation

Future<MemoryFile?> removeSection(String path, String heading) async {
  final existing = _files[path];
  if (existing == null) return null;

  final sections = MemoryParser.parse(existing.content);
  final filtered = sections.where((s) => s.heading != heading).toList();

  if (filtered.length == sections.length) return existing; // Not found.

  final newContent = MemoryParser.build(filtered);
  return save(path, newContent);
}