Bugfixes, renames, create custom TextEditor, logic simplifications
This commit is contained in:
@@ -36,8 +36,10 @@ struct NotesStorage {
|
||||
|
||||
func createNote(name: String) {
|
||||
let currentNotes = loadNotes()
|
||||
var proposedName = name
|
||||
var index: Int? = nil
|
||||
var proposedName: String {
|
||||
index.map { name + " \($0)" } ?? name
|
||||
}
|
||||
|
||||
while currentNotes.contains(where: { $0.name == proposedName }) {
|
||||
if let _index = index {
|
||||
@@ -46,12 +48,6 @@ struct NotesStorage {
|
||||
index = 1
|
||||
}
|
||||
}
|
||||
|
||||
proposedName = if let index {
|
||||
"\(proposedName) \(index)"
|
||||
} else {
|
||||
proposedName
|
||||
}
|
||||
let pathToWrite = URL.documentsDirectory.appendingPathComponent(proposedName).appendingPathExtension(for: .text)
|
||||
try! String().write(to: pathToWrite, atomically: true, encoding: .utf8)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user