From ae74e02fa7747c73dcbfdf7a7e3dd29d0d51e6b6 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Wed, 10 Jun 2020 15:15:47 +0200 Subject: [PATCH] Rename Note: Ensure markdown files end with .md This broke when supporting txt files --- lib/core/note.dart | 18 ++++++++++-------- lib/screens/note_editor.dart | 1 + 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/core/note.dart b/lib/core/note.dart index 558b921b..1bb47eda 100644 --- a/lib/core/note.dart +++ b/lib/core/note.dart @@ -306,24 +306,26 @@ class Note with NotesNotifier { void rename(String newName) { // Do not let the user rename it to a non-markdown file switch (_fileFormat) { - case NoteFileFormat.Markdown: - if (!newName.toLowerCase().endsWith('.md')) { - newName += '.md'; - } - break; - case NoteFileFormat.Txt: if (!newName.toLowerCase().endsWith('.txt')) { newName += '.txt'; } break; + + case NoteFileFormat.Markdown: + default: + if (!newName.toLowerCase().endsWith('.md')) { + newName += '.md'; + } + break; } var oldFilePath = filePath; var parentDirName = p.dirname(filePath); var newFilePath = p.join(parentDirName, newName); - if (_loadState != NoteLoadState.None) { - // for new notes + + // The file will not exist for new notes + if (File(oldFilePath).existsSync()) { File(filePath).renameSync(newFilePath); } _filePath = newFilePath; diff --git a/lib/screens/note_editor.dart b/lib/screens/note_editor.dart index 6b01af00..643d7d2b 100644 --- a/lib/screens/note_editor.dart +++ b/lib/screens/note_editor.dart @@ -229,6 +229,7 @@ class NoteEditorState extends State { note = _note; note.rename(fileName); }); + return; } var container = Provider.of(context, listen: false); container.renameNote(note, fileName);