mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-24 11:37:32 +03:00
Migrate nvim objects to Swift
This commit is contained in:
parent
680862f23a
commit
333eba4a6d
@ -47,12 +47,6 @@
|
||||
4B90F07B1FD30650008A39E0 /* NeoVimMsgIds.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B90F0591FD2AFF7008A39E0 /* NeoVimMsgIds.h */; settings = {ATTRIBUTES = (Private, ); }; };
|
||||
4BE45C081FD2D4E3005C0A95 /* NvimServer in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4B90F04F1FD2AFD3008A39E0 /* NvimServer */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
|
||||
4BE45C0C1FD2DA49005C0A95 /* runtime in Resources */ = {isa = PBXBuildFile; fileRef = 4BE45C0B1FD2DA49005C0A95 /* runtime */; };
|
||||
4BE45C161FD2DB53005C0A95 /* NeoVimWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BE45C101FD2DB52005C0A95 /* NeoVimWindow.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
4BE45C171FD2DB53005C0A95 /* NeoVimWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BE45C111FD2DB52005C0A95 /* NeoVimWindow.m */; };
|
||||
4BE45C181FD2DB53005C0A95 /* NeoVimTab.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BE45C121FD2DB52005C0A95 /* NeoVimTab.m */; };
|
||||
4BE45C191FD2DB53005C0A95 /* NeoVimTab.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BE45C131FD2DB52005C0A95 /* NeoVimTab.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
4BE45C1A1FD2DB53005C0A95 /* NeoVimBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BE45C141FD2DB53005C0A95 /* NeoVimBuffer.m */; };
|
||||
4BE45C1B1FD2DB53005C0A95 /* NeoVimBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BE45C151FD2DB53005C0A95 /* NeoVimBuffer.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
4BF18C5D1FD2EEE400DF95D1 /* NvimView.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BF18C5C1FD2EEE400DF95D1 /* NvimView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
@ -137,12 +131,6 @@
|
||||
4B90F0731FD2B9F1008A39E0 /* NvimMsgPack.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = NvimMsgPack.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
4B90F0771FD2BA7B008A39E0 /* Logger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Logger.h; path = NvimView/Logger.h; sourceTree = SOURCE_ROOT; };
|
||||
4BE45C0B1FD2DA49005C0A95 /* runtime */ = {isa = PBXFileReference; lastKnownFileType = folder; name = runtime; path = neovim/runtime; sourceTree = "<group>"; };
|
||||
4BE45C101FD2DB52005C0A95 /* NeoVimWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NeoVimWindow.h; sourceTree = "<group>"; };
|
||||
4BE45C111FD2DB52005C0A95 /* NeoVimWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NeoVimWindow.m; sourceTree = "<group>"; };
|
||||
4BE45C121FD2DB52005C0A95 /* NeoVimTab.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NeoVimTab.m; sourceTree = "<group>"; };
|
||||
4BE45C131FD2DB52005C0A95 /* NeoVimTab.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NeoVimTab.h; sourceTree = "<group>"; };
|
||||
4BE45C141FD2DB53005C0A95 /* NeoVimBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NeoVimBuffer.m; sourceTree = "<group>"; };
|
||||
4BE45C151FD2DB53005C0A95 /* NeoVimBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NeoVimBuffer.h; sourceTree = "<group>"; };
|
||||
4BF18C5A1FD2E72D00DF95D1 /* nvim */ = {isa = PBXFileReference; lastKnownFileType = folder; name = nvim; path = neovim/src/nvim; sourceTree = "<group>"; };
|
||||
4BF18C5B1FD2E74800DF95D1 /* auto */ = {isa = PBXFileReference; lastKnownFileType = folder; name = auto; path = neovim/build/src/nvim/auto; sourceTree = "<group>"; };
|
||||
4BF18C5C1FD2EEE400DF95D1 /* NvimView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NvimView.h; sourceTree = "<group>"; };
|
||||
@ -226,12 +214,6 @@
|
||||
4B90F0231FD2AFAD008A39E0 /* TextDrawer.h */,
|
||||
4B90F0221FD2AFAD008A39E0 /* TextDrawer.m */,
|
||||
4B90F0771FD2BA7B008A39E0 /* Logger.h */,
|
||||
4BE45C151FD2DB53005C0A95 /* NeoVimBuffer.h */,
|
||||
4BE45C141FD2DB53005C0A95 /* NeoVimBuffer.m */,
|
||||
4BE45C131FD2DB52005C0A95 /* NeoVimTab.h */,
|
||||
4BE45C121FD2DB52005C0A95 /* NeoVimTab.m */,
|
||||
4BE45C101FD2DB52005C0A95 /* NeoVimWindow.h */,
|
||||
4BE45C111FD2DB52005C0A95 /* NeoVimWindow.m */,
|
||||
1929B22A0CAD417EC3790F02 /* NvimViewObjects.swift */,
|
||||
);
|
||||
path = NvimView;
|
||||
@ -274,10 +256,7 @@
|
||||
4B90F0411FD2AFAE008A39E0 /* TextDrawer.h in Headers */,
|
||||
4B90F0371FD2AFAE008A39E0 /* NeoVimAgent.h in Headers */,
|
||||
4B90F02D1FD2AFAE008A39E0 /* NvimUiBridgeProtocol.h in Headers */,
|
||||
4BE45C161FD2DB53005C0A95 /* NeoVimWindow.h in Headers */,
|
||||
4BE45C1B1FD2DB53005C0A95 /* NeoVimBuffer.h in Headers */,
|
||||
4B2016EF1FD45EED0038528A /* NvimAutoCommandEvent.generated.h in Headers */,
|
||||
4BE45C191FD2DB53005C0A95 /* NeoVimTab.h in Headers */,
|
||||
4B90F0441FD2AFAE008A39E0 /* MMCoreTextView.h in Headers */,
|
||||
4B90F0781FD2BA7B008A39E0 /* Logger.h in Headers */,
|
||||
4B90F07B1FD30650008A39E0 /* NeoVimMsgIds.h in Headers */,
|
||||
@ -414,14 +393,12 @@
|
||||
4B90F02F1FD2AFAE008A39E0 /* NvimView+Resize.swift in Sources */,
|
||||
4B90F0341FD2AFAE008A39E0 /* CocoaExtensions.swift in Sources */,
|
||||
4B90F0461FD2AFAE008A39E0 /* Grid.swift in Sources */,
|
||||
4BE45C171FD2DB53005C0A95 /* NeoVimWindow.m in Sources */,
|
||||
4B90F0421FD2AFAE008A39E0 /* NvimView+UiBridge.swift in Sources */,
|
||||
4B90F0401FD2AFAE008A39E0 /* TextDrawer.m in Sources */,
|
||||
4B90F02E1FD2AFAE008A39E0 /* NvimView.swift in Sources */,
|
||||
4B90F03C1FD2AFAE008A39E0 /* NvimView+TouchBar.swift in Sources */,
|
||||
4B2016EE1FD45EED0038528A /* NvimAutoCommandEvent.generated.m in Sources */,
|
||||
4B90F03B1FD2AFAE008A39E0 /* NvimObjectsExtensions.swift in Sources */,
|
||||
4BE45C1A1FD2DB53005C0A95 /* NeoVimBuffer.m in Sources */,
|
||||
4B90F04A1FD2AFAE008A39E0 /* NeoVimAgent.m in Sources */,
|
||||
4B90F0351FD2AFAE008A39E0 /* NvimView+Mouse.swift in Sources */,
|
||||
4B90F0431FD2AFAE008A39E0 /* NvimView+MenuItems.swift in Sources */,
|
||||
@ -432,7 +409,6 @@
|
||||
4B90F0301FD2AFAE008A39E0 /* KeyUtils.swift in Sources */,
|
||||
4B90F03A1FD2AFAE008A39E0 /* NvimView+Key.swift in Sources */,
|
||||
4B90F0361FD2AFAE008A39E0 /* NvimViewDelegate.swift in Sources */,
|
||||
4BE45C181FD2DB53005C0A95 /* NeoVimTab.m in Sources */,
|
||||
1929B40A751BDA2882D4FC94 /* NvimViewObjects.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
@ -1,47 +0,0 @@
|
||||
/**
|
||||
* Tae Won Ha - http://taewon.de - @hataewon
|
||||
* See LICENSE
|
||||
*/
|
||||
|
||||
@import Foundation;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface NeoVimBuffer : NSObject <NSCoding>
|
||||
|
||||
@property (nonatomic, readonly) NSInteger handle;
|
||||
@property (nonatomic, readonly, nullable) NSURL *url;
|
||||
/**
|
||||
* Only the file name
|
||||
*/
|
||||
@property (nonatomic, readonly, nullable) NSString *name;
|
||||
@property (nonatomic, readonly) bool isReadOnly;
|
||||
@property (nonatomic, readonly) bool isDirty;
|
||||
@property (nonatomic, readonly) bool isCurrent;
|
||||
@property (nonatomic, readonly) bool isTransient;
|
||||
|
||||
- (instancetype)initWithHandle:(NSInteger)handle
|
||||
unescapedPath:(NSString *_Nullable)unescapedPath
|
||||
dirty:(bool)dirty
|
||||
readOnly:(bool)readOnly
|
||||
current:(bool)current;
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder;
|
||||
- (void)encodeWithCoder:(NSCoder *)coder;
|
||||
|
||||
- (NSString *)description;
|
||||
- (BOOL)isEqual:(id _Nullable)other;
|
||||
- (BOOL)isEqualToBuffer:(NeoVimBuffer *)buffer;
|
||||
- (NSUInteger)hash;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@interface NeoVimBuffer (Equality)
|
||||
|
||||
- (BOOL)isEqual:(id _Nullable)other;
|
||||
- (BOOL)isEqualToBuffer:(NeoVimBuffer * _Nullable)buffer;
|
||||
- (NSUInteger)hash;
|
||||
|
||||
@end
|
@ -1,110 +0,0 @@
|
||||
/**
|
||||
* Tae Won Ha - http://taewon.de - @hataewon
|
||||
* See LICENSE
|
||||
*/
|
||||
|
||||
#import "NeoVimBuffer.h"
|
||||
|
||||
@implementation NeoVimBuffer
|
||||
|
||||
- (instancetype)initWithHandle:(NSInteger)handle
|
||||
unescapedPath:(NSString *_Nullable)unescapedPath
|
||||
dirty:(bool)dirty
|
||||
readOnly:(bool)readOnly
|
||||
current:(bool)current
|
||||
{
|
||||
self = [super init];
|
||||
if (self == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
_handle = handle;
|
||||
_url = unescapedPath == nil ? nil : [NSURL fileURLWithPath:unescapedPath];
|
||||
_isDirty = dirty;
|
||||
_isReadOnly = readOnly;
|
||||
_isCurrent = current;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
NSNumber *objHandle = [coder decodeObjectForKey:@"handle"];
|
||||
_handle = objHandle.integerValue;
|
||||
_url = [coder decodeObjectForKey:@"url"];
|
||||
_isDirty = [coder decodeBoolForKey:@"dirty"];
|
||||
_isReadOnly = [coder decodeBoolForKey:@"readOnly"];
|
||||
_isCurrent = [coder decodeBoolForKey:@"current"];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder {
|
||||
[coder encodeObject:@(self.handle) forKey:@"handle"];
|
||||
[coder encodeObject:self.url forKey:@"url"];
|
||||
[coder encodeBool:self.isDirty forKey:@"dirty"];
|
||||
[coder encodeBool:self.isReadOnly forKey:@"readOnly"];
|
||||
[coder encodeBool:self.isCurrent forKey:@"current"];
|
||||
}
|
||||
|
||||
- (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;
|
||||
if (self.url != buffer.url && ![self.url isEqual:buffer.url])
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSUInteger)hash {
|
||||
NSUInteger hash = (NSUInteger) self.handle;
|
||||
hash = hash * 31u + [self.url hash];
|
||||
return hash;
|
||||
}
|
||||
|
||||
- (NSString *)description {
|
||||
NSMutableString *description = [NSMutableString stringWithFormat:@"<%@: ", NSStringFromClass([self class])];
|
||||
[description appendFormat:@"self.handle=%li", self.handle];
|
||||
[description appendFormat:@", self.url=%@", self.url];
|
||||
[description appendFormat:@", self.dirty=%d", self.isDirty];
|
||||
[description appendFormat:@", self.readOnly=%d", self.isReadOnly];
|
||||
[description appendFormat:@", self.current=%d", self.isCurrent];
|
||||
[description appendString:@">"];
|
||||
return description;
|
||||
}
|
||||
|
||||
- (NSString *)name {
|
||||
if (self.url == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
return self.url.lastPathComponent;
|
||||
}
|
||||
|
||||
- (bool)isTransient {
|
||||
if (self.isDirty) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (self.url != nil) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
@ -1,29 +0,0 @@
|
||||
/**
|
||||
* Tae Won Ha - http://taewon.de - @hataewon
|
||||
* See LICENSE
|
||||
*/
|
||||
|
||||
@import Foundation;
|
||||
|
||||
|
||||
@class NeoVimWindow;
|
||||
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface NeoVimTab : NSObject <NSCoding>
|
||||
|
||||
@property (nonatomic, readonly) NSInteger handle;
|
||||
@property (nonatomic, readonly) NSArray <NeoVimWindow *> *windows;
|
||||
@property (nonatomic, readonly) bool isCurrent;
|
||||
|
||||
- (instancetype)initWithHandle:(NSInteger)handle windows:(NSArray <NeoVimWindow *> *)windows current:(bool)current;
|
||||
|
||||
/// @returns The most recently selected window in *this* tab.
|
||||
- (NeoVimWindow * _Nullable )currentWindow;
|
||||
|
||||
- (NSString *)description;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -1,57 +0,0 @@
|
||||
/**
|
||||
* Tae Won Ha - http://taewon.de - @hataewon
|
||||
* See LICENSE
|
||||
*/
|
||||
|
||||
#import "NeoVimTab.h"
|
||||
#import "NeoVimWindow.h"
|
||||
|
||||
|
||||
@implementation NeoVimTab
|
||||
|
||||
- (instancetype)initWithHandle:(NSInteger)handle windows:(NSArray <NeoVimWindow *> *)windows current:(bool)current {
|
||||
self = [super init];
|
||||
if (self == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
_handle = handle;
|
||||
_windows = windows;
|
||||
_isCurrent = current;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NeoVimWindow *)currentWindow {
|
||||
for (NeoVimWindow *window in self.windows) if (window.isCurrentInTab) return window;
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSString *)description {
|
||||
NSMutableString *description = [NSMutableString stringWithFormat:@"<%@: ", NSStringFromClass([self class])];
|
||||
[description appendFormat:@"self.handle=%li", self.handle];
|
||||
[description appendFormat:@", self.windows=%@", self.windows];
|
||||
[description appendFormat:@", self.current=%d", self.isCurrent];
|
||||
[description appendString:@">"];
|
||||
return description;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder {
|
||||
[coder encodeObject:@(self.handle) forKey:@"handle"];
|
||||
[coder encodeObject:self.windows forKey:@"windows"];
|
||||
[coder encodeBool:self.isCurrent forKey:@"current"];
|
||||
}
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
NSNumber *objHandle = [coder decodeObjectForKey:@"handle"];
|
||||
_handle = objHandle.integerValue;
|
||||
_windows = [coder decodeObjectForKey:@"windows"];
|
||||
_isCurrent = [coder decodeBoolForKey:@"current"];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
@ -1,29 +0,0 @@
|
||||
/**
|
||||
* Tae Won Ha - http://taewon.de - @hataewon
|
||||
* See LICENSE
|
||||
*/
|
||||
|
||||
@import Foundation;
|
||||
|
||||
|
||||
@class NeoVimBuffer;
|
||||
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface NeoVimWindow : NSObject <NSCoding>
|
||||
|
||||
@property (nonatomic, readonly) NSInteger handle;
|
||||
@property (nonatomic, readonly) NeoVimBuffer *buffer;
|
||||
@property (nonatomic, readonly) bool isCurrentInTab;
|
||||
|
||||
- (instancetype)initWithHandle:(NSInteger)handle buffer:(NeoVimBuffer *)buffer currentInTab:(bool)current;
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder;
|
||||
- (void)encodeWithCoder:(NSCoder *)coder;
|
||||
|
||||
- (NSString *)description;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -1,52 +0,0 @@
|
||||
//
|
||||
// Created by Tae Won Ha on 22/10/16.
|
||||
// Copyright (c) 2016 Tae Won Ha. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NeoVimWindow.h"
|
||||
#import "NeoVimBuffer.h"
|
||||
|
||||
|
||||
@implementation NeoVimWindow
|
||||
|
||||
- (instancetype)initWithHandle:(NSInteger)handle buffer:(NeoVimBuffer *)buffer currentInTab:(bool)current {
|
||||
self = [super init];
|
||||
if (self == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
_handle = handle;
|
||||
_buffer = buffer;
|
||||
_isCurrentInTab = current;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *)description {
|
||||
NSMutableString *description = [NSMutableString stringWithFormat:@"<%@: ", NSStringFromClass([self class])];
|
||||
[description appendFormat:@"self.handle=%li", self.handle];
|
||||
[description appendFormat:@", self.buffer=%@", self.buffer];
|
||||
[description appendFormat:@", self.currentInTab=%d", self.isCurrentInTab];
|
||||
[description appendString:@">"];
|
||||
return description;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder {
|
||||
[coder encodeObject:@(self.handle) forKey:@"handle"];
|
||||
[coder encodeObject:self.buffer forKey:@"buffer"];
|
||||
[coder encodeBool:self.isCurrentInTab forKey:@"currentInTab"];
|
||||
}
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
NSNumber *objHandle = [coder decodeObjectForKey:@"handle"];
|
||||
_handle = objHandle.integerValue;
|
||||
_buffer = [coder decodeObjectForKey:@"buffer"];
|
||||
_isCurrentInTab = [coder decodeBoolForKey:@"currentInTab"];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
@ -6,13 +6,6 @@
|
||||
import Foundation
|
||||
|
||||
|
||||
extension NeoVimTab {
|
||||
|
||||
public func allBuffers() -> [NeoVimBuffer] {
|
||||
return Array(Set(self.windows.map { $0.buffer }))
|
||||
}
|
||||
}
|
||||
|
||||
extension Position {
|
||||
|
||||
public static let beginning = Position(row: 1, column: 1)
|
||||
|
@ -22,7 +22,7 @@ extension NvimView {
|
||||
/**
|
||||
- returns: nil when for exampls a quickfix panel is open.
|
||||
*/
|
||||
public func currentBuffer() -> NeoVimBuffer? {
|
||||
public func currentBuffer() -> NvimView.Buffer? {
|
||||
guard let buf = self.nvim.getCurrentBuf().value else {
|
||||
return nil
|
||||
}
|
||||
@ -30,7 +30,7 @@ extension NvimView {
|
||||
return self.neoVimBuffer(for: buf, currentBuffer: buf)
|
||||
}
|
||||
|
||||
public func allBuffers() -> [NeoVimBuffer] {
|
||||
public func allBuffers() -> [NvimView.Buffer] {
|
||||
let curBuf = self.nvim.getCurrentBuf().value
|
||||
return self.nvim.listBufs()
|
||||
.value?
|
||||
@ -41,7 +41,7 @@ extension NvimView {
|
||||
return self.currentBuffer()?.isDirty ?? false
|
||||
}
|
||||
|
||||
public func allTabs() -> [NeoVimTab] {
|
||||
public func allTabs() -> [NvimView.Tabpage] {
|
||||
let curBuf = self.nvim.getCurrentBuf().value
|
||||
let curTab = self.nvim.getCurrentTabpage().value
|
||||
|
||||
@ -93,7 +93,7 @@ extension NvimView {
|
||||
urls.forEach { self.open($0, cmd: "vsp") }
|
||||
}
|
||||
|
||||
public func select(buffer: NeoVimBuffer) {
|
||||
public func select(buffer: NvimView.Buffer) {
|
||||
for window in self.allTabs().map({ $0.windows }).flatMap({ $0 }) {
|
||||
if window.buffer.handle == buffer.handle {
|
||||
self.nvim.setCurrentWin(window: NvimApi.Window(window.handle), expectsReturnValue: false)
|
||||
@ -188,7 +188,7 @@ extension NvimView {
|
||||
self.exec(command: "\(cmd) \(escapedFileName)")
|
||||
}
|
||||
|
||||
private func neoVimBuffer(for buf: NvimApi.Buffer, currentBuffer: NvimApi.Buffer?) -> NeoVimBuffer? {
|
||||
private func neoVimBuffer(for buf: NvimApi.Buffer, currentBuffer: NvimApi.Buffer?) -> NvimView.Buffer? {
|
||||
guard let path = self.nvim.bufGetName(buffer: buf).value else {
|
||||
return nil
|
||||
}
|
||||
@ -204,12 +204,16 @@ extension NvimView {
|
||||
let readonly = buftype != ""
|
||||
let current = buf == currentBuffer
|
||||
|
||||
return NeoVimBuffer(handle: buf.handle, unescapedPath: path, dirty: dirty, readOnly: readonly, current: current)
|
||||
return NvimView.Buffer(apiBuffer: buf,
|
||||
url: URL(fileURLWithPath: path),
|
||||
isReadOnly: readonly,
|
||||
isDirty: dirty,
|
||||
isCurrent: current)
|
||||
}
|
||||
|
||||
private func neoVimWindow(for window: NvimApi.Window,
|
||||
currentWindow: NvimApi.Window?,
|
||||
currentBuffer: NvimApi.Buffer?) -> NeoVimWindow? {
|
||||
currentBuffer: NvimApi.Buffer?) -> NvimView.Window? {
|
||||
|
||||
guard let buf = self.nvim.winGetBuf(window: window).value else {
|
||||
return nil
|
||||
@ -219,16 +223,16 @@ extension NvimView {
|
||||
return nil
|
||||
}
|
||||
|
||||
return NeoVimWindow(handle: window.handle, buffer: buffer, currentInTab: window == currentWindow)
|
||||
return NvimView.Window(apiWindow: window, buffer: buffer, isCurrentInTab: window == currentWindow)
|
||||
}
|
||||
|
||||
private func neoVimTab(for tabpage: NvimApi.Tabpage,
|
||||
currentTabpage: NvimApi.Tabpage?,
|
||||
currentBuffer: NvimApi.Buffer?) -> NeoVimTab? {
|
||||
currentBuffer: NvimApi.Buffer?) -> NvimView.Tabpage? {
|
||||
|
||||
let curWinInTab = self.nvim.tabpageGetWin(tabpage: tabpage).value
|
||||
|
||||
let windows: [NeoVimWindow] = self.nvim.tabpageListWins(tabpage: tabpage)
|
||||
let windows: [NvimView.Window] = self.nvim.tabpageListWins(tabpage: tabpage)
|
||||
.value?
|
||||
.flatMap {
|
||||
self.neoVimWindow(for: $0,
|
||||
@ -236,7 +240,7 @@ extension NvimView {
|
||||
currentBuffer: currentBuffer)
|
||||
} ?? []
|
||||
|
||||
return NeoVimTab(handle: tabpage.handle, windows: windows, current: tabpage == currentTabpage)
|
||||
return NvimView.Tabpage(apiTabpage: tabpage, windows: windows, isCurrent: tabpage == currentTabpage)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ extension NvimView: NSTouchBarDelegate, NSScrubberDataSource, NSScrubberDelegate
|
||||
let itemView = scrubber.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: type(of: self).touchBarTabSwitcherItem), owner: nil) as! NSScrubberTextItemView
|
||||
guard tabsCache.count > index else { return itemView }
|
||||
let tab = tabsCache[index]
|
||||
itemView.title = tab.currentWindow()?.buffer.name ?? "[No Name]"
|
||||
itemView.title = tab.currentWindow?.buffer.name ?? "[No Name]"
|
||||
|
||||
return itemView
|
||||
}
|
||||
@ -86,7 +86,7 @@ extension NvimView: NSTouchBarDelegate, NSScrubberDataSource, NSScrubberDelegate
|
||||
return
|
||||
}
|
||||
|
||||
let window = tab.currentWindow() ?? tab.windows[0]
|
||||
let window = tab.currentWindow ?? tab.windows[0]
|
||||
self.nvim.setCurrentWin(window: NvimApi.Window(window.handle), expectsReturnValue: false)
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,4 @@ FOUNDATION_EXPORT const unsigned char NvimViewVersionString[];
|
||||
// TODO: this header should not be public, but we cannot use a bridging header in a framework.
|
||||
#import <NvimView/TextDrawer.h>
|
||||
#import <NvimView/NeoVimAgent.h>
|
||||
#import <NvimView/NeoVimBuffer.h>
|
||||
#import <NvimView/NeoVimTab.h>
|
||||
#import <NvimView/NeoVimWindow.h>
|
||||
#import <NvimView/NvimAutoCommandEvent.generated.h>
|
||||
|
@ -246,7 +246,7 @@ public class NvimView: NSView,
|
||||
var isInitialResize = true
|
||||
|
||||
// cache the tabs for Touch Bar use
|
||||
var tabsCache = [NeoVimTab]()
|
||||
var tabsCache = [NvimView.Tabpage]()
|
||||
|
||||
// MARK: - Private
|
||||
fileprivate var _linespacing = NvimView.defaultLinespacing
|
||||
|
@ -15,7 +15,7 @@ public protocol NvimViewDelegate: class {
|
||||
func bufferListChanged()
|
||||
func tabChanged()
|
||||
/// Called when the current buffer changes, including when a new one is selected.
|
||||
func currentBufferChanged(_ currentBuffer: NeoVimBuffer)
|
||||
func currentBufferChanged(_ currentBuffer: NvimView.Buffer)
|
||||
|
||||
func colorschemeChanged(to: NvimView.Theme)
|
||||
|
||||
|
@ -6,12 +6,65 @@
|
||||
import Foundation
|
||||
import NvimMsgPack
|
||||
|
||||
public struct NvimBuffer {
|
||||
extension NvimView {
|
||||
|
||||
public let apiBuffer: NvimApi.Buffer
|
||||
public let url: URL
|
||||
public struct Buffer: Equatable {
|
||||
|
||||
public let isDirty: Bool
|
||||
public let isCurrent: Bool
|
||||
public let isTransient: Bool
|
||||
public static func ==(lhs: Buffer, rhs: Buffer) -> Bool {
|
||||
return lhs.handle == rhs.handle
|
||||
}
|
||||
|
||||
public let apiBuffer: NvimApi.Buffer
|
||||
public let url: URL?
|
||||
|
||||
public let isReadOnly: Bool
|
||||
public let isDirty: Bool
|
||||
public let isCurrent: Bool
|
||||
|
||||
public var isTransient: Bool {
|
||||
if self.isDirty {
|
||||
return false
|
||||
}
|
||||
|
||||
if self.url != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
public var name: String? {
|
||||
return self.url?.lastPathComponent
|
||||
}
|
||||
|
||||
public var handle: Int {
|
||||
return self.apiBuffer.handle
|
||||
}
|
||||
}
|
||||
|
||||
public struct Window {
|
||||
|
||||
public let apiWindow: NvimApi.Window
|
||||
public let buffer: Buffer
|
||||
public let isCurrentInTab: Bool
|
||||
|
||||
public var handle: Int {
|
||||
return self.apiWindow.handle
|
||||
}
|
||||
}
|
||||
|
||||
public struct Tabpage {
|
||||
|
||||
public let apiTabpage: NvimApi.Tabpage
|
||||
public let windows: [Window]
|
||||
public let isCurrent: Bool
|
||||
|
||||
public var currentWindow: Window? {
|
||||
return self.windows.first { $0.isCurrentInTab }
|
||||
}
|
||||
|
||||
public var handle: Int {
|
||||
return self.apiTabpage.handle
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ extension MainWindow {
|
||||
self.emit(self.uuidAction(for: .setBufferList(buffers)))
|
||||
}
|
||||
|
||||
func currentBufferChanged(_ currentBuffer: NeoVimBuffer) {
|
||||
func currentBufferChanged(_ currentBuffer: NvimView.Buffer) {
|
||||
self.emit(self.uuidAction(for: .setCurrentBuffer(currentBuffer)))
|
||||
}
|
||||
|
||||
|
@ -20,9 +20,9 @@ class MainWindow: NSObject,
|
||||
enum Action {
|
||||
|
||||
case cd(to: URL)
|
||||
case setBufferList([NeoVimBuffer])
|
||||
case setBufferList([NvimView.Buffer])
|
||||
|
||||
case setCurrentBuffer(NeoVimBuffer)
|
||||
case setCurrentBuffer(NvimView.Buffer)
|
||||
case setDirtyStatus(Bool)
|
||||
|
||||
case becomeKey(isFullScreen: Bool)
|
||||
@ -316,7 +316,7 @@ class MainWindow: NSObject,
|
||||
|
||||
fileprivate let disposeBag = DisposeBag()
|
||||
|
||||
fileprivate var currentBuffer: NeoVimBuffer?
|
||||
fileprivate var currentBuffer: NvimView.Buffer?
|
||||
|
||||
fileprivate var defaultFont = NvimView.defaultFont
|
||||
fileprivate var linespacing = NvimView.defaultLinespacing
|
||||
|
@ -18,7 +18,7 @@ class BuffersList: NSView,
|
||||
|
||||
enum Action {
|
||||
|
||||
case open(NeoVimBuffer)
|
||||
case open(NvimView.Buffer)
|
||||
}
|
||||
|
||||
fileprivate(set) var theme = Theme.default
|
||||
@ -78,7 +78,7 @@ class BuffersList: NSView,
|
||||
fileprivate let bufferList = NSTableView.standardTableView()
|
||||
fileprivate let genericIcon: NSImage
|
||||
|
||||
fileprivate var buffers = [NeoVimBuffer]()
|
||||
fileprivate var buffers = [NvimView.Buffer]()
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
@ -157,7 +157,7 @@ extension BuffersList {
|
||||
return cell
|
||||
}
|
||||
|
||||
fileprivate func text(for buffer: NeoVimBuffer) -> NSAttributedString {
|
||||
fileprivate func text(for buffer: NvimView.Buffer) -> NSAttributedString {
|
||||
guard let name = buffer.name else {
|
||||
return NSAttributedString(string: "No Name")
|
||||
}
|
||||
@ -180,7 +180,7 @@ extension BuffersList {
|
||||
return rowText
|
||||
}
|
||||
|
||||
fileprivate func icon(for buffer: NeoVimBuffer) -> NSImage? {
|
||||
fileprivate func icon(for buffer: NvimView.Buffer) -> NSImage? {
|
||||
if let url = buffer.url {
|
||||
return FileUtils.icon(forUrl: url)
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class PreviewUtils {
|
||||
}
|
||||
}
|
||||
|
||||
static func state(for uuid: String, baseUrl: URL, buffer: NeoVimBuffer?) -> PreviewState {
|
||||
static func state(for uuid: String, baseUrl: URL, buffer: NvimView.Buffer?) -> PreviewState {
|
||||
guard let url = buffer?.url else {
|
||||
return self.state(for: .notSaved, baseUrl: baseUrl)
|
||||
}
|
||||
|
@ -234,8 +234,8 @@ extension MainWindow {
|
||||
|
||||
// neovim
|
||||
var uuid = UUID().uuidString
|
||||
var currentBuffer: NeoVimBuffer?
|
||||
var buffers = [NeoVimBuffer]()
|
||||
var currentBuffer: NvimView.Buffer?
|
||||
var buffers = [NvimView.Buffer]()
|
||||
var cwd = FileUtils.userHomeUrl
|
||||
|
||||
var isDirty = false
|
||||
@ -247,7 +247,7 @@ extension MainWindow {
|
||||
|
||||
// to be cleaned
|
||||
var urlsToOpen = [URL: OpenMode]()
|
||||
var currentBufferToSet: NeoVimBuffer?
|
||||
var currentBufferToSet: NvimView.Buffer?
|
||||
var cwdToSet: URL?
|
||||
var viewToBeFocused: FocusableView? = FocusableView.neoVimView
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user