Compare commits

..

12 Commits

Author SHA1 Message Date
fish 1a525c763e 归档笔记保留 Note 格式化操作
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-07-17 22:33:41 +08:00
fish a0dffdc715 增大收集箱列表文案与时间间距 2026-07-16 21:46:43 +08:00
fish 4765d48021 收集箱列表展示完整文案 2026-07-16 21:44:51 +08:00
fish f888e28d15 添加简体中文本地化支持 2026-07-16 21:38:07 +08:00
fish c934dbad84 调整完成按钮与键盘的间距 2026-07-16 21:35:40 +08:00
fish 4088db8ec0 编辑页完成按钮改为玻璃浮动效果 2026-07-16 21:26:36 +08:00
fish 255f171aa8 编辑页键盘增加完成按钮 2026-07-16 21:19:29 +08:00
fish 70870e1ec2 编辑页增加键盘遮挡处理 2026-07-16 21:13:52 +08:00
fish f1a380d105 保存失败时返回具体错误信息 2026-07-15 23:55:36 +08:00
fish 01ad237af3 修复 TextFormatter actor 隔离警告 2026-07-15 23:47:47 +08:00
fish 7d49f7d5a4 预置快捷指令自动读取剪贴板 2026-07-15 23:43:22 +08:00
fish 87eb958869 添加预置快捷指令 2026-07-15 23:39:15 +08:00
9 changed files with 123 additions and 20 deletions
+1
View File
@@ -184,6 +184,7 @@
knownRegions = (
en,
Base,
"zh-Hans",
);
mainGroup = CFD40B073003C283009C9F2A;
minimizedProjectReferenceProxies = 1;
+67 -1
View File
@@ -10,6 +10,8 @@ import UIKit
class ClipEditViewController: UIViewController {
private var textView: UITextView!
private var floatingDoneButton: UIButton!
private var floatingDoneButtonBottomConstraint: NSLayoutConstraint!
private var clip: Clip
init(clip: Clip) {
@@ -29,6 +31,45 @@ class ClipEditViewController: UIViewController {
setupNavigationBar()
setupTextView()
setupKeyboardObservers()
}
deinit {
NotificationCenter.default.removeObserver(self)
}
private func setupKeyboardObservers() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
}
@objc private func keyboardWillShow(_ notification: Notification) {
guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return }
let keyboardFrameInView = view.convert(keyboardFrame, from: nil)
let intersection = keyboardFrameInView.intersection(view.bounds)
let keyboardHeight = intersection.height
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval ?? 0.25
UIView.animate(withDuration: duration, delay: 0, options: .beginFromCurrentState) {
self.textView.contentInset.bottom = keyboardHeight
self.textView.verticalScrollIndicatorInsets.bottom = keyboardHeight
self.floatingDoneButtonBottomConstraint.constant = -(keyboardHeight + 8)
self.floatingDoneButton.alpha = 1
self.view.layoutIfNeeded()
}
}
@objc private func keyboardWillHide(_ notification: Notification) {
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval ?? 0.25
UIView.animate(withDuration: duration, delay: 0, options: .beginFromCurrentState) {
self.textView.contentInset.bottom = 0
self.textView.verticalScrollIndicatorInsets.bottom = 0
self.floatingDoneButtonBottomConstraint.constant = -16
self.floatingDoneButton.alpha = 0
self.view.layoutIfNeeded()
}
}
override func viewDidAppear(_ animated: Bool) {
@@ -61,15 +102,40 @@ class ClipEditViewController: UIViewController {
textView.text = clip.text
view.addSubview(textView)
var doneConfig = UIButton.Configuration.glass()
doneConfig.title = "完成"
doneConfig.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
var outgoing = incoming
outgoing.font = UIFont.systemFont(ofSize: 17, weight: .semibold)
return outgoing
}
doneConfig.baseForegroundColor = .label
doneConfig.cornerStyle = .capsule
doneConfig.contentInsets = NSDirectionalEdgeInsets(top: 15, leading: 22, bottom: 15, trailing: 22)
floatingDoneButton = UIButton(configuration: doneConfig)
floatingDoneButton.translatesAutoresizingMaskIntoConstraints = false
floatingDoneButton.alpha = 0
floatingDoneButton.addTarget(self, action: #selector(didTapFloatingDoneButton), for: .touchUpInside)
view.addSubview(floatingDoneButton)
let safeArea = view.safeAreaLayoutGuide
floatingDoneButtonBottomConstraint = floatingDoneButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -16)
NSLayoutConstraint.activate([
textView.topAnchor.constraint(equalTo: safeArea.topAnchor, constant: 16),
textView.leadingAnchor.constraint(equalTo: safeArea.leadingAnchor, constant: 16),
textView.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor, constant: -16),
textView.bottomAnchor.constraint(equalTo: safeArea.bottomAnchor, constant: -16)
textView.bottomAnchor.constraint(equalTo: safeArea.bottomAnchor, constant: -16),
floatingDoneButton.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor, constant: -16),
floatingDoneButtonBottomConstraint
])
}
@objc private func didTapFloatingDoneButton() {
textView.resignFirstResponder()
}
@objc private func didTapSaveButton() {
let updatedText = textView.text ?? ""
guard !updatedText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
+3 -3
View File
@@ -246,8 +246,10 @@ extension ClipInboxViewController: UITableViewDataSource {
var config = cell.defaultContentConfiguration()
config.text = previewText(for: clip.text)
config.textProperties.numberOfLines = 0
config.secondaryText = formattedDate(clip.createdAt)
config.secondaryTextProperties.color = .secondaryLabel
config.textToSecondaryTextVerticalPadding = 12
cell.contentConfiguration = config
cell.accessoryType = .disclosureIndicator
@@ -255,9 +257,7 @@ extension ClipInboxViewController: UITableViewDataSource {
}
private func previewText(for text: String) -> String {
let lines = text.components(separatedBy: .newlines)
let firstTwoLines = Array(lines.prefix(2))
let preview = firstTwoLines.joined(separator: " ").trimmingCharacters(in: .whitespaces)
let preview = text.trimmingCharacters(in: .whitespacesAndNewlines)
if preview.isEmpty {
return "(无内容)"
}
+16 -5
View File
@@ -21,6 +21,17 @@ struct Clip: Codable, Identifiable, Equatable, Sendable {
}
}
enum ClipStoreError: Error, LocalizedError {
case appGroupUnavailable
var errorDescription: String? {
switch self {
case .appGroupUnavailable:
return "无法访问 App Group 容器,请检查签名和 entitlements 配置。"
}
}
}
actor ClipStore {
static let shared = ClipStore()
@@ -31,13 +42,13 @@ actor ClipStore {
private var cachedClips: [Clip]?
private var fileURL: URL {
private func fileURL() throws -> URL {
let fileManager = FileManager.default
guard let containerURL = fileManager.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier) else {
fatalError("无法访问 App Group 容器: \(appGroupIdentifier)")
throw ClipStoreError.appGroupUnavailable
}
let directoryURL = containerURL.appendingPathComponent(subdirectory, isDirectory: true)
try? fileManager.createDirectory(at: directoryURL, withIntermediateDirectories: true)
try fileManager.createDirectory(at: directoryURL, withIntermediateDirectories: true)
return directoryURL.appendingPathComponent(fileName)
}
@@ -55,7 +66,7 @@ actor ClipStore {
return cached
}
let url = fileURL
let url = try fileURL()
let fileManager = FileManager.default
guard fileManager.fileExists(atPath: url.path) else {
cachedClips = []
@@ -93,7 +104,7 @@ actor ClipStore {
}
private func persist(_ clips: [Clip]) async throws {
let url = fileURL
let url = try fileURL()
let data = try JSONEncoder().encode(clips)
try data.write(to: url, options: .atomic)
cachedClips = clips
-4
View File
@@ -35,10 +35,6 @@ class FormatNoteViewController: UIViewController {
setupUI()
if let initialText = initialText {
textView.text = initialText
isNoteFormatted = true
noteButton.setTitle("复制并打开备忘录", for: .normal)
rightBarButtonMode = .reset
updateRightBarButtonItem()
}
setupKeyboardObservers()
}
+20
View File
@@ -0,0 +1,20 @@
//
// NoteAppShortcuts.swift
// Note
//
// Created by Kimi Code CLI on 2026/7/15.
//
import AppIntents
struct NoteAppShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: SaveClipIntent(),
phrases: ["保存剪贴板到 ${applicationName}"],
shortTitle: "保存剪贴板",
systemImageName: "doc.text"
)
}
}
+10 -2
View File
@@ -6,13 +6,14 @@
//
import AppIntents
import UIKit
struct SaveClipIntent: AppIntent {
static var title: LocalizedStringResource = "保存剪贴板到 Note"
static var description: IntentDescription? = "将一段文本保存到 Note App 的收集箱,稍后统一处理。"
@Parameter(title: "文案", description: "要保存的文本内容", requestValueDialog: "请提供要保存的文案")
@Parameter(title: "文案", description: "要保存的文本内容", default: "")
var text: String
@Parameter(title: "来源", description: "文案来源,例如应用名称", default: "快捷指令")
@@ -26,7 +27,14 @@ struct SaveClipIntent: AppIntent {
}
func perform() async throws -> some IntentResult & ReturnsValue<String> {
let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
var inputText = text
if inputText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
inputText = await MainActor.run {
UIPasteboard.general.string ?? ""
}
}
let trimmed = inputText.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmed.isEmpty else {
return .result(value: "文案为空,未保存。")
}
+5 -5
View File
@@ -9,7 +9,7 @@ import Foundation
enum TextFormatter {
static func formatLog(_ text: String) -> String {
static nonisolated func formatLog(_ text: String) -> String {
var content = text
content = content.replacingOccurrences(of: "# ", with: "")
@@ -31,7 +31,7 @@ enum TextFormatter {
return content
}
static func formatForCloud(_ text: String) -> String {
static nonisolated func formatForCloud(_ text: String) -> String {
var content = formatForShortcut(text)
content = "# " + content
content = insertEmptyLineAfterFirstLine(content)
@@ -81,7 +81,7 @@ enum TextFormatter {
return content
}
static func formatForNote(_ text: String) -> String {
static nonisolated func formatForNote(_ text: String) -> String {
var content = text
content = content.replacingOccurrences(of: "# ", with: "")
content = content.replacingOccurrences(of: "#", with: "")
@@ -116,13 +116,13 @@ enum TextFormatter {
return result.trimmingCharacters(in: .whitespacesAndNewlines)
}
static func removeEmptyLines(_ text: String) -> String {
static nonisolated func removeEmptyLines(_ text: String) -> String {
let lines = text.components(separatedBy: .newlines)
let nonEmptyLines = lines.filter { !$0.trimmingCharacters(in: .whitespaces).isEmpty }
return nonEmptyLines.joined(separator: "\n")
}
static func insertEmptyLineAfterFirstLine(_ text: String) -> String {
static nonisolated func insertEmptyLineAfterFirstLine(_ text: String) -> String {
var lines = text.components(separatedBy: .newlines)
if !lines.isEmpty {
lines.insert("", at: 1)
+1
View File
@@ -0,0 +1 @@
/* Simplified Chinese localization */