From ec3cb14cc6bdd942d175e783d0e1222573d1f152 Mon Sep 17 00:00:00 2001 From: miyashi Date: Fri, 22 Jul 2022 06:09:27 +0900 Subject: [PATCH 1/6] hover select --- CopyHistory/CopyHistory.xcodeproj/project.pbxproj | 4 ++-- CopyHistory/CopyHistory/ContentView.swift | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CopyHistory/CopyHistory.xcodeproj/project.pbxproj b/CopyHistory/CopyHistory.xcodeproj/project.pbxproj index 3acc7f8..607c049 100644 --- a/CopyHistory/CopyHistory.xcodeproj/project.pbxproj +++ b/CopyHistory/CopyHistory.xcodeproj/project.pbxproj @@ -271,7 +271,7 @@ CODE_SIGN_ENTITLEMENTS = CopyHistory/CopyHistory.entitlements; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 17; + CURRENT_PROJECT_VERSION = 18; DEVELOPMENT_TEAM = H6UU7923NK; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; @@ -301,7 +301,7 @@ CODE_SIGN_ENTITLEMENTS = CopyHistory/CopyHistory.entitlements; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 17; + CURRENT_PROJECT_VERSION = 18; DEVELOPMENT_TEAM = H6UU7923NK; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; diff --git a/CopyHistory/CopyHistory/ContentView.swift b/CopyHistory/CopyHistory/ContentView.swift index ea7b68e..6c8dcad 100644 --- a/CopyHistory/CopyHistory/ContentView.swift +++ b/CopyHistory/CopyHistory/ContentView.swift @@ -11,10 +11,10 @@ import WebKit struct ContentView: View { @StateObject var pasteboardService: PasteboardService = .build() - @AppStorage("isShowingKeyboardShortcuts") var isShowingKeyboardShortcuts = true @FocusState var isFocus @State var isAlertPresented: Bool = false @State var focusedItemIndex: Int? + @AppStorage("isShowingKeyboardShortcuts") var isShowingKeyboardShortcuts = true @AppStorage("isExpanded") var isExpanded: Bool = true @AppStorage("isShowingRTF") var isShowingRTF: Bool = false @AppStorage("isShowingHTML") var isShowingHTML: Bool = false @@ -154,9 +154,10 @@ struct ContentView: View { @ViewBuilder func MainView() -> some View { ScrollView { - Spacer() // there is a mysterious plain view at the top of the scrollview and it overlays this content. so this is put here + // there is a mysterious plain view at the top of the scrollview and it overlays this content. so this is put here + Spacer() ScrollViewReader { proxy in - VStack(spacing: 0) { // This doesn't make ScrollView + ForEach make additional padding + VStack(spacing: 0) { // This doesn't make ScrollView + ForEach make additional padding, https://www.reddit.com/r/SwiftUI/comments/e607z3/swiftui_scrollview_foreach_padding_weird/ ForEach(Array(zip(pasteboardService.copiedItems.indices, pasteboardService.copiedItems)), id: \.1.dataHash) { index, item in Row(item: item, @@ -173,6 +174,12 @@ struct ContentView: View { isShowingRTF: $isShowingRTF, isShowingHTML: $isShowingHTML) .id(item.dataHash) + .onHover(perform: { hover in + if hover { + focusedItemIndex = index + } + + }) } } From b1f28c5ea1b4f13639636d5037272bf2ac1cf041 Mon Sep 17 00:00:00 2001 From: miyashi Date: Fri, 22 Jul 2022 06:09:55 +0900 Subject: [PATCH 2/6] update version --- CopyHistory/CopyHistory.xcodeproj/project.pbxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CopyHistory/CopyHistory.xcodeproj/project.pbxproj b/CopyHistory/CopyHistory.xcodeproj/project.pbxproj index 607c049..82d07a2 100644 --- a/CopyHistory/CopyHistory.xcodeproj/project.pbxproj +++ b/CopyHistory/CopyHistory.xcodeproj/project.pbxproj @@ -271,7 +271,7 @@ CODE_SIGN_ENTITLEMENTS = CopyHistory/CopyHistory.entitlements; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 18; + CURRENT_PROJECT_VERSION = 19; DEVELOPMENT_TEAM = H6UU7923NK; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; @@ -285,7 +285,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.0; - MARKETING_VERSION = 1.0.7; + MARKETING_VERSION = 1.0.8; PRODUCT_BUNDLE_IDENTIFIER = "jp.po-miyasaka.CopyHistory.CopyHistory"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; @@ -301,7 +301,7 @@ CODE_SIGN_ENTITLEMENTS = CopyHistory/CopyHistory.entitlements; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 18; + CURRENT_PROJECT_VERSION = 19; DEVELOPMENT_TEAM = H6UU7923NK; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; @@ -315,7 +315,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.0; - MARKETING_VERSION = 1.0.7; + MARKETING_VERSION = 1.0.8; PRODUCT_BUNDLE_IDENTIFIER = "jp.po-miyasaka.CopyHistory.CopyHistory"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; From 74dbbb118276190f62ab347d437576ca8c904a5e Mon Sep 17 00:00:00 2001 From: miyashi Date: Sat, 23 Jul 2022 04:10:05 +0900 Subject: [PATCH 3/6] improving search & scroll performance --- CopyHistory/CopyHistory/ContentView.swift | 5 ++++- .../Model.xcdatamodeld/Model2.xcdatamodel/contents | 4 +++- CopyHistory/CopyHistory/PasteboardService.swift | 9 ++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CopyHistory/CopyHistory/ContentView.swift b/CopyHistory/CopyHistory/ContentView.swift index 6c8dcad..e8b8d3c 100644 --- a/CopyHistory/CopyHistory/ContentView.swift +++ b/CopyHistory/CopyHistory/ContentView.swift @@ -157,7 +157,10 @@ struct ContentView: View { // there is a mysterious plain view at the top of the scrollview and it overlays this content. so this is put here Spacer() ScrollViewReader { proxy in - VStack(spacing: 0) { // This doesn't make ScrollView + ForEach make additional padding, https://www.reddit.com/r/SwiftUI/comments/e607z3/swiftui_scrollview_foreach_padding_weird/ + LazyVStack(spacing: 0) { + // ・This doesn't make ScrollView + ForEach make additional padding, https://www.reddit.com/r/SwiftUI/comments/e607z3/swiftui_scrollview_foreach_padding_weird/ + // ・Lazy improves performance the inclement search + ForEach(Array(zip(pasteboardService.copiedItems.indices, pasteboardService.copiedItems)), id: \.1.dataHash) { index, item in Row(item: item, diff --git a/CopyHistory/CopyHistory/Model.xcdatamodeld/Model2.xcdatamodel/contents b/CopyHistory/CopyHistory/Model.xcdatamodeld/Model2.xcdatamodel/contents index 970a91a..e30829c 100644 --- a/CopyHistory/CopyHistory/Model.xcdatamodeld/Model2.xcdatamodel/contents +++ b/CopyHistory/CopyHistory/Model.xcdatamodeld/Model2.xcdatamodel/contents @@ -1,16 +1,18 @@ + + - + \ No newline at end of file diff --git a/CopyHistory/CopyHistory/PasteboardService.swift b/CopyHistory/CopyHistory/PasteboardService.swift index 92b4788..e1d62db 100644 --- a/CopyHistory/CopyHistory/PasteboardService.swift +++ b/CopyHistory/CopyHistory/PasteboardService.swift @@ -188,14 +188,21 @@ extension CopiedItem { var attributeString: NSAttributedString? { guard let content = content else { return nil } + if let att = attibutedStringCached { + return att + } let attributeString = (try? NSAttributedString(data: content, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.rtf], documentAttributes: nil)) + attibutedStringCached = attributeString return attributeString } var htmlString: NSAttributedString? { guard let content = content else { return nil } + if let att = htmlStringCached { + return att + } let attributeString = (try? NSAttributedString(data: content, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)) - + htmlStringCached = attributeString return attributeString } From aa143fe91d50462d21bdc43d33e3befc2b04bd5f Mon Sep 17 00:00:00 2001 From: miyashi Date: Sat, 23 Jul 2022 04:16:40 +0900 Subject: [PATCH 4/6] version up --- CopyHistory/CopyHistory.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CopyHistory/CopyHistory.xcodeproj/project.pbxproj b/CopyHistory/CopyHistory.xcodeproj/project.pbxproj index 82d07a2..a63fb70 100644 --- a/CopyHistory/CopyHistory.xcodeproj/project.pbxproj +++ b/CopyHistory/CopyHistory.xcodeproj/project.pbxproj @@ -271,7 +271,7 @@ CODE_SIGN_ENTITLEMENTS = CopyHistory/CopyHistory.entitlements; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 19; + CURRENT_PROJECT_VERSION = 20; DEVELOPMENT_TEAM = H6UU7923NK; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; @@ -301,7 +301,7 @@ CODE_SIGN_ENTITLEMENTS = CopyHistory/CopyHistory.entitlements; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 19; + CURRENT_PROJECT_VERSION = 20; DEVELOPMENT_TEAM = H6UU7923NK; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; From a3a4bfa016373609822bebaf81b83372d064565a Mon Sep 17 00:00:00 2001 From: miyashi Date: Sat, 23 Jul 2022 04:16:57 +0900 Subject: [PATCH 5/6] caching attribute string --- .../Model.xcdatamodeld/Model2.xcdatamodel/contents | 2 +- CopyHistory/CopyHistory/PasteboardService.swift | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CopyHistory/CopyHistory/Model.xcdatamodeld/Model2.xcdatamodel/contents b/CopyHistory/CopyHistory/Model.xcdatamodeld/Model2.xcdatamodel/contents index e30829c..926f670 100644 --- a/CopyHistory/CopyHistory/Model.xcdatamodeld/Model2.xcdatamodel/contents +++ b/CopyHistory/CopyHistory/Model.xcdatamodeld/Model2.xcdatamodel/contents @@ -1,7 +1,6 @@ - @@ -10,6 +9,7 @@ + diff --git a/CopyHistory/CopyHistory/PasteboardService.swift b/CopyHistory/CopyHistory/PasteboardService.swift index e1d62db..9cb067c 100644 --- a/CopyHistory/CopyHistory/PasteboardService.swift +++ b/CopyHistory/CopyHistory/PasteboardService.swift @@ -187,20 +187,22 @@ extension CopiedItem { } var attributeString: NSAttributedString? { - guard let content = content else { return nil } - if let att = attibutedStringCached { + if let att = rtfStringCached { return att } + guard let content = content else { return nil } + let attributeString = (try? NSAttributedString(data: content, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.rtf], documentAttributes: nil)) - attibutedStringCached = attributeString + rtfStringCached = attributeString return attributeString } var htmlString: NSAttributedString? { - guard let content = content else { return nil } if let att = htmlStringCached { return att } + guard let content = content else { return nil } + let attributeString = (try? NSAttributedString(data: content, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)) htmlStringCached = attributeString return attributeString From ce2183b8b266d76475f9ed2c3507345a8941e2a7 Mon Sep 17 00:00:00 2001 From: miyashi Date: Sat, 23 Jul 2022 04:24:25 +0900 Subject: [PATCH 6/6] refactor --- CopyHistory/CopyHistory/ContentView.swift | 4 ++-- CopyHistory/CopyHistory/PasteboardService.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CopyHistory/CopyHistory/ContentView.swift b/CopyHistory/CopyHistory/ContentView.swift index e8b8d3c..be3e842 100644 --- a/CopyHistory/CopyHistory/ContentView.swift +++ b/CopyHistory/CopyHistory/ContentView.swift @@ -382,10 +382,10 @@ struct Row: View, Equatable { Group { if let content = item.content, let image = NSImage(data: content) { Image(nsImage: image).resizable().scaledToFit().frame(maxHeight: 300) - } else if isShowingRTF, item.contentTypeString?.contains("rtf") == true, let attributedString = item.attributeString { + } else if isShowingRTF, let attributedString = item.attributeString { Text(AttributedString(attributedString)) - } else if isShowingHTML, item.contentTypeString?.contains("html") == true, let attributedString = item.htmlString { + } else if isShowingHTML, let attributedString = item.htmlString { Text(AttributedString(attributedString)) } else if let url = item.fileURL { // TODO: why images disappear after first diff --git a/CopyHistory/CopyHistory/PasteboardService.swift b/CopyHistory/CopyHistory/PasteboardService.swift index 9cb067c..ee31a15 100644 --- a/CopyHistory/CopyHistory/PasteboardService.swift +++ b/CopyHistory/CopyHistory/PasteboardService.swift @@ -190,7 +190,7 @@ extension CopiedItem { if let att = rtfStringCached { return att } - guard let content = content else { return nil } + guard contentTypeString?.contains("rtf") == true, let content = content else { return nil } let attributeString = (try? NSAttributedString(data: content, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.rtf], documentAttributes: nil)) rtfStringCached = attributeString @@ -201,7 +201,7 @@ extension CopiedItem { if let att = htmlStringCached { return att } - guard let content = content else { return nil } + guard contentTypeString?.contains("html") == true, let content = content else { return nil } let attributeString = (try? NSAttributedString(data: content, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)) htmlStringCached = attributeString