diff --git a/Note/FormatNoteViewController.swift b/Note/FormatNoteViewController.swift index 39ca2c1..36dfa29 100644 --- a/Note/FormatNoteViewController.swift +++ b/Note/FormatNoteViewController.swift @@ -17,6 +17,7 @@ class FormatNoteViewController: UIViewController { private var resetButton: UIBarButtonItem! private var rightBarButtonMode: RightBarButtonMode = .paste private var isCloudFormatted = false + private var isNoteFormatted = false private enum RightBarButtonMode { case paste @@ -120,7 +121,9 @@ class FormatNoteViewController: UIViewController { textView.text = "" rightBarButtonMode = .paste isCloudFormatted = false + isNoteFormatted = false iCloudButton.setTitle("iCloud 格式化", for: .normal) + noteButton.setTitle("Note 格式化", for: .normal) updateRightBarButtonItem() } @@ -158,9 +161,22 @@ class FormatNoteViewController: UIViewController { showEmptyAlert() return } - textView.text = formatForNote(textView.text) - rightBarButtonMode = .reset - updateRightBarButtonItem() + if isNoteFormatted { + copyAndOpenNotes() + } else { + textView.text = formatForNote(textView.text) + isNoteFormatted = true + noteButton.setTitle("复制并打开备忘录", for: .normal) + rightBarButtonMode = .reset + updateRightBarButtonItem() + } + } + + private func copyAndOpenNotes() { + UIPasteboard.general.string = textView.text + guard let url = URL(string: "mobilenotes://") else { return } + guard UIApplication.shared.canOpenURL(url) else { return } + UIApplication.shared.open(url, options: [:], completionHandler: nil) } private func formatForCloud(_ text: String) -> String {