diff --git a/lib/data/repo_note.dart b/lib/data/repo_note.dart index 143fb14..c74c604 100644 --- a/lib/data/repo_note.dart +++ b/lib/data/repo_note.dart @@ -4,7 +4,6 @@ library; import 'package:todo/data/note.dart'; import 'package:todo/data/note_repository.dart'; -import 'package:todo/data/note_template.dart'; import 'package:uuid/uuid.dart'; /// Statuses that count as open. @@ -31,8 +30,15 @@ String repoSection(String title, String body) { Priority maxPriority(Priority a, Priority b) => a.value >= b.value ? a : b; /// Title line and rest of a note's text. -({String title, String body}) splitNote(String text) => - (title: noteTitle(text), body: text.split('\n').skip(1).join('\n').trim()); +({String title, String body}) splitNote(String text) { + final lines = text.split('\n'); + final first = lines.indexWhere((l) => l.trim().isNotEmpty); + if (first < 0) return (title: '', body: ''); + return ( + title: lines[first].trim().replaceFirst(RegExp(r'^#+\s*'), ''), + body: lines.skip(first + 1).join('\n').trim(), + ); +} /// Oldest first; ties broken by id so the choice is deterministic. int byAge(Note a, Note b) { diff --git a/pubspec.yaml b/pubspec.yaml index 2cfd9ef..33f71f0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.57+1 +version: 1.0.58+1 environment: sdk: ^3.12.2 diff --git a/test/repo_note_test.dart b/test/repo_note_test.dart index 1d00ae9..8bec462 100644 --- a/test/repo_note_test.dart +++ b/test/repo_note_test.dart @@ -41,6 +41,10 @@ void main() { }); }); + test('splitNote of blank text is empty', () { + expect(splitNote(' \n'), (title: '', body: '')); + }); + group('addRepoTask', () { late NoteRepository repo; setUp(() async => repo = await NoteRepository.openInMemory()); @@ -165,6 +169,11 @@ void main() { ); }); + test('a leading blank line and a # prefix do not leak into sections', () { + final plan = planRepoMerges([_n('a', '\n# Title\nbody')]); + expect(plan.single.kept.text, 'wake-alarm todos\n\n## Title\nbody'); + }); + test('closed notes and plain ideas are ignored', () { final idea = Note( id: 'i',