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

GH-339 React to cursor moved also

This commit is contained in:
Tae Won Ha 2017-01-08 13:52:28 +01:00
parent 7d69f6f1ae
commit 63b3a35ba9
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
4 changed files with 13 additions and 5 deletions

View File

@ -1288,6 +1288,9 @@ extension NeoVimView {
self.grid.goto(position)
self.grid.moveCursor(screenCursor)
}
DispatchUtils.gui {
self.delegate?.cursor(to: currentPosition)
}
}
public func updateMenu() {

View File

@ -18,4 +18,5 @@ public protocol NeoVimViewDelegate: class {
func ipcBecameInvalid(reason: String)
func scroll()
func cursor(to: Position)
}

View File

@ -91,6 +91,7 @@ class MainWindowComponent: WindowComponent,
enum ScrollAction {
case scroll(to: Position)
case cursor(to: Position)
}
fileprivate static let nibName = "MainWindow"
@ -560,8 +561,11 @@ extension MainWindowComponent {
}
func scroll() {
let pos = self.neoVimView.currentPosition
self.scrollFlow.publish(event: ScrollAction.scroll(to: pos))
self.scrollFlow.publish(event: ScrollAction.scroll(to: self.neoVimView.currentPosition))
}
func cursor(to position: Position) {
self.scrollFlow.publish(event: ScrollAction.cursor(to: self.neoVimView.currentPosition))
}
}

View File

@ -291,12 +291,12 @@ class MarkdownRenderer: NSObject, Flow, PreviewRenderer {
fileprivate func scrollSubscription(source: Observable<Any>) -> Disposable {
return source
.throttle(0.5, latest: true, scheduler: MainScheduler.instance)
.throttle(1, latest: true, scheduler: MainScheduler.instance)
.filter { $0 is MainWindowComponent.ScrollAction }
.map { $0 as! MainWindowComponent.ScrollAction }
.subscribe(onNext: { [unowned self] action in
switch action {
case let .scroll(to: position):
case let .scroll(to: position), let .cursor(to: position):
self.currentEditorPosition = position
}
@ -311,7 +311,7 @@ class MarkdownRenderer: NSObject, Flow, PreviewRenderer {
fileprivate func addReactions() {
self.webviewMessageHandler.flow.sink
.throttle(0.5, latest: true, scheduler: MainScheduler.instance)
.throttle(1, latest: true, scheduler: MainScheduler.instance)
.filter { $0 is WebviewMessageHandler.Action }
.map { $0 as! WebviewMessageHandler.Action }
.subscribe(onNext: { [weak self] action in