diff --git a/assets/langs/en.yaml b/assets/langs/en.yaml index a39f24fa..80556359 100644 --- a/assets/langs/en.yaml +++ b/assets/langs/en.yaml @@ -62,7 +62,9 @@ editors: addImage: Add Image from Gallery editFileName: Edit File Name tags: Edit Tags - saveNoteFailed: Failed to Save Note + saveNoteFailed: + title: Failed to Save Note + message: We're sorry, but we cannot seem to save the Note. It has been copied to the clipboard to avoid data loss. pro: Pro actions: newNote: New Note diff --git a/lib/core/note.dart b/lib/core/note.dart index 296250a6..fd977ce0 100644 --- a/lib/core/note.dart +++ b/lib/core/note.dart @@ -303,6 +303,10 @@ class Note with NotesNotifier { await file.writeAsString(contents); } + String serialize() { + return _serializer.encode(data); + } + // FIXME: What about error handling? Future remove() async { assert(_filePath != null); diff --git a/lib/screens/note_editor.dart b/lib/screens/note_editor.dart index 196b0c02..a1debd5d 100644 --- a/lib/screens/note_editor.dart +++ b/lib/screens/note_editor.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:collection/collection.dart'; +import 'package:flutter/services.dart'; import 'package:gitjournal/core/note.dart'; import 'package:gitjournal/core/md_yaml_doc.dart'; @@ -331,11 +332,12 @@ class NoteEditorState extends State { : await stateContainer.updateNote(note); } catch (e, stackTrace) { logException(e, stackTrace); + Clipboard.setData(ClipboardData(text: note.serialize())); await showAlertDialog( context, - tr("editors.common.saveNoteFailed"), - e.toString(), + tr("editors.common.saveNoteFailed.title"), + tr("editors.common.saveNoteFailed.message"), ); return false; }