Skip to content
Merged
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,16 @@ public extension NSPasteboard {
setString(url, forType: .URL)
}

// Handle the case where the pasted content has different line endings
if let lineBreak, let sanitized = string?.sanitizing(lineBreak: lineBreak), sanitized != string {
let sanitized: String? = {
// Prefer pasting plain text for source code
let containsCode = (types ?? []).contains { $0.rawValue.hasPrefix("SourceEditor") }
// Normalize line endings when the pasted content uses a different style
let lineBreakNormalized = (lineBreak.flatMap { string?.sanitizing(lineBreak: $0) }) ?? string
// Paste plain text for source code, or whenever line endings were changed
return (containsCode || lineBreakNormalized != string) ? lineBreakNormalized : nil
}()
Comment thread
cyanzhong marked this conversation as resolved.

if let sanitized {
let savedItems = getDataItems()
declareTypes([.string], owner: nil)
setString(sanitized, forType: .string)
Comment thread
cyanzhong marked this conversation as resolved.
Expand Down