1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-28 02:54:31 +03:00

GH-423 Cache cwd and send the change event as a callback

This commit is contained in:
Tae Won Ha 2017-06-09 01:15:45 +02:00
parent 4547ed8c7f
commit 91fac3868e
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
7 changed files with 50 additions and 14 deletions

View File

@ -36,6 +36,7 @@ typedef NS_ENUM(NSUInteger, NeoVimServerMsgId) {
NeoVimServerMsgIdStop, NeoVimServerMsgIdStop,
NeoVimServerMsgIdDirtyStatusChanged, NeoVimServerMsgIdDirtyStatusChanged,
NeoVimServerMsgIdCwdChanged,
NeoVimServerMsgIdAutoCommandEvent, NeoVimServerMsgIdAutoCommandEvent,
#ifdef DEBUG #ifdef DEBUG

View File

@ -128,6 +128,20 @@ static void send_dirty_status() {
[data release]; [data release];
} }
static void send_cwd() {
char_u *temp = xmalloc(MAXPATHL);
if (os_dirname(temp, MAXPATHL) == FAIL) {
xfree(temp);
[_neovim_server sendMessageWithId:NeoVimServerMsgIdCwdChanged];
}
NSString *pwd = [NSString stringWithCString:(const char *) temp encoding:NSUTF8StringEncoding];
xfree(temp);
NSData *resultData = [pwd dataUsingEncoding:NSUTF8StringEncoding];
[_neovim_server sendMessageWithId:NeoVimServerMsgIdCwdChanged data:resultData];
}
static void insert_marked_text(NSString *markedText) { static void insert_marked_text(NSString *markedText) {
_marked_text = [markedText retain]; // release when the final text is input in -vimInput _marked_text = [markedText retain]; // release when the final text is input in -vimInput
@ -490,6 +504,11 @@ void custom_ui_autocmds_groups(
@autoreleasepool { @autoreleasepool {
DLOG("got event %d for file %s in group %d.", event, fname, group); DLOG("got event %d for file %s in group %d.", event, fname, group);
if (event == EVENT_DIRCHANGED) {
send_cwd();
return;
}
if (event == EVENT_TEXTCHANGED if (event == EVENT_TEXTCHANGED
|| event == EVENT_TEXTCHANGEDI || event == EVENT_TEXTCHANGEDI
|| event == EVENT_BUFWRITEPOST || event == EVENT_BUFWRITEPOST

View File

@ -604,6 +604,15 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
return; return;
} }
case NeoVimServerMsgIdCwdChanged: {
if (data == nil) {
return;
}
[_bridge cwdChanged:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]];
return;
}
case NeoVimServerMsgIdAutoCommandEvent: { case NeoVimServerMsgIdAutoCommandEvent: {
if (data.length == sizeof(NSUInteger) + sizeof(NSInteger)) { if (data.length == sizeof(NSUInteger) + sizeof(NSInteger)) {
NSUInteger *values = (NSUInteger *) data.bytes; NSUInteger *values = (NSUInteger *) data.bytes;

View File

@ -128,6 +128,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)setTitle:(NSString *)title; - (void)setTitle:(NSString *)title;
- (void)setIcon:(NSString *)icon; - (void)setIcon:(NSString *)icon;
- (void)setDirtyStatus:(bool)dirty; - (void)setDirtyStatus:(bool)dirty;
- (void)cwdChanged:(NSString *)cwd;
- (void)autoCommandEvent:(NeoVimAutoCommandEvent)event bufferHandle:(NSInteger)bufferHandle; - (void)autoCommandEvent:(NeoVimAutoCommandEvent)event bufferHandle:(NSInteger)bufferHandle;
/** /**

View File

@ -201,10 +201,6 @@ extension NeoVimView {
self.tabChanged() self.tabChanged()
} }
if event == .DIRCHANGED {
self.cwdChanged()
}
if event == .BUFREADPOST || event == .BUFWRITEPOST { if event == .BUFREADPOST || event == .BUFWRITEPOST {
self.currentBufferChanged(bufferHandle) self.currentBufferChanged(bufferHandle)
} }
@ -238,6 +234,15 @@ extension NeoVimView {
} }
} }
public func cwdChanged(_ cwd: String) {
gui.async {
self.bridgeLogger.debug(cwd)
self._cwd = URL(fileURLWithPath: cwd)
self.cwdChanged()
}
}
public func setDirtyStatus(_ dirty: Bool) { public func setDirtyStatus(_ dirty: Bool) {
gui.async { gui.async {
self.bridgeLogger.debug(dirty) self.bridgeLogger.debug(dirty)

View File

@ -80,7 +80,7 @@ public class NeoVimView: NSView,
public var cwd: URL { public var cwd: URL {
get { get {
return self.agent.pwd() return self._cwd
} }
set { set {
@ -184,6 +184,7 @@ public class NeoVimView: NSView,
var currentEmoji = "😎" var currentEmoji = "😎"
var _font = NeoVimView.defaultFont var _font = NeoVimView.defaultFont
var _cwd = URL(fileURLWithPath: NSHomeDirectory())
var shouldDrawCursor = false var shouldDrawCursor = false
// MARK: - Private // MARK: - Private

View File

@ -187,9 +187,9 @@ class MainWindow: NSObject,
self.windowController.setDocumentEdited(state.isDirty) self.windowController.setDocumentEdited(state.isDirty)
if self.neoVimView.cwd != state.cwd { // if self.neoVimView.cwd != state.cwd {
self.neoVimView.cwd = state.cwd // self.neoVimView.cwd = state.cwd
} // }
if state.previewTool.isReverseSearchAutomatically if state.previewTool.isReverseSearchAutomatically
&& state.preview.previewPosition.hasDifferentMark(as: self.previewPosition) && state.preview.previewPosition.hasDifferentMark(as: self.previewPosition)
@ -227,9 +227,9 @@ class MainWindow: NSObject,
self.updateNeoVimAppearance() self.updateNeoVimAppearance()
self.neoVimView.delegate = self self.neoVimView.delegate = self
if self.neoVimView.cwd != state.cwd { // if self.neoVimView.cwd != state.cwd {
self.neoVimView.cwd = state.cwd // self.neoVimView.cwd = state.cwd
} // }
self.open(urls: state.urlsToOpen) self.open(urls: state.urlsToOpen)
@ -444,9 +444,9 @@ extension MainWindow {
let urls = panel.urls let urls = panel.urls
if self.neoVimView.allBuffers().count == 1 { if self.neoVimView.allBuffers().count == 1 {
let isTransient = self.neoVimView.allBuffers().first?.isTransient ?? false let isTransient = self.neoVimView.allBuffers().first?.isTransient ?? false
if isTransient { // if isTransient {
self.neoVimView.cwd = FileUtils.commonParent(of: urls) // self.neoVimView.cwd = FileUtils.commonParent(of: urls)
} // }
} }
self.neoVimView.open(urls: urls) self.neoVimView.open(urls: urls)
} }