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);