1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-24 03:25:03 +03:00

GH-297 Use url instead of unescaped path in neovim buffer

This commit is contained in:
Tae Won Ha 2016-11-24 19:46:25 +01:00
parent 2dde944a46
commit af718bc3e5
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
6 changed files with 37 additions and 61 deletions

View File

@ -10,22 +10,18 @@ NS_ASSUME_NONNULL_BEGIN
@interface NeoVimBuffer : NSObject <NSCoding>
@property (nonatomic, readonly) NSInteger handle;
/**
* Full path without escaping, e.g. /some/path with spaces/file.txt
*/
@property (nonatomic, retain, nullable) NSString *fileName;
@property (nonatomic, readonly, nullable) NSURL *url;
/**
* Only the file name
*/
@property (nonatomic, readonly, nullable) NSString *name;
@property (nonatomic, readonly, nullable) NSURL *url;
@property (nonatomic, readonly) bool isReadOnly;
@property (nonatomic, readonly) bool isDirty;
@property (nonatomic, readonly) bool isCurrent;
@property (nonatomic, readonly) bool isTransient;
- (instancetype)initWithHandle:(NSInteger)handle
fileName:(NSString * _Nullable)fileName
unescapedPath:(NSString *_Nullable)unescapedPath
dirty:(bool)dirty
readOnly:(bool)readOnly
current:(bool)current;

View File

@ -8,17 +8,18 @@
@implementation NeoVimBuffer
- (instancetype)initWithHandle:(NSInteger)handle
fileName:(NSString *)fileName
unescapedPath:(NSString *_Nullable)unescapedPath
dirty:(bool)dirty
readOnly:(bool)readOnly
current:(bool)current {
current:(bool)current
{
self = [super init];
if (self == nil) {
return nil;
}
_handle = handle;
_fileName = fileName;
_url = unescapedPath == nil ? nil : [NSURL fileURLWithPath:unescapedPath];
_isDirty = dirty;
_isReadOnly = readOnly;
_isCurrent = current;
@ -31,7 +32,7 @@
if (self) {
NSNumber *objHandle = [coder decodeObjectForKey:@"handle"];
_handle = objHandle.integerValue;
_fileName = [coder decodeObjectForKey:@"fileName"];
_url = [coder decodeObjectForKey:@"url"];
_isDirty = [coder decodeBoolForKey:@"dirty"];
_isReadOnly = [coder decodeBoolForKey:@"readOnly"];
_isCurrent = [coder decodeBoolForKey:@"current"];
@ -40,6 +41,14 @@
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;
@ -63,18 +72,10 @@
return (NSUInteger) self.handle;
}
- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeObject:@(self.handle) forKey:@"handle"];
[coder encodeObject:self.fileName forKey:@"fileName"];
[coder encodeBool:self.isDirty forKey:@"dirty"];
[coder encodeBool:self.isReadOnly forKey:@"readOnly"];
[coder encodeBool:self.isCurrent forKey:@"current"];
}
- (NSString *)description {
NSMutableString *description = [NSMutableString stringWithFormat:@"<%@: ", NSStringFromClass([self class])];
[description appendFormat:@"self.handle=%li", self.handle];
[description appendFormat:@", self.fileName=%@", self.fileName];
[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];
@ -83,22 +84,11 @@
}
- (NSString *)name {
if (self.fileName == nil) {
if (self.url == nil) {
return nil;
}
return self.fileName.lastPathComponent;
}
- (NSURL *)url {
if (self.fileName == nil) {
return nil;
}
NSString *percentageEscaped = [self.fileName stringByAddingPercentEncodingWithAllowedCharacters:
[NSCharacterSet URLQueryAllowedCharacterSet]
];
return [[NSURL alloc] initWithString:percentageEscaped];
return self.url.lastPathComponent;
}
- (bool)isTransient {
@ -106,7 +96,7 @@
return NO;
}
if (self.fileName != nil) {
if (self.url != nil) {
return NO;
}

View File

@ -760,7 +760,7 @@ static NeoVimBuffer *buffer_for(buf_T *buf) {
bool current = curbuf == buf;
NeoVimBuffer *buffer = [[NeoVimBuffer alloc] initWithHandle:buf->handle
fileName:fileName
unescapedPath:fileName
dirty:buf->b_changed
readOnly:buf->b_p_ro
current:current];

View File

@ -263,24 +263,21 @@ extension NeoVimView {
let currentBufferIsTransient = buffers.filter { $0.isCurrent }.first?.isTransient ?? false
urls.enumerated().forEach { (idx, url) in
let path = url.path
if buffers.filter({ $0.fileName == path }).first != nil {
for window in tabs.map({ $0.windows }).flatMap({ $0 }) {
if buffers.filter({ $0.url == url }).first != nil {
for window in tabs.map({ $0.windows }).flatMap({ $0 }) {
if window.buffer.url == url {
self.agent.select(window)
return
}
}
}
if window.buffer.fileName == path {
Swift.print(window)
self.agent.select(window)
return
if currentBufferIsTransient {
self.open(url, cmd: "e")
} else {
self.open(url, cmd: "tabe")
}
}
}
if idx == 0 && currentBufferIsTransient {
self.open(url, cmd: "e")
} else {
self.open(url, cmd: "tabe")
}
}
}
public func openInNewTab(urls: [URL]) {

View File

@ -117,7 +117,6 @@ extension BufferListComponent {
}
guard let url = buffer.url else {
NSLog("WARN No URL for \(buffer.fileName)")
return NSAttributedString(string: name)
}
@ -131,16 +130,10 @@ extension BufferListComponent {
}
fileprivate func icon(for buffer: NeoVimBuffer) -> NSImage? {
if let fileName = buffer.fileName {
if let url = URL(string: fileName) {
return self.fileItemService.icon(forUrl: url)
} else {
return self.genericIcon
}
} else {
return self.genericIcon
if let url = buffer.url {
return self.fileItemService.icon(forUrl: url)
}
return self.genericIcon
}
}

View File

@ -339,7 +339,7 @@ extension MainWindowComponent {
return
}
if curBuf.fileName == nil {
if curBuf.url == nil {
self.savePanelSheet { self.neoVimView.saveCurrentTab(url: $0) }
return
}