From 401a6dafc803354b0b110fd97a1b80e1a1495702 Mon Sep 17 00:00:00 2001 From: fish Date: Sun, 12 Jul 2026 21:36:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A9=BA=E5=86=85=E5=AE=B9=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E5=92=8C=20Alert=20=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Note/FormatLogViewController.swift | 14 ++++++++++++++ Note/FormatNoteViewController.swift | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/Note/FormatLogViewController.swift b/Note/FormatLogViewController.swift index ca5e2cf..de8394a 100644 --- a/Note/FormatLogViewController.swift +++ b/Note/FormatLogViewController.swift @@ -74,6 +74,10 @@ class FormatLogViewController: UIViewController { } @objc private func didTapFormatButton() { + guard !trimmedText().isEmpty else { + showEmptyAlert() + return + } if isFormatted { saveToFiles() } 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() { textView.text = "" isFormatted = false diff --git a/Note/FormatNoteViewController.swift b/Note/FormatNoteViewController.swift index 29509a0..9bd658f 100644 --- a/Note/FormatNoteViewController.swift +++ b/Note/FormatNoteViewController.swift @@ -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()