格式化操作增加空内容拦截和 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
+14
View File
@@ -74,6 +74,10 @@ class FormatLogViewController: UIViewController {
} }
@objc private func didTapFormatButton() { @objc private func didTapFormatButton() {
guard !trimmedText().isEmpty else {
showEmptyAlert()
return
}
if isFormatted { if isFormatted {
saveToFiles() saveToFiles()
} else { } else {
@@ -91,6 +95,16 @@ class FormatLogViewController: 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() { @objc private func didTapResetButton() {
textView.text = "" textView.text = ""
isFormatted = false isFormatted = false
+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() { @objc private func didTapResetButton() {
textView.text = "" textView.text = ""
rightBarButtonMode = .paste rightBarButtonMode = .paste
@@ -124,6 +134,10 @@ class FormatNoteViewController: UIViewController {
} }
@objc private func didTapiCloudButton() { @objc private func didTapiCloudButton() {
guard !trimmedText().isEmpty else {
showEmptyAlert()
return
}
if isCloudFormatted { if isCloudFormatted {
saveToFiles() saveToFiles()
} else { } else {
@@ -136,6 +150,10 @@ class FormatNoteViewController: UIViewController {
} }
@objc private func didTapNoteButton() { @objc private func didTapNoteButton() {
guard !trimmedText().isEmpty else {
showEmptyAlert()
return
}
textView.text = formatForNote(textView.text) textView.text = formatForNote(textView.text)
rightBarButtonMode = .reset rightBarButtonMode = .reset
updateRightBarButtonItem() updateRightBarButtonItem()