From 2dde944a46f0ec07174bdf329fb1288090d147d9 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Thu, 24 Nov 2016 00:48:49 +0100 Subject: [PATCH] GH-297 Handle also paths with spaces --- NeoVimServer/NeoVimBuffer.h | 3 ++- NeoVimServer/NeoVimBuffer.m | 11 +++++++++++ VimR/BufferListComponent.swift | 5 +++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/NeoVimServer/NeoVimBuffer.h b/NeoVimServer/NeoVimBuffer.h index 444f7c16..2adfc38b 100644 --- a/NeoVimServer/NeoVimBuffer.h +++ b/NeoVimServer/NeoVimBuffer.h @@ -11,13 +11,14 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) NSInteger handle; /** - * Full path + * Full path without escaping, e.g. /some/path with spaces/file.txt */ @property (nonatomic, retain, nullable) NSString *fileName; /** * 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; diff --git a/NeoVimServer/NeoVimBuffer.m b/NeoVimServer/NeoVimBuffer.m index f4712d8a..3a06eb72 100644 --- a/NeoVimServer/NeoVimBuffer.m +++ b/NeoVimServer/NeoVimBuffer.m @@ -90,6 +90,17 @@ return self.fileName.lastPathComponent; } +- (NSURL *)url { + if (self.fileName == nil) { + return nil; + } + + NSString *percentageEscaped = [self.fileName stringByAddingPercentEncodingWithAllowedCharacters: + [NSCharacterSet URLQueryAllowedCharacterSet] + ]; + return [[NSURL alloc] initWithString:percentageEscaped]; +} + - (bool)isTransient { if (self.isDirty) { return NO; diff --git a/VimR/BufferListComponent.swift b/VimR/BufferListComponent.swift index 210e20c9..b083bb8f 100644 --- a/VimR/BufferListComponent.swift +++ b/VimR/BufferListComponent.swift @@ -112,11 +112,12 @@ extension BufferListComponent { } fileprivate func text(for buffer: NeoVimBuffer) -> NSAttributedString { - guard let name = buffer.name, let fileName = buffer.fileName else { + guard let name = buffer.name else { return NSAttributedString(string: "No Name") } - guard let url = URL(string: fileName) else { + guard let url = buffer.url else { + NSLog("WARN No URL for \(buffer.fileName)") return NSAttributedString(string: name) }