1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-25 23:02:35 +03:00

GH-458 Fix open files by drag-n-dropping on VimR window

This commit is contained in:
Tae Won Ha 2019-03-12 10:54:00 +01:00
parent 31c49215bc
commit efbc9af8da
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44

View File

@ -7,11 +7,15 @@ import Cocoa
extension NvimView {
override public func draggingEntered(_ sender: NSDraggingInfo) -> NSDragOperation {
override public func draggingEntered(
_ sender: NSDraggingInfo
) -> NSDragOperation {
return isFile(sender: sender) ? .copy : NSDragOperation()
}
override public func draggingUpdated(_ sender: NSDraggingInfo) -> NSDragOperation {
override public func draggingUpdated(
_ sender: NSDraggingInfo
) -> NSDragOperation {
return isFile(sender: sender) ? .copy : NSDragOperation()
}
@ -20,16 +24,15 @@ extension NvimView {
return false
}
guard let paths = sender.draggingPasteboard.propertyList(
forType: NSPasteboard.PasteboardType(String(kUTTypeFileURL))
) as? [String] else {
return false
}
guard let urls = sender.draggingPasteboard
.readObjects(forClasses: [NSURL.self]) as? [URL] else { return false }
self.open(urls: paths.map { URL(fileURLWithPath: $0) })
self.open(urls: urls)
.subscribeOn(self.scheduler)
.subscribe(onError: { error in
self.eventsSubject.onNext(.apiError(msg: "\(paths) could not be opened.", cause: error))
self.eventsSubject.onNext(
.apiError(msg: "\(urls) could not be opened.", cause: error)
)
})
.disposed(by: self.disposeBag)
@ -38,5 +41,7 @@ extension NvimView {
}
private func isFile(sender: NSDraggingInfo) -> Bool {
return (sender.draggingPasteboard.types?.contains(NSPasteboard.PasteboardType(String(kUTTypeFileURL)))) ?? false
return (sender.draggingPasteboard.types?.contains(
NSPasteboard.PasteboardType(String(kUTTypeFileURL))
)) ?? false
}