Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 38 additions & 34 deletions Maccy/Clipboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Copy Markdown
Owner

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?

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
Copy link
Copy Markdown

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.

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.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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)
Expand Down
12 changes: 11 additions & 1 deletion Maccy/Views/KeyHandlingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Copy Markdown
Owner

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().

let selectedItem = appState.history.selectedItem?.item,
event.modifierFlags.contains(.option),
event.modifierFlags.contains(.shift) {
Comment thread
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()
Expand Down
4 changes: 1 addition & 3 deletions Maccy/Views/PreviewItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import KeyboardShortcuts
import SwiftUI

struct PreviewItemView: View {
weak var item: HistoryItemDecorator?

Copy link
Copy Markdown

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

var body: some View {
var item: HistoryItemDecorator
if let item = item {
VStack(alignment: .leading, spacing: 0) {
if let image = item.previewImage {
Expand Down