-
-
Notifications
You must be signed in to change notification settings - Fork 821
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?
Conversation
|
This was requested part of #1063 and I think we should implement it as "Paste without formatting" shortcut. There is already logic to extract text from image and store it inside "title" field (see 2255498). With this in-place, we only need to add a special handling of paste without formatting to copy the title of |
|
Got it, thanks... Just to confirm — shall I go ahead and work on the “Paste without formatting” shortcut and update this PR to follow the approach you described (i.e., copying from the title field of the HistoryItem)? Happy to modify this PR accordingly if that works for you. |
|
@DanNoby It would be great. This should be as simple as probably adding a condition to check for image + removeFormatting somewhere in Lines 73 to 109 in 245986b
|
|
I’ve updated the PR to implement the “Paste without formatting” feature as discussed. I ran into a few SwiftLint and build issues along the way — sorry for the extra commits while I worked through them 😅 |
|
I wouldn't be against having both : a shortcut (what @p0deje proposes) , as well as an option in the form of apple OCR in the bottom right after performing an image preview . generally, good software have both, as visual indicator helps paliate a potential memory issue |
hi, has this been implemented yet ? i can't really tell because i have issues with paste without formatting anyway |
| 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)) |
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.
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.
|
|
||
| struct PreviewItemView: View { | ||
| var item: HistoryItemDecorator | ||
|
|
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.
Please undo this whitespace change, or move it to a dinstinct formatting-focused PR
| return .handled | ||
| case .selectCurrentItem: | ||
| appState.select() | ||
| if let event = NSApp.currentEvent, |
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.
You don't need that, it should be already handled in History.select().
| } | ||
| } | ||
|
|
||
| // Based on https://github.com/Clipy/Clipy/blob/develop/Clipy/Sources/Services/PasteService.swift. |
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.
Can you revert?
| contents = clearFormatting(contents) | ||
| } | ||
| @MainActor | ||
| func copy(_ item: HistoryItem?, removeFormatting: Bool = false) { |
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?
This feature aims to allows users to extract text from images in their clipboard history using Apple’s Vision framework.
When previewing an image in the clipboard history, an “Extract Text” button appears.
Clicking the button runs OCR on the image and copies the extracted text directly to the clipboard.
The feature is only visible for image items.
No popups or alerts are shown; feedback is via clipboard update.
Technical notes:
Uses Apple’s Vision framework for OCR (macOS 10.15+).
UI/UX is minimal and consistent with the Maccy's design.
Tested on:
macOS Sequoia 15.5, Xcode 16.43