Skip to content

Commit

Permalink
Add scroll method to XiViewProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatoszko committed Feb 28, 2019
1 parent 90a35c1 commit 5476a80
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Sources/XiEditor/XiViewProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ protocol XiViewProxy: class {
func copy() -> String?
func cut() -> String?

/// Notifies the back-end of the visible scroll region, defined as the first and last
/// (non-inclusive) formatted lines. The visible scroll region is used to compute movement
/// distance for page up and page down commands, and also controls the size of the fragment
/// sent in the update method.
func scroll(firstLine: Int, lastLine: Int)

func toggleRecording(name: String)
func playRecording(name: String)
func clearRecording(name: String)
Expand Down Expand Up @@ -104,6 +110,10 @@ final class XiViewConnection: XiViewProxy {
}
}

func scroll(firstLine: Int, lastLine: Int) {
sendRpcAsync("scroll", params: [firstLine, lastLine])
}

func toggleRecording(name: String) {
sendRpcAsync("toggle_recording", params: ["recording_name": name])
}
Expand Down
13 changes: 13 additions & 0 deletions Tests/XiEditorTests/XiViewProxyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ class XiViewProxyTests: XCTestCase {
XCTAssertEqual(result!, testCopyCharacters)
}

func testScroll() {
let asyncCalledExpectation = expectation(description: "Async should be called")
let async: XiViewConnection.AsyncRpc = { method, params, _ in
XCTAssertEqual("scroll", method)
let scrollParams = params as! [Int]
XCTAssertEqual([23, 42], scrollParams)
asyncCalledExpectation.fulfill()
}
let connection: XiViewProxy = XiViewConnection(asyncRpc: async, syncRpc: unusedSync)
connection.scroll(firstLine: 23, lastLine: 42)
wait(for: [asyncCalledExpectation], timeout: 1)
}

func testToggleRecording() {
let asyncCalledExpectation = expectation(description: "Async should be called")
let async: XiViewConnection.AsyncRpc = { method, params,_ in
Expand Down

0 comments on commit 5476a80

Please sign in to comment.