diff --git a/NeoVimServer/NeoVimBuffer.h b/NeoVimServer/NeoVimBuffer.h index 88673f71..dfe9cce8 100644 --- a/NeoVimServer/NeoVimBuffer.h +++ b/NeoVimServer/NeoVimBuffer.h @@ -28,3 +28,11 @@ NS_ASSUME_NONNULL_BEGIN @end NS_ASSUME_NONNULL_END + +@interface NeoVimBuffer (Equality) + +- (BOOL)isEqual:(id _Nullable)other; +- (BOOL)isEqualToBuffer:(NeoVimBuffer * _Nullable)buffer; +- (NSUInteger)hash; + +@end diff --git a/NeoVimServer/NeoVimBuffer.m b/NeoVimServer/NeoVimBuffer.m index f8f92ec8..c65a2e9c 100644 --- a/NeoVimServer/NeoVimBuffer.m +++ b/NeoVimServer/NeoVimBuffer.m @@ -37,6 +37,29 @@ return self; } +- (BOOL)isEqual:(id)other { + if (other == self) + return YES; + if (!other || ![[other class] isEqual:[self class]]) + return NO; + + return [self isEqualToBuffer:other]; +} + +- (BOOL)isEqualToBuffer:(NeoVimBuffer *)buffer { + if (self == buffer) + return YES; + if (buffer == nil) + return NO; + if (self.handle != buffer.handle) + return NO; + return YES; +} + +- (NSUInteger)hash { + return (NSUInteger) self.handle; +} + - (void)encodeWithCoder:(NSCoder *)coder { [coder encodeObject:@(self.handle) forKey:@"handle"]; [coder encodeObject:self.fileName forKey:@"fileName"]; diff --git a/SwiftNeoVim/NeoVimObjectsExtensions.swift b/SwiftNeoVim/NeoVimObjectsExtensions.swift new file mode 100644 index 00000000..08bc6730 --- /dev/null +++ b/SwiftNeoVim/NeoVimObjectsExtensions.swift @@ -0,0 +1,14 @@ +/** + * Tae Won Ha - http://taewon.de - @hataewon + * See LICENSE + */ + +import Foundation + + +extension NeoVimTab { + + public func allBuffers() -> [NeoVimBuffer] { + return Array(Set(self.windows.map { $0.buffer })) + } +} diff --git a/SwiftNeoVim/NeoVimView.swift b/SwiftNeoVim/NeoVimView.swift index d6652cfb..061732f8 100644 --- a/SwiftNeoVim/NeoVimView.swift +++ b/SwiftNeoVim/NeoVimView.swift @@ -181,7 +181,8 @@ public class NeoVimView: NSView, NSUserInterfaceValidations { @IBAction public func debug1(_ sender: AnyObject!) { NSLog("DEBUG 1 - Start") - NSLog("\(self.agent.tabs())") + let buffers = self.agent.tabs().map { $0.allBuffers() }.flatMap { $0 } + NSLog("\(Set(buffers))") NSLog("DEBUG 1 - End") } } diff --git a/VimR.xcodeproj/project.pbxproj b/VimR.xcodeproj/project.pbxproj index 4bbfbe2c..95c5390b 100644 --- a/VimR.xcodeproj/project.pbxproj +++ b/VimR.xcodeproj/project.pbxproj @@ -85,6 +85,7 @@ 4B6A709C1D6507A000E12030 /* Nimble.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4B56F29B1D29926600C1F92E /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 4B6B0A781DA2A1A500212D6D /* FileOutlineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6B0A771DA2A1A500212D6D /* FileOutlineView.swift */; }; 4B854A1D1D31447C00E08DE1 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B854A1C1D31447C00E08DE1 /* main.m */; }; + 4B8AC0441DBCB3A2007CCC9B /* NeoVimObjectsExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8AC0431DBCB3A1007CCC9B /* NeoVimObjectsExtensions.swift */; }; 4B97E2CC1D33F53D00FC0660 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B97E2CE1D33F53D00FC0660 /* MainWindow.xib */; }; 4B9A15241D2993DA009F9F67 /* Nimble.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4B56F29B1D29926600C1F92E /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 4B9A15261D2993DF009F9F67 /* SwiftNeoVim.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4B2A2BF71D0351810074CE9A /* SwiftNeoVim.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -312,6 +313,7 @@ 4B6B0A771DA2A1A500212D6D /* FileOutlineView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileOutlineView.swift; sourceTree = ""; }; 4B854A1A1D31447C00E08DE1 /* NeoVimServer */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = NeoVimServer; sourceTree = BUILT_PRODUCTS_DIR; }; 4B854A1C1D31447C00E08DE1 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 4B8AC0431DBCB3A1007CCC9B /* NeoVimObjectsExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NeoVimObjectsExtensions.swift; sourceTree = ""; }; 4B97E2CD1D33F53D00FC0660 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainWindow.xib; sourceTree = ""; }; 4BAD81D41D80B5D8004F91AE /* OpenQuicklyFileViewRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenQuicklyFileViewRow.swift; sourceTree = ""; }; 4BAD84E71D7CA8FC00A79CC3 /* OpenQuicklyFilterOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenQuicklyFilterOperation.swift; sourceTree = ""; }; @@ -518,6 +520,7 @@ 4B1BB3521D16C5E500CA4FEF /* InputTestView.swift */, 4BEE79141D16D2100012EDAA /* DispatchUtils.swift */, 4BF6E29B1D34153C0053FA76 /* KeyUtils.swift */, + 4B8AC0431DBCB3A1007CCC9B /* NeoVimObjectsExtensions.swift */, ); path = SwiftNeoVim; sourceTree = ""; @@ -1008,6 +1011,7 @@ 4BDF64251D08CAB000D47E1D /* MMCoreTextView.m in Sources */, 4BDD058C1DBBC50000D1B405 /* NeoVimWindow.m in Sources */, 1929BEB90DCDAF7A2B68C886 /* ColorUtils.swift in Sources */, + 4B8AC0441DBCB3A2007CCC9B /* NeoVimObjectsExtensions.swift in Sources */, 4B4192181D0C52D700A0BEB2 /* Grid.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0;