Unified · Split
| @@ -78,30 +78,24 @@ class View: NSView, CALayerDelegate { · 77 unmodified lines | ||
| 78 | 78 | override func performDragOperation(_ sender: NSDraggingInfo) -> Bool { |
| 79 | 79 | let pb = sender.draggingPasteboard |
| 80 | 80 | guard let types = pb.types else { return false } |
| 81 | + var files: [String] = [] | |
| 81 | 82 | |
| 82 | 83 | if types.contains(.fileURL) || types.contains(.URL) { |
| 83 | − if let urls = pb.readObjects(forClasses: [NSURL.self]) as? [URL] { | |
| 84 | − let files = urls.map { $0.absoluteString } | |
| 85 | − input?.open(files: files) | |
| 86 | − return true | |
| 87 | − } | |
| 84 | + guard let urls = pb.readObjects(forClasses: [NSURL.self]) as? [URL] else { return false } | |
| 85 | + files = urls.map { $0.absoluteString } | |
| 88 | 86 | } else if types.contains(.string) { |
| 89 | 87 | guard let str = pb.string(forType: .string) else { return false } |
| 90 | − var filesArray: [String] = [] | |
| 91 | − | |
| 92 | − for val in str.components(separatedBy: "\n") { | |
| 93 | − let url = val.trimmingCharacters(in: .whitespacesAndNewlines) | |
| 88 | + files = str.components(separatedBy: "\n").compactMap { | |
| 89 | + let url = $0.trimmingCharacters(in: .whitespacesAndNewlines) | |
| 94 | 90 | let path = (url as NSString).expandingTildeInPath |
| 95 | − if isURL(url) { | |
| 96 | − filesArray.append(url) | |
| 97 | − } else if path.starts(with: "/") { | |
| 98 | − filesArray.append(path) | |
| 99 | − } | |
| 91 | + if isURL(url) { return url } | |
| 92 | + if path.starts(with: "/") { return path } | |
| 93 | + return nil | |
| 100 | 94 | } |
| 101 | − input?.open(files: filesArray) | |
| 102 | − return true | |
| 103 | 95 | } |
| 104 | − return false | |
| 96 | + if files.isEmpty { return false } | |
| 97 | + input?.open(files: files) | |
| 98 | + return true | |
| 105 | 99 | } |
| 106 | 100 | |
| 107 | 101 | override func acceptsFirstMouse(for event: NSEvent?) -> Bool { |