Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5eba9cc

Browse files
committed
Change key up/down row selection to first/last visible rows, instead of global first/last
1 parent facfb7e commit 5eba9cc

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Package.resolved

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717
],
1818
dependencies: [
1919
// Dependencies declare other packages that this package depends on.
20-
.package(url: "https://github.com/ipedro/UIKitOptions.git", from: "0.3.0"),
20+
.package(url: "https://github.com/ipedro/UIKitOptions.git", from: "0.3.1"),
2121
],
2222
targets: [
2323
// Targets are the basic building blocks of a package. A target can define a module or a test suite.

Sources/UIKeyCommandTableView/UIKeyCommandTableView.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,25 @@ private extension UIKeyCommandTableView {
293293

294294
func selectPrevious() {
295295
guard let currentSelection = indexPathForSelectedRow else {
296-
return selectRowIfPossible(at: indexPathForLastRowInLastSection)
296+
return selectRowIfPossible(at: {
297+
if let lastVisibleRow = indexPathsForVisibleRows?.last {
298+
return lastVisibleRow
299+
}
300+
return indexPathForLastRowInLastSection
301+
}())
297302
}
298303

299304
selectRowIfPossible(at: currentSelection.previousRow())
300305
}
301306

302307
func selectNext() {
303308
guard let currentSelection = indexPathForSelectedRow else {
304-
return selectRowIfPossible(at: .first)
309+
return selectRowIfPossible(at: {
310+
if let firstVisibleRow = indexPathsForVisibleRows?.first {
311+
return firstVisibleRow
312+
}
313+
return IndexPath(row: NSNotFound, section: .zero)
314+
}())
305315
}
306316

307317
selectRowIfPossible(at: currentSelection.nextRow())

0 commit comments

Comments
 (0)