1
0
mirror of https://github.com/GitJournal/GitJournal.git synced 2025-08-06 15:21:21 +08:00

NoteEditor Discard Changes: Do a git checkout on the file

This way it will go back to the exact original version. Our Note loading
and saving sometimes changes the yaml metadata order.

Also, this allows us to autosave the note file.
This commit is contained in:
Vishesh Handa
2020-10-22 14:57:12 +02:00
parent 73b5e56139
commit f81b2ed167
2 changed files with 9 additions and 4 deletions

@ -373,10 +373,9 @@ class NoteEditorState extends State<NoteEditor> {
}
}
void _discardChangesSelected(Note note) {
if (_noteModified(note)) {
note.data = originalNoteData;
}
void _discardChangesSelected(Note note) async {
var stateContainer = Provider.of<StateContainer>(context, listen: false);
stateContainer.discardChanges(note);
Navigator.pop(context);
}

@ -413,6 +413,12 @@ class StateContainer with ChangeNotifier {
_loadNotes();
}
}
Future<void> discardChanges(Note note) async {
var repo = await GitRepository.load(repoPath);
await repo.checkout(note.filePath);
return note.load();
}
}
Future<void> _copyDirectory(String source, String destination) async {