-
-
Notifications
You must be signed in to change notification settings - Fork 940
Add extract text from image feature to clipboard preview #1152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
a77b3fe
706122d
8ed07b0
1e24098
98fbd21
aaa3f7c
734bfa9
31d86f6
91bc8ad
bb04a2b
3cc1162
74b0919
8c8f3ab
d2f666f
8f72a12
aa440a5
e2e1e05
5728ff3
66d3b85
b38eaca
6ab20da
f481043
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,48 +70,52 @@ class Clipboard { | |
| checkForChangesInPasteboard() | ||
| } | ||
|
|
||
| @MainActor | ||
| func copy(_ item: HistoryItem?, removeFormatting: Bool = false) { | ||
| guard let item else { return } | ||
|
|
||
| pasteboard.clearContents() | ||
| var contents = item.contents | ||
|
|
||
| if removeFormatting { | ||
| contents = clearFormatting(contents) | ||
| } | ||
| @MainActor | ||
| func copy(_ item: HistoryItem?, removeFormatting: Bool = false) { | ||
| guard let item else { return } | ||
|
|
||
| pasteboard.clearContents() | ||
| // Special handling for images with text when removeFormatting is true | ||
| if removeFormatting && item.image != nil && !item.title.isEmpty { | ||
| // For images with text recognition, just paste the title as plain tex | ||
| pasteboard.setString(item.title, forType: .string) | ||
| } else { | ||
| // Regular handling for other content types | ||
| var contents = item.contents | ||
| if removeFormatting { | ||
| contents = clearFormatting(contents) | ||
| } | ||
|
|
||
| for content in contents { | ||
| guard content.type != NSPasteboard.PasteboardType.fileURL.rawValue else { continue } | ||
| pasteboard.setData(content.value, forType: NSPasteboard.PasteboardType(content.type)) | ||
| } | ||
| for content in contents { | ||
| guard content.type != NSPasteboard.PasteboardType.fileURL.rawValue else { continue } | ||
| pasteboard.setData(content.value, forType: NSPasteboard.PasteboardType(content.type)) | ||
| } | ||
|
|
||
| // Use writeObjects for file URLs so that multiple files that are copied actually work. | ||
| // Only do this for file URLs because it causes an issue with some other data types (like formatted text) | ||
| // where the item is pasted more than once. | ||
| let fileURLItems: [NSPasteboardItem] = contents.compactMap { item in | ||
| guard item.type == NSPasteboard.PasteboardType.fileURL.rawValue else { return nil } | ||
| guard let value = item.value else { return nil } | ||
| let pasteItem = NSPasteboardItem() | ||
| pasteItem.setData(value, forType: NSPasteboard.PasteboardType(item.type)) | ||
| return pasteItem | ||
| } | ||
| pasteboard.writeObjects(fileURLItems) | ||
| // Use writeObjects for file URLs so that multiple files that are copied actually work. | ||
| // Only do this for file URLs because it causes an issue with some other data types (like formatted text) | ||
| // where the item is pasted more than once. | ||
| let fileURLItems: [NSPasteboardItem] = contents.compactMap { item in | ||
| guard item.type == NSPasteboard.PasteboardType.fileURL.rawValue else { return nil } | ||
| guard let value = item.value else { return nil } | ||
| let pasteItem = NSPasteboardItem() | ||
| pasteItem.setData(value, forType: NSPasteboard.PasteboardType(item.type)) | ||
|
Comment on lines
+89
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be wrong, but it looks like there's a lot of non-meaningful whitespace changes here muddying up the pull request diff. Can those be cleaned up so reviewers can zero in on functional changes? Please and thank you. |
||
| return pasteItem | ||
| } | ||
| pasteboard.writeObjects(fileURLItems) | ||
| } | ||
|
|
||
| pasteboard.setString("", forType: .fromMaccy) | ||
| pasteboard.setString(item.application ?? "", forType: .source) | ||
| sync() | ||
| pasteboard.setString("", forType: .fromMaccy) | ||
| pasteboard.setString(item.application ?? "", forType: .source) | ||
| sync() | ||
|
|
||
| Task { | ||
| Notifier.notify(body: item.title, sound: .knock) | ||
| checkForChangesInPasteboard() | ||
| Task { | ||
| Notifier.notify(body: item.title, sound: .knock) | ||
| checkForChangesInPasteboard() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Based on https://github.com/Clipy/Clipy/blob/develop/Clipy/Sources/Services/PasteService.swift. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you revert? |
||
| func paste() { | ||
| Accessibility.check() | ||
|
|
||
| // Add flag that left/right modifier key has been pressed. | ||
| // See https://github.com/TermiT/Flycut/pull/18 for details. | ||
| let cmdFlag = CGEventFlags(rawValue: UInt64(KeyChord.pasteKeyModifiers.rawValue) | 0x000008) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,7 +100,17 @@ struct KeyHandlingView<Content: View>: View { | |
| appState.history.togglePin(appState.history.selectedItem) | ||
| return .handled | ||
| case .selectCurrentItem: | ||
| appState.select() | ||
| if let event = NSApp.currentEvent, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need that, it should be already handled in |
||
| let selectedItem = appState.history.selectedItem?.item, | ||
| event.modifierFlags.contains(.option), | ||
| event.modifierFlags.contains(.shift) { | ||
|
DanNoby marked this conversation as resolved.
|
||
| // Option+Shift+Enter: paste without formatting | ||
| Clipboard.shared.copy(selectedItem, removeFormatting: true) | ||
| appState.popup.close() | ||
| Clipboard.shared.paste() | ||
| } else { | ||
| appState.select() | ||
| } | ||
| return .handled | ||
| case .close: | ||
| appState.popup.close() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,7 @@ import KeyboardShortcuts | |
| import SwiftUI | ||
|
|
||
| struct PreviewItemView: View { | ||
| weak var item: HistoryItemDecorator? | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please undo this whitespace change, or move it to a dinstinct formatting-focused PR |
||
| var body: some View { | ||
| var item: HistoryItemDecorator | ||
| if let item = item { | ||
| VStack(alignment: .leading, spacing: 0) { | ||
| if let image = item.previewImage { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why you needed to increase indentation, can you revert?