2017-01-22 16:22:05 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
2017-01-17 21:47:59 +03:00
|
|
|
|
|
|
|
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 {
|
|
|
|
|
2017-02-23 00:51:24 +03:00
|
|
|
case let .open(marks):
|
|
|
|
state.urlsToOpen = state.urlsToOpen.filter { !marks.contains($0.mark) }
|
|
|
|
|
|
|
|
case let .cd(to:cwd):
|
2017-01-17 21:47:59 +03:00
|
|
|
if state.cwd != cwd {
|
|
|
|
state.cwd = cwd
|
|
|
|
}
|
|
|
|
|
|
|
|
case let .setBufferList(buffers):
|
|
|
|
state.buffers = buffers
|
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
case let .setCurrentBuffer(buffer):
|
|
|
|
state.currentBuffer = buffer
|
|
|
|
|
2017-02-26 12:26:37 +03:00
|
|
|
case let .setDirtyStatus(status):
|
|
|
|
state.isDirty = status
|
|
|
|
|
2017-02-23 00:51:24 +03:00
|
|
|
// if we scroll for reverse search we get scroll and set cursor event
|
|
|
|
case let .setCursor(to:position):
|
2017-02-12 18:40:49 +03:00
|
|
|
state.preview.forceNextReverse = false
|
|
|
|
|
2017-02-11 20:32:22 +03:00
|
|
|
if state.preview.ignoreNextForward {
|
|
|
|
state.preview.editorPosition = Marked(mark: state.preview.editorPosition.mark, payload: position.payload)
|
|
|
|
state.preview.ignoreNextForward = false
|
|
|
|
} else {
|
|
|
|
state.preview.editorPosition = position
|
|
|
|
}
|
2017-02-07 00:54:22 +03:00
|
|
|
|
2017-02-25 00:47:32 +03:00
|
|
|
case let .focus(view):
|
|
|
|
state.focusedView = view
|
|
|
|
|
2017-02-04 17:34:13 +03:00
|
|
|
case .close:
|
|
|
|
state.isClosed = true
|
|
|
|
|
2017-01-17 21:47:59 +03:00
|
|
|
default:
|
2017-01-22 16:22:05 +03:00
|
|
|
return pair
|
2017-01-17 21:47:59 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return StateActionPair(state: UuidState(uuid: state.uuid, state: state), action: pair.action)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|