diff --git a/Proton/Sources/Swift/Grid/View/GridView.swift b/Proton/Sources/Swift/Grid/View/GridView.swift index a11464ca..f89fc667 100644 --- a/Proton/Sources/Swift/Grid/View/GridView.swift +++ b/Proton/Sources/Swift/Grid/View/GridView.swift @@ -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. diff --git a/Proton/Tests/Grid/GridViewTests.swift b/Proton/Tests/Grid/GridViewTests.swift index f6b23d8b..8684d588 100644 --- a/Proton/Tests/Grid/GridViewTests.swift +++ b/Proton/Tests/Grid/GridViewTests.swift @@ -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) + } + }