mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 10:17:16 +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;
|
DateTime _modified;
|
||||||
String _body = "";
|
String _body = "";
|
||||||
NoteType _type = NoteType.Unknown;
|
NoteType _type = NoteType.Unknown;
|
||||||
List<String> _tags = [];
|
Set<String> _tags = {};
|
||||||
|
|
||||||
MdYamlDoc _data = MdYamlDoc();
|
MdYamlDoc _data = MdYamlDoc();
|
||||||
NoteSerializer noteSerializer = NoteSerializer();
|
NoteSerializer noteSerializer = NoteSerializer();
|
||||||
@ -125,11 +125,11 @@ class Note with NotesNotifier {
|
|||||||
_notifyModified();
|
_notifyModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> get tags {
|
Set<String> get tags {
|
||||||
return _tags;
|
return _tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
set tags(List<String> tags) {
|
set tags(Set<String> tags) {
|
||||||
if (!canHaveMetadata) return;
|
if (!canHaveMetadata) return;
|
||||||
|
|
||||||
_tags = tags;
|
_tags = tags;
|
||||||
|
@ -60,7 +60,7 @@ class NoteSerializer implements NoteSerializerInterface {
|
|||||||
if (note.tags.isEmpty) {
|
if (note.tags.isEmpty) {
|
||||||
data.props.remove(settings.tagsKey);
|
data.props.remove(settings.tagsKey);
|
||||||
} else {
|
} else {
|
||||||
data.props[settings.tagsKey] = note.tags;
|
data.props[settings.tagsKey] = note.tags.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
data.body = emojiParser.unemojify(note.body);
|
data.body = emojiParser.unemojify(note.body);
|
||||||
@ -108,7 +108,7 @@ class NoteSerializer implements NoteSerializerInterface {
|
|||||||
try {
|
try {
|
||||||
var tags = data.props[settings.tagsKey] as YamlList;
|
var tags = data.props[settings.tagsKey] as YamlList;
|
||||||
if (tags != null) {
|
if (tags != null) {
|
||||||
note.tags = tags.map((t) => t.toString()).toList();
|
note.tags = tags.map((t) => t.toString()).toSet();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Log.e("Note Decoding Failed: $e");
|
Log.e("Note Decoding Failed: $e");
|
||||||
|
@ -93,11 +93,11 @@ Hello""";
|
|||||||
var note = Note(parentFolder, notePath);
|
var note = Note(parentFolder, notePath);
|
||||||
await note.load();
|
await note.load();
|
||||||
|
|
||||||
expect(note.tags[0], 'A');
|
expect(note.tags.contains('A'), true);
|
||||||
expect(note.tags[1], 'B');
|
expect(note.tags.contains('B'), true);
|
||||||
expect(note.tags.length, 2);
|
expect(note.tags.length, 2);
|
||||||
|
|
||||||
note.tags = [...note.tags]..add('C');
|
note.tags = {...note.tags}..add('C');
|
||||||
note.tags.add('D');
|
note.tags.add('D');
|
||||||
note.tags.remove('B');
|
note.tags.remove('B');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user