1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-24 11:37:32 +03:00
vimr/VimR/MainWindowReducer.swift

77 lines
2.2 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
2017-03-29 21:10:11 +03:00
class MainWindowReducer: Reducer {
typealias Pair = StateActionPair<UuidState<MainWindow.State>, MainWindow.Action>
2017-03-29 21:17:45 +03:00
func reduce(_ 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 .cd(to:cwd):
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):
// When I gt or w around, we change tab somehow... Dunno why...
if status == pair.state.payload.isDirty {
return pair
}
2017-02-26 12:26:37 +03:00
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
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):
2017-03-31 20:32:01 +03:00
state.viewToBeFocused = view
2017-02-25 00:47:32 +03:00
2017-02-28 17:52:48 +03:00
case let .setState(for: tool, with: workspaceTool):
2017-03-01 18:59:23 +03:00
state.tools[tool] = WorkspaceToolState(location: workspaceTool.location,
dimension: workspaceTool.dimension,
open: workspaceTool.isSelected)
if workspaceTool.isSelected {
state.tools
.filter { $0 != tool && $1.location == workspaceTool.location }
.forEach { state.tools[$0.0]?.open = false }
}
2017-02-28 17:52:48 +03:00
case let .toggleAllTools(value):
state.isAllToolsVisible = value
case let .toggleToolButtons(value):
state.isToolButtonsVisible = value
default:
2017-01-22 16:22:05 +03:00
return pair
}
return StateActionPair(state: UuidState(uuid: state.uuid, state: state), action: pair.action)
}
}
}