|
@@ -576,48 +576,48 @@ extension KMNThumbnailBaseViewController {
|
|
|
var pastIndex = 1
|
|
|
let point = menuitemProperty.representedObject as? NSPoint
|
|
|
|
|
|
- if(point != nil) {
|
|
|
- let pointInCollectionView = collectionView.convert(point!, from: nil)
|
|
|
-
|
|
|
- let visibleItems = collectionView.visibleItems()
|
|
|
- let mouseX = pointInCollectionView.x
|
|
|
- let mouseY = pointInCollectionView.y
|
|
|
-
|
|
|
- // 获取当前行的所有 cell
|
|
|
- let currentRowItems = visibleItems.filter { item in
|
|
|
- if let indexPath = collectionView.indexPath(for: item),
|
|
|
- let cellAttributes = collectionView.layoutAttributesForItem(at: indexPath) {
|
|
|
- return cellAttributes.frame.minY <= mouseY && cellAttributes.frame.maxY >= mouseY
|
|
|
- }
|
|
|
- return false
|
|
|
- }
|
|
|
- if(mouseX < 24) { //点击区域在最左边
|
|
|
- // 找到最近右边的 cell
|
|
|
- let rightMostCell = currentRowItems.compactMap { collectionView.indexPath(for: $0) }
|
|
|
- .filter { indexPath in
|
|
|
- let cellRect = collectionView.layoutAttributesForItem(at: indexPath)?.frame
|
|
|
- return cellRect?.minX ?? 0 > mouseX // 只选择右侧的 cell
|
|
|
- }
|
|
|
- .sorted { ($0.item < $1.item) } // 按 item 的顺序排列
|
|
|
- .first // 选择第一个,即最右边的 cell
|
|
|
- pastIndex = (rightMostCell?.item ?? (Int(showDocument?.pageCount ?? 1)))
|
|
|
- } else {
|
|
|
- // 找到最近右边的 cell
|
|
|
- let leftMostCell = currentRowItems.compactMap { collectionView.indexPath(for: $0) }
|
|
|
- .filter { indexPath in
|
|
|
- let cellRect = collectionView.layoutAttributesForItem(at: indexPath)?.frame
|
|
|
- return cellRect?.maxX ?? 0 < mouseX // 只选择左侧的 cell
|
|
|
- }
|
|
|
- .sorted { $0.item > $1.item } // 按 item 的逆序排列,以选择最近的左侧 cell
|
|
|
- .first // 选择第一个,即最近的左边的 cell
|
|
|
-
|
|
|
- pastIndex = (leftMostCell?.item ?? (Int(showDocument?.pageCount ?? 1)) - 1) + 1
|
|
|
- }
|
|
|
+ let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
+ if(selectedIndexPaths.count > 0) {
|
|
|
+ let maxmumIndexPath = selectedIndexPaths.max(by: { $0 < $1 })
|
|
|
+ pastIndex = ((maxmumIndexPath?.item ?? 0) + 1)
|
|
|
} else {
|
|
|
- let selectedIndexPaths = collectionView.selectionIndexPaths
|
|
|
- if(selectedIndexPaths.count > 0) {
|
|
|
- let maxmumIndexPath = selectedIndexPaths.max(by: { $0 < $1 })
|
|
|
- pastIndex = ((maxmumIndexPath?.item ?? 0) + 1)
|
|
|
+ if(point != nil) {
|
|
|
+ let pointInCollectionView = collectionView.convert(point!, from: nil)
|
|
|
+
|
|
|
+ let visibleItems = collectionView.visibleItems()
|
|
|
+ let mouseX = pointInCollectionView.x
|
|
|
+ let mouseY = pointInCollectionView.y
|
|
|
+
|
|
|
+ // 获取当前行的所有 cell
|
|
|
+ let currentRowItems = visibleItems.filter { item in
|
|
|
+ if let indexPath = collectionView.indexPath(for: item),
|
|
|
+ let cellAttributes = collectionView.layoutAttributesForItem(at: indexPath) {
|
|
|
+ return cellAttributes.frame.minY <= mouseY && cellAttributes.frame.maxY >= mouseY
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if(mouseX < 24) { //点击区域在最左边
|
|
|
+ // 找到最近右边的 cell
|
|
|
+ let rightMostCell = currentRowItems.compactMap { collectionView.indexPath(for: $0) }
|
|
|
+ .filter { indexPath in
|
|
|
+ let cellRect = collectionView.layoutAttributesForItem(at: indexPath)?.frame
|
|
|
+ return cellRect?.minX ?? 0 > mouseX // 只选择右侧的 cell
|
|
|
+ }
|
|
|
+ .sorted { ($0.item < $1.item) } // 按 item 的顺序排列
|
|
|
+ .first // 选择第一个,即最右边的 cell
|
|
|
+ pastIndex = (rightMostCell?.item ?? (Int(showDocument?.pageCount ?? 1)))
|
|
|
+ } else {
|
|
|
+ // 找到最近右边的 cell
|
|
|
+ let leftMostCell = currentRowItems.compactMap { collectionView.indexPath(for: $0) }
|
|
|
+ .filter { indexPath in
|
|
|
+ let cellRect = collectionView.layoutAttributesForItem(at: indexPath)?.frame
|
|
|
+ return cellRect?.maxX ?? 0 < mouseX // 只选择左侧的 cell
|
|
|
+ }
|
|
|
+ .sorted { $0.item > $1.item } // 按 item 的逆序排列,以选择最近的左侧 cell
|
|
|
+ .first // 选择第一个,即最近的左边的 cell
|
|
|
+
|
|
|
+ pastIndex = (leftMostCell?.item ?? (Int(showDocument?.pageCount ?? 1)) - 1) + 1
|
|
|
+ }
|
|
|
} else {
|
|
|
pastIndex = Int(showDocument?.pageCount ?? 0)
|
|
|
}
|