Bugfixes, renames, create custom TextEditor, logic simplifications

This commit is contained in:
2026-05-14 20:21:41 +02:00
parent 23fd16f88e
commit 3e8d5eb025
8 changed files with 83 additions and 28 deletions
@@ -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)
}