格式化操作增加空内容拦截和 Alert 提示

This commit is contained in:
2026-07-12 21:36:41 +08:00
parent 95744da9c7
commit 401a6dafc8
2 changed files with 32 additions and 0 deletions
+18
View File
@@ -102,6 +102,16 @@ class FormatNoteViewController: UIViewController {
}
}
private func trimmedText() -> String {
return textView.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
}
private func showEmptyAlert() {
let alert = UIAlertController(title: "提示", message: "请输入内容后再进行格式化", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "确定", style: .default))
present(alert, animated: true)
}
@objc private func didTapResetButton() {
textView.text = ""
rightBarButtonMode = .paste
@@ -124,6 +134,10 @@ class FormatNoteViewController: UIViewController {
}
@objc private func didTapiCloudButton() {
guard !trimmedText().isEmpty else {
showEmptyAlert()
return
}
if isCloudFormatted {
saveToFiles()
} else {
@@ -136,6 +150,10 @@ class FormatNoteViewController: UIViewController {
}
@objc private func didTapNoteButton() {
guard !trimmedText().isEmpty else {
showEmptyAlert()
return
}
textView.text = formatForNote(textView.text)
rightBarButtonMode = .reset
updateRightBarButtonItem()