Compare commits
12 Commits
4340fd3635
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a525c763e | |||
| a0dffdc715 | |||
| 4765d48021 | |||
| f888e28d15 | |||
| c934dbad84 | |||
| 4088db8ec0 | |||
| 255f171aa8 | |||
| 70870e1ec2 | |||
| f1a380d105 | |||
| 01ad237af3 | |||
| 7d49f7d5a4 | |||
| 87eb958869 |
@@ -184,6 +184,7 @@
|
||||
knownRegions = (
|
||||
en,
|
||||
Base,
|
||||
"zh-Hans",
|
||||
);
|
||||
mainGroup = CFD40B073003C283009C9F2A;
|
||||
minimizedProjectReferenceProxies = 1;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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: "文案为空,未保存。")
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
/* Simplified Chinese localization */
|
||||
Reference in New Issue
Block a user