Skip to content

Commit

Permalink
Added ability to query cell for given editor in GridView
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep committed Nov 24, 2023
1 parent 7a0a81f commit ffb4cbc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Proton/Sources/Swift/Grid/View/GridView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,13 @@ public class GridView: UIView {
public func setColumnResizing(_ enabled: Bool) {
isColumnResizingHandlesVisible = enabled
}

/// Gets the cell for the `EditorView` contained in the current instance
/// - Parameter editor: Editor for which cell needs to be queried.
/// - Returns: `GridCell` that contains the passed in `EditorView`, if present
public func cellFor(_ editor: EditorView) -> GridCell? {
return cells.first(where: { $0.editor == editor })
}

/// Determines if the collection of cells can be merged. For cells to be mergable, they need to
/// be adjacent to each other, and the shape of selection needs to be rectangular.
Expand Down
13 changes: 13 additions & 0 deletions Proton/Tests/Grid/GridViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,17 @@ class GridViewTests: XCTestCase {
waitForExpectations(timeout: 1.0)
}

func testGetsCellFromEditor() throws {
let gridView = GridView(config: config)
let delegate = MockGridViewDelegate()
gridView.delegate = delegate
gridView.gridView.willMove(toWindow: UIWindow())

let cellToQuery = try XCTUnwrap(gridView.cellAt(rowIndex: 1, columnIndex: 1))
let editorToQuery = try XCTUnwrap(cellToQuery.editor)

let cell = gridView.cellFor(editorToQuery)
XCTAssertEqual(cell, cellToQuery)
}

}

0 comments on commit ffb4cbc

Please sign in to comment.