mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
Note: Make tags a set instead of a list
This way we don't need to check for duplicates
This commit is contained in:
@ -36,7 +36,7 @@ class Note with NotesNotifier {
|
||||
DateTime _modified;
|
||||
String _body = "";
|
||||
NoteType _type = NoteType.Unknown;
|
||||
List<String> _tags = [];
|
||||
Set<String> _tags = {};
|
||||
|
||||
MdYamlDoc _data = MdYamlDoc();
|
||||
NoteSerializer noteSerializer = NoteSerializer();
|
||||
@ -125,11 +125,11 @@ class Note with NotesNotifier {
|
||||
_notifyModified();
|
||||
}
|
||||
|
||||
List<String> get tags {
|
||||
Set<String> get tags {
|
||||
return _tags;
|
||||
}
|
||||
|
||||
set tags(List<String> tags) {
|
||||
set tags(Set<String> tags) {
|
||||
if (!canHaveMetadata) return;
|
||||
|
||||
_tags = tags;
|
||||
|
@ -60,7 +60,7 @@ class NoteSerializer implements NoteSerializerInterface {
|
||||
if (note.tags.isEmpty) {
|
||||
data.props.remove(settings.tagsKey);
|
||||
} else {
|
||||
data.props[settings.tagsKey] = note.tags;
|
||||
data.props[settings.tagsKey] = note.tags.toList();
|
||||
}
|
||||
|
||||
data.body = emojiParser.unemojify(note.body);
|
||||
@ -108,7 +108,7 @@ class NoteSerializer implements NoteSerializerInterface {
|
||||
try {
|
||||
var tags = data.props[settings.tagsKey] as YamlList;
|
||||
if (tags != null) {
|
||||
note.tags = tags.map((t) => t.toString()).toList();
|
||||
note.tags = tags.map((t) => t.toString()).toSet();
|
||||
}
|
||||
} catch (e) {
|
||||
Log.e("Note Decoding Failed: $e");
|
||||
|
@ -93,11 +93,11 @@ Hello""";
|
||||
var note = Note(parentFolder, notePath);
|
||||
await note.load();
|
||||
|
||||
expect(note.tags[0], 'A');
|
||||
expect(note.tags[1], 'B');
|
||||
expect(note.tags.contains('A'), true);
|
||||
expect(note.tags.contains('B'), true);
|
||||
expect(note.tags.length, 2);
|
||||
|
||||
note.tags = [...note.tags]..add('C');
|
||||
note.tags = {...note.tags}..add('C');
|
||||
note.tags.add('D');
|
||||
note.tags.remove('B');
|
||||
|
||||
|
Reference in New Issue
Block a user