Skip to content

Commit

Permalink
Fixed issue where a cell with nested editor in focus may get recycled
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep committed Oct 4, 2024
1 parent 486b674 commit d75c0c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Proton/Sources/Swift/Table/TableCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class TableCell {
/// Returns `true` if the cell has one or more retain invocations.
@MainActor
public var isRetained: Bool {
retainCount > 0
retainCount > 0 || containsFirstResponder
}

/// Additional attributes that can be stored on Cell to identify various aspects like Header, Numbered etc.
Expand Down
18 changes: 9 additions & 9 deletions Proton/Sources/Swift/Table/TableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public class TableView: UIView {

var cellsInViewport: [TableCell] = [] {
didSet {
reclaimReleasedCells()
reclaimReleasedCells(cellsInViewport)

guard oldValue != cellsInViewport else { return }

Expand Down Expand Up @@ -496,13 +496,15 @@ public class TableView: UIView {
.intersects(adjustedViewport) }
}

private func reclaimReleasedCells() {
retainedCells.forEach {
if $0.isRetained == false {
self.repository.enqueue(cell: $0)
retainedCells.remove($0)
private func reclaimReleasedCells(_ cellsInViewport: [TableCell]) {
retainedCells
.filter { cellsInViewport.contains($0) == false }
.forEach {
if $0.isRetained == false {
self.repository.enqueue(cell: $0)
retainedCells.remove($0)
}
}
}
}

func cellBelow(_ cell: TableCell) -> TableCell? {
Expand Down Expand Up @@ -870,13 +872,11 @@ extension TableView: TableContentViewDelegate {
}

func tableContentView(_ tableContentView: TableContentView, didReceiveFocusAt range: NSRange, in cell: TableCell) {
cell.retain()
resetColumnResizingHandles(selectedCell: cell)
delegate?.tableView(self, didReceiveFocusAt: range, in: cell)
}

func tableContentView(_ tableContentView: TableContentView, didLoseFocusFrom range: NSRange, in cell: TableCell) {
cell.release()
removeSelectionBorders()
delegate?.tableView(self, didLoseFocusFrom: range, in: cell)
}
Expand Down

0 comments on commit d75c0c7

Please sign in to comment.