1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-29 00:34:26 +03:00
vimr/VimR/MainWindowTransformer.swift

56 lines
1.5 KiB
Swift
Raw Normal View History

2017-01-22 16:22:05 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Foundation
import RxSwift
class MainWindowTransformer: Transformer {
typealias Pair = StateActionPair<UuidState<MainWindow.State>, MainWindow.Action>
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
return source.map { pair in
var state = pair.state.payload
switch pair.action {
case let .cd(to: cwd):
if state.cwd != cwd {
state.cwd = cwd
}
case let .setBufferList(buffers):
buffers
.flatMap { $0.url }
.forEach { state.urlsToOpen.removeValue(forKey: $0) }
state.buffers = buffers
2017-01-22 16:22:05 +03:00
case let .setCurrentBuffer(buffer):
state.currentBuffer = buffer
// if we scroll for reverse search we get scroll and set cursor event
case let .setCursor(to: position):
if state.preview.ignoreNextForward {
NSLog("ignoring!!!!! \(pair.action) -> \(position.payload)")
state.preview.editorPosition = Marked(mark: state.preview.editorPosition.mark, payload: position.payload)
state.preview.ignoreNextForward = false
} else {
NSLog("not ignoring!!!!! \(pair.action) -> \(position.payload)")
state.preview.editorPosition = position
}
2017-02-07 00:54:22 +03:00
case .close:
state.isClosed = true
default:
2017-01-22 16:22:05 +03:00
return pair
}
return StateActionPair(state: UuidState(uuid: state.uuid, state: state), action: pair.action)
}
}
}