1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-10-27 18:34:58 +03:00

GH-339 Pass neovim view to the renderer to get the current line and col

This commit is contained in:
Tae Won Ha 2017-01-04 18:38:52 +01:00
parent 1c163c96dd
commit 2e9a824de7
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
6 changed files with 47 additions and 3 deletions

View File

@ -336,6 +336,10 @@ extension NeoVimView {
self.exec(command: "qa!")
}
public func vimOutput(of command: String) -> String {
return self.agent.vimCommandOutput(command) ?? ""
}
fileprivate func open(_ url: URL, cmd: String) {
let path = url.path
let escapedFileName = self.agent.escapedFileName(path)

View File

@ -27,6 +27,7 @@
1929BD3F9E609BFADB27584B /* Scorer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B9D510177918080BE39B /* Scorer.swift */; };
1929BD4CA2204E061A86A140 /* MatcherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BC19C1BC19246AFF1621 /* MatcherTests.swift */; };
1929BD52275A6570C666A7BA /* PreviewRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B1EC32D8A26958FB39B1 /* PreviewRenderer.swift */; };
1929BE27005D80C5C129BF42 /* NeoVimViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B60F33F13D64762740E0 /* NeoVimViewExtension.swift */; };
1929BEB90DCDAF7A2B68C886 /* ColorUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BA6128BFDD54CA92F46E /* ColorUtils.swift */; };
1929BEFEABA0448306CDB6D4 /* FileItemIgnorePatternTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BBC84557C8351EC6183E /* FileItemIgnorePatternTest.swift */; };
1929BF81A40B4154D3EA33CE /* server_ui.m in Sources */ = {isa = PBXBuildFile; fileRef = 1929B93013228985F509C8F6 /* server_ui.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
@ -285,6 +286,7 @@
1929B477E1E62433BC48E10B /* ArrayCommonsTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayCommonsTest.swift; sourceTree = "<group>"; };
1929B5C3F2F1CA4113DABFFD /* CocoaCategories.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CocoaCategories.m; sourceTree = "<group>"; };
1929B5D977261F1EBFA9E8F1 /* FileUtilsTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileUtilsTest.swift; sourceTree = "<group>"; };
1929B60F33F13D64762740E0 /* NeoVimViewExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NeoVimViewExtension.swift; sourceTree = "<group>"; };
1929B69499B2569793350CEC /* FileItemIgnorePattern.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileItemIgnorePattern.swift; sourceTree = "<group>"; };
1929B7CB4863F80230C32D3C /* FileItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileItem.swift; sourceTree = "<group>"; };
1929B8DA5AA33536F0082200 /* PreviewComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreviewComponent.swift; sourceTree = "<group>"; };
@ -730,6 +732,7 @@
4B705B9F1DDF761C005F844B /* Tools */,
4B1AC1AF1D7F395300898F0B /* Open Quickly */,
4B238BED1D3ED55300CBDD98 /* Preferences */,
1929B60F33F13D64762740E0 /* NeoVimViewExtension.swift */,
);
name = UI;
sourceTree = "<group>";
@ -1288,6 +1291,7 @@
1929BA3BB94B77E9AE051FE5 /* PreviewComponent.swift in Sources */,
1929B4145AA81F006BAF3B5C /* PreviewService.swift in Sources */,
1929BD52275A6570C666A7BA /* PreviewRenderer.swift in Sources */,
1929BE27005D80C5C129BF42 /* NeoVimViewExtension.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -212,6 +212,7 @@ class MainWindowComponent: WindowComponent,
let previewData = previewToolData.toolData as? PreviewComponent.PrefData ?? PreviewComponent.PrefData.default
let preview = PreviewComponent(source: self.sink,
scrollSource: self.scrollFlow.sink,
neoVimInfoProvider: self.neoVimView,
initialData: previewData)
let previewConfig = WorkspaceTool.Config(title: "Preview",
view: preview,

View File

@ -117,6 +117,8 @@ class MarkdownRenderer: NSObject, Flow, PreviewRenderer {
fileprivate let webview: WKWebView
weak fileprivate var neoVimInfoProvider: NeoVimInfoProvider?
let identifier: String = MarkdownRenderer.identifier
var prefData: StandardPrefData? {
return PrefData(isForwardSearchAutomatically: self.isForwardSearchAutomatically,
@ -131,7 +133,7 @@ class MarkdownRenderer: NSObject, Flow, PreviewRenderer {
let toolbar: NSView? = NSView(forAutoLayout: ())
let menuItems: [NSMenuItem]?
init(source: Observable<Any>, scrollSource: Observable<Any>, initialData: PrefData) {
init(source: Observable<Any>, scrollSource: Observable<Any>, neoVimInfoProvider: NeoVimInfoProvider, initialData: PrefData) {
guard let templateUrl = Bundle.main.url(forResource: "template",
withExtension: "html",
subdirectory: "markdown")
@ -143,6 +145,8 @@ class MarkdownRenderer: NSObject, Flow, PreviewRenderer {
preconditionFailure("ERROR Cannot load markdown template")
}
self.neoVimInfoProvider = neoVimInfoProvider
self.template = template
self.flow = EmbeddableComponent(source: source)
@ -314,7 +318,7 @@ extension MarkdownRenderer {
}
func forwardSearchAction(_: Any?) {
NSLog("\(#function)")
NSLog("\(#function) for \(self.neoVimInfoProvider?.currentLine()) x \(self.neoVimInfoProvider?.currentColumn())")
}
func reverseSearchAction(_: Any?) {

View File

@ -0,0 +1,27 @@
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Cocoa
import SwiftNeoVim
protocol NeoVimInfoProvider: class {
func currentLine() -> Int
func currentColumn() -> Int
}
extension NeoVimView: NeoVimInfoProvider {
func currentLine() -> Int {
let output = self.vimOutput(of: "echo line('.')")
return Int(output) ?? 0
}
func currentColumn() -> Int {
let output = self.vimOutput(of: "echo virtcol('.')")
return Int(output) ?? 0
}
}

View File

@ -110,6 +110,8 @@ class PreviewComponent: NSView, ViewComponent, ToolDataHolder {
}
}
weak fileprivate var neoVimInfoProvider: NeoVimInfoProvider?
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@ -135,7 +137,8 @@ class PreviewComponent: NSView, ViewComponent, ToolDataHolder {
return self
}
init(source: Observable<Any>, scrollSource: Observable<Any>, initialData: PrefData) {
init(source: Observable<Any>, scrollSource: Observable<Any>, neoVimInfoProvider: NeoVimInfoProvider, initialData: PrefData) {
self.neoVimInfoProvider = neoVimInfoProvider
self.flow = EmbeddableComponent(source: source)
self.baseUrl = self.previewService.baseUrl()
@ -144,6 +147,7 @@ class PreviewComponent: NSView, ViewComponent, ToolDataHolder {
self.markdownRenderer = MarkdownRenderer(
source: self.flow.sink,
scrollSource: scrollSource.throttle(0.5, latest: true, scheduler: MainScheduler.instance),
neoVimInfoProvider: neoVimInfoProvider,
initialData: markdownData
)