mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-29 03:53:38 +03:00
GH-339 Pass scroll event
This commit is contained in:
parent
03f20abffb
commit
1c163c96dd
@ -1307,6 +1307,7 @@ extension NeoVimView {
|
|||||||
DispatchUtils.gui {
|
DispatchUtils.gui {
|
||||||
self.grid.scroll(Int(count))
|
self.grid.scroll(Int(count))
|
||||||
self.setNeedsDisplay(region: self.grid.region)
|
self.setNeedsDisplay(region: self.grid.region)
|
||||||
|
self.delegate?.scroll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,4 +16,6 @@ public protocol NeoVimViewDelegate: class {
|
|||||||
func currentBufferChanged(_ currentBuffer: NeoVimBuffer)
|
func currentBufferChanged(_ currentBuffer: NeoVimBuffer)
|
||||||
|
|
||||||
func ipcBecameInvalid(reason: String)
|
func ipcBecameInvalid(reason: String)
|
||||||
|
|
||||||
|
func scroll()
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,11 @@ class MainWindowComponent: WindowComponent,
|
|||||||
WorkspaceDelegate
|
WorkspaceDelegate
|
||||||
{
|
{
|
||||||
|
|
||||||
|
enum ScrollAction {
|
||||||
|
|
||||||
|
case scroll
|
||||||
|
}
|
||||||
|
|
||||||
fileprivate static let nibName = "MainWindow"
|
fileprivate static let nibName = "MainWindow"
|
||||||
|
|
||||||
fileprivate var defaultEditorFont: NSFont
|
fileprivate var defaultEditorFont: NSFont
|
||||||
@ -101,6 +106,8 @@ class MainWindowComponent: WindowComponent,
|
|||||||
fileprivate let neoVimView: NeoVimView
|
fileprivate let neoVimView: NeoVimView
|
||||||
fileprivate var tools = [ToolIdentifier: WorkspaceToolComponent]()
|
fileprivate var tools = [ToolIdentifier: WorkspaceToolComponent]()
|
||||||
|
|
||||||
|
fileprivate let scrollFlow: EmbeddableComponent
|
||||||
|
|
||||||
// MARK: - API
|
// MARK: - API
|
||||||
var uuid: String {
|
var uuid: String {
|
||||||
return self.neoVimView.uuid
|
return self.neoVimView.uuid
|
||||||
@ -144,6 +151,8 @@ class MainWindowComponent: WindowComponent,
|
|||||||
self.defaultEditorFont = initialData.appearance.editorFont
|
self.defaultEditorFont = initialData.appearance.editorFont
|
||||||
self.fileItemService = fileItemService
|
self.fileItemService = fileItemService
|
||||||
|
|
||||||
|
self.scrollFlow = EmbeddableComponent(source: Observable.empty())
|
||||||
|
|
||||||
super.init(source: source, nibName: MainWindowComponent.nibName)
|
super.init(source: source, nibName: MainWindowComponent.nibName)
|
||||||
|
|
||||||
self.window.delegate = self
|
self.window.delegate = self
|
||||||
@ -201,7 +210,9 @@ class MainWindowComponent: WindowComponent,
|
|||||||
self.tools[.bufferList] = bufferListTool
|
self.tools[.bufferList] = bufferListTool
|
||||||
|
|
||||||
let previewData = previewToolData.toolData as? PreviewComponent.PrefData ?? PreviewComponent.PrefData.default
|
let previewData = previewToolData.toolData as? PreviewComponent.PrefData ?? PreviewComponent.PrefData.default
|
||||||
let preview = PreviewComponent(source: self.sink, initialData: previewData)
|
let preview = PreviewComponent(source: self.sink,
|
||||||
|
scrollSource: self.scrollFlow.sink,
|
||||||
|
initialData: previewData)
|
||||||
let previewConfig = WorkspaceTool.Config(title: "Preview",
|
let previewConfig = WorkspaceTool.Config(title: "Preview",
|
||||||
view: preview,
|
view: preview,
|
||||||
minimumDimension: 200,
|
minimumDimension: 200,
|
||||||
@ -543,6 +554,10 @@ extension MainWindowComponent {
|
|||||||
self?.windowController.close()
|
self?.windowController.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func scroll() {
|
||||||
|
self.scrollFlow.publish(event: ScrollAction.scroll)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - NSWindowDelegate
|
// MARK: - NSWindowDelegate
|
||||||
|
@ -131,7 +131,7 @@ class MarkdownRenderer: NSObject, Flow, PreviewRenderer {
|
|||||||
let toolbar: NSView? = NSView(forAutoLayout: ())
|
let toolbar: NSView? = NSView(forAutoLayout: ())
|
||||||
let menuItems: [NSMenuItem]?
|
let menuItems: [NSMenuItem]?
|
||||||
|
|
||||||
init(source: Observable<Any>, initialData: PrefData) {
|
init(source: Observable<Any>, scrollSource: Observable<Any>, initialData: PrefData) {
|
||||||
guard let templateUrl = Bundle.main.url(forResource: "template",
|
guard let templateUrl = Bundle.main.url(forResource: "template",
|
||||||
withExtension: "html",
|
withExtension: "html",
|
||||||
subdirectory: "markdown")
|
subdirectory: "markdown")
|
||||||
@ -197,6 +197,13 @@ class MarkdownRenderer: NSObject, Flow, PreviewRenderer {
|
|||||||
refreshOnWriteMenuItem.target = self
|
refreshOnWriteMenuItem.target = self
|
||||||
refreshOnWriteMenuItem.action = #selector(MarkdownRenderer.refreshOnWriteAction)
|
refreshOnWriteMenuItem.action = #selector(MarkdownRenderer.refreshOnWriteAction)
|
||||||
|
|
||||||
|
scrollSource
|
||||||
|
.filter { $0 is MainWindowComponent.ScrollAction }
|
||||||
|
.subscribe(onNext: { action in
|
||||||
|
NSLog("renderer scroll")
|
||||||
|
})
|
||||||
|
.addDisposableTo(self.flow.disposeBag)
|
||||||
|
|
||||||
self.addReactions()
|
self.addReactions()
|
||||||
self.userContentController.add(webviewMessageHandler, name: "com_vimr_preview_markdown")
|
self.userContentController.add(webviewMessageHandler, name: "com_vimr_preview_markdown")
|
||||||
}
|
}
|
||||||
|
@ -135,13 +135,17 @@ class PreviewComponent: NSView, ViewComponent, ToolDataHolder {
|
|||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
init(source: Observable<Any>, initialData: PrefData) {
|
init(source: Observable<Any>, scrollSource: Observable<Any>, initialData: PrefData) {
|
||||||
self.flow = EmbeddableComponent(source: source)
|
self.flow = EmbeddableComponent(source: source)
|
||||||
|
|
||||||
self.baseUrl = self.previewService.baseUrl()
|
self.baseUrl = self.previewService.baseUrl()
|
||||||
let markdownData = initialData.rendererDatas[MarkdownRenderer.identifier] as? MarkdownRenderer.PrefData ??
|
let markdownData = initialData.rendererDatas[MarkdownRenderer.identifier] as? MarkdownRenderer.PrefData ??
|
||||||
MarkdownRenderer.PrefData.default
|
MarkdownRenderer.PrefData.default
|
||||||
self.markdownRenderer = MarkdownRenderer(source: self.flow.sink, initialData: markdownData)
|
self.markdownRenderer = MarkdownRenderer(
|
||||||
|
source: self.flow.sink,
|
||||||
|
scrollSource: scrollSource.throttle(0.5, latest: true, scheduler: MainScheduler.instance),
|
||||||
|
initialData: markdownData
|
||||||
|
)
|
||||||
|
|
||||||
self.renderers = [
|
self.renderers = [
|
||||||
self.markdownRenderer,
|
self.markdownRenderer,
|
||||||
|
Loading…
Reference in New Issue
Block a user