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

Pass through current buffer changed event to preview component

This commit is contained in:
Tae Won Ha 2016-12-20 01:03:37 +01:00
parent 069adb5c6e
commit 9b377c9d34
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
6 changed files with 32 additions and 11 deletions

View File

@ -1436,9 +1436,7 @@ extension NeoVimView {
} }
if event == .BUFREADPOST || event == .BUFWRITEPOST { if event == .BUFREADPOST || event == .BUFWRITEPOST {
if self.currentBuffer()?.handle == bufferHandle { self.currentBufferChanged(bufferHandle)
self.currentBufferChanged()
}
} }
} }
@ -1455,9 +1453,17 @@ extension NeoVimView {
} }
} }
fileprivate func currentBufferChanged() { fileprivate func currentBufferChanged(_ handle: Int) {
DispatchUtils.gui { DispatchUtils.gui {
self.delegate?.currentBufferChanged() guard let currentBuffer = self.currentBuffer() else {
return
}
guard currentBuffer.handle == handle else {
return
}
self.delegate?.currentBufferChanged(currentBuffer)
} }
} }

View File

@ -13,7 +13,7 @@ public protocol NeoVimViewDelegate: class {
func set(dirtyStatus: Bool) func set(dirtyStatus: Bool)
func cwdChanged() func cwdChanged()
func bufferListChanged() func bufferListChanged()
func currentBufferChanged() func currentBufferChanged(_ currentBuffer: NeoVimBuffer)
func ipcBecameInvalid(reason: String) func ipcBecameInvalid(reason: String)
} }

View File

@ -1121,7 +1121,7 @@
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "if [ \"${CONFIGURATION}\" = \"Debug\" ]; then ]\n if [ -f \"SwiftNeoVim/NeoVimAutoCommandEvent.generated.h\" ]; then\n exit 0\n fi\nfi\n\nsed 's/^typedef enum auto_event/typedef NS_ENUM(NSUInteger, NeoVimAutoCommandEvent)/' <./neovim/build/include/auevents_enum.generated.h | sed 's/ event_T//' | sed 's/EVENT_/NeoVimAutoCommandEvent/' | sed 's/NUM_EVENTS/NumberOfAutoCommandEvents/' | sed -e '1s/^/@import Foundation;\\'$'\\n/' > SwiftNeoVim/NeoVimAutoCommandEvent.generated.h\n"; shellScript = "if [ \"${CONFIGURATION}\" = \"Debug\" ]; then\n if [ -f \"SwiftNeoVim/NeoVimAutoCommandEvent.generated.h\" ]; then\n exit 0\n fi\nfi\n\nsed 's/^typedef enum auto_event/typedef NS_ENUM(NSUInteger, NeoVimAutoCommandEvent)/' <./neovim/build/include/auevents_enum.generated.h | sed 's/ event_T//' | sed 's/EVENT_/NeoVimAutoCommandEvent/' | sed 's/NUM_EVENTS/NumberOfAutoCommandEvents/' | sed -e '1s/^/@import Foundation;\\'$'\\n/' > SwiftNeoVim/NeoVimAutoCommandEvent.generated.h\n";
}; };
4BBA71F11D319E0900E16612 /* ShellScript */ = { 4BBA71F11D319E0900E16612 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase; isa = PBXShellScriptBuildPhase;

View File

@ -15,6 +15,8 @@ enum MainWindowAction {
case changeBufferList(mainWindow: MainWindowComponent, buffers: [NeoVimBuffer]) case changeBufferList(mainWindow: MainWindowComponent, buffers: [NeoVimBuffer])
case changeFileBrowserSelection(mainWindow: MainWindowComponent, url: URL) case changeFileBrowserSelection(mainWindow: MainWindowComponent, url: URL)
case close(mainWindow: MainWindowComponent, mainWindowPrefData: MainWindowPrefData) case close(mainWindow: MainWindowComponent, mainWindowPrefData: MainWindowPrefData)
case currentBufferChanged(mainWindow: MainWindowComponent, buffer: NeoVimBuffer)
} }
struct MainWindowPrefData: StandardPrefData { struct MainWindowPrefData: StandardPrefData {
@ -516,8 +518,8 @@ extension MainWindowComponent {
self.publish(event: MainWindowAction.changeBufferList(mainWindow: self, buffers: buffers)) self.publish(event: MainWindowAction.changeBufferList(mainWindow: self, buffers: buffers))
} }
func currentBufferChanged() { func currentBufferChanged(_ currentBuffer: NeoVimBuffer) {
NSLog("current buffer changed!!!") self.publish(event: MainWindowAction.currentBufferChanged(mainWindow: self, buffer: currentBuffer))
} }
func ipcBecameInvalid(reason: String) { func ipcBecameInvalid(reason: String) {

View File

@ -49,7 +49,7 @@ class MainWindowManager: StandardFlow {
case let .close(mainWindow, mainWindowPrefData): case let .close(mainWindow, mainWindowPrefData):
self.close(mainWindow, prefData: mainWindowPrefData) self.close(mainWindow, prefData: mainWindowPrefData)
case .changeCwd, .changeBufferList, .changeFileBrowserSelection: default:
break; break;
} }
}) })

View File

@ -50,6 +50,19 @@ class PreviewComponent: ViewComponent {
} }
override func subscription(source: Observable<Any>) -> Disposable { override func subscription(source: Observable<Any>) -> Disposable {
return Disposables.create() return source
.filter { $0 is MainWindowAction }
.map { $0 as! MainWindowAction }
.subscribe(onNext: { action in
switch action {
case let .currentBufferChanged(mainWindow, currentBuffer):
NSLog("\(currentBuffer)")
default:
return
}
})
} }
} }