diff --git a/osdep/mac/swift_extensions.swift b/osdep/mac/swift_extensions.swift index 954730578d..672c095760 100644 --- a/osdep/mac/swift_extensions.swift +++ b/osdep/mac/swift_extensions.swift @@ -52,6 +52,19 @@ extension NSEvent.ModifierFlags { public static let optionRight: NSEvent.ModifierFlags = .init(rawValue: UInt(NX_DEVICERALTKEYMASK)) } +extension String { + func isUrl() -> Bool { + guard let regex = try? NSRegularExpression(pattern: "^(https?|ftp)://[^\\s/$.?#].[^\\s]*$", + options: .caseInsensitive) else { + return false + } + let isUrl = regex.numberOfMatches(in: self, + options: [], + range: NSRange(location: 0, length: self.count)) + return isUrl > 0 + } +} + extension mp_keymap { init(_ f: Int, _ t: Int32) { self.init(from: Int32(f), to: t) diff --git a/video/out/mac/view.swift b/video/out/mac/view.swift index f303c84c06..8c9c006f94 100644 --- a/video/out/mac/view.swift +++ b/video/out/mac/view.swift @@ -65,17 +65,6 @@ class View: NSView, CALayerDelegate { return [] } - func isURL(_ str: String) -> Bool { - guard let regex = try? NSRegularExpression(pattern: "^(https?|ftp)://[^\\s/$.?#].[^\\s]*$", - options: .caseInsensitive) else { - return false - } - let isURL = regex.numberOfMatches(in: str, - options: [], - range: NSRange(location: 0, length: str.count)) - return isURL > 0 - } - override func performDragOperation(_ sender: NSDraggingInfo) -> Bool { let pb = sender.draggingPasteboard guard let types = pb.types else { return false } @@ -89,7 +78,7 @@ class View: NSView, CALayerDelegate { files = str.components(separatedBy: "\n").compactMap { let url = $0.trimmingCharacters(in: .whitespacesAndNewlines) let path = (url as NSString).expandingTildeInPath - if isURL(url) { return url } + if url.isUrl() { return url } if path.starts(with: "/") { return path } return nil }