Rename Note: Ensure markdown files end with .md

This broke when supporting txt files
This commit is contained in:
Vishesh Handa
2020-06-10 15:15:47 +02:00
parent 2502f4a79d
commit ae74e02fa7
2 changed files with 11 additions and 8 deletions

View File

@ -306,24 +306,26 @@ class Note with NotesNotifier {
void rename(String newName) { void rename(String newName) {
// Do not let the user rename it to a non-markdown file // Do not let the user rename it to a non-markdown file
switch (_fileFormat) { switch (_fileFormat) {
case NoteFileFormat.Markdown:
if (!newName.toLowerCase().endsWith('.md')) {
newName += '.md';
}
break;
case NoteFileFormat.Txt: case NoteFileFormat.Txt:
if (!newName.toLowerCase().endsWith('.txt')) { if (!newName.toLowerCase().endsWith('.txt')) {
newName += '.txt'; newName += '.txt';
} }
break; break;
case NoteFileFormat.Markdown:
default:
if (!newName.toLowerCase().endsWith('.md')) {
newName += '.md';
}
break;
} }
var oldFilePath = filePath; var oldFilePath = filePath;
var parentDirName = p.dirname(filePath); var parentDirName = p.dirname(filePath);
var newFilePath = p.join(parentDirName, newName); 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); File(filePath).renameSync(newFilePath);
} }
_filePath = newFilePath; _filePath = newFilePath;

View File

@ -229,6 +229,7 @@ class NoteEditorState extends State<NoteEditor> {
note = _note; note = _note;
note.rename(fileName); note.rename(fileName);
}); });
return;
} }
var container = Provider.of<StateContainer>(context, listen: false); var container = Provider.of<StateContainer>(context, listen: false);
container.renameNote(note, fileName); container.renameNote(note, fileName);