Skip to content

Commit

Permalink
feat: ctrl/alt+up/down arrow to scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
netdcy committed Nov 22, 2024
1 parent ef36e5f commit f84c1d9
Showing 1 changed file with 70 additions and 2 deletions.
72 changes: 70 additions & 2 deletions FlowVision/Sources/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,78 @@ class ViewController: NSViewController, NSSplitViewDelegate {
}
}

// 检查按键是否是 Command+⬆️ 键
// if specialKey == .upArrow && isCommandPressed {
// closeLargeImage(0)
// switchDirByDirection(direction: .up, stackDeep: 0)
// return nil
// }

// 检查按键是否是 Command+⬆️ 键
if specialKey == .upArrow && isCommandPressed {
closeLargeImage(0)
switchDirByDirection(direction: .up, stackDeep: 0)
if let scrollView = collectionView.enclosingScrollView {
scrollView.contentView.scroll(to: NSPoint(x: 0, y: 0))
scrollView.reflectScrolledClipView(scrollView.contentView)
DispatchQueue.main.async { [weak self] in
self?.setLoadThumbPriority(ifNeedVisable: true)
}
}
return nil
}

// 检查按键是否是 Command+⬇️ 键
if specialKey == .downArrow && isCommandPressed {
if let scrollView = collectionView.enclosingScrollView {
let newOrigin = NSPoint(x: 0, y: collectionView.bounds.height - scrollView.contentSize.height)
scrollView.contentView.scroll(to: newOrigin)
scrollView.reflectScrolledClipView(scrollView.contentView)
DispatchQueue.main.async { [weak self] in
self?.setLoadThumbPriority(ifNeedVisable: true)
}
}
return nil
}

// 检查按键是否是 Alt+⬆️ 键
if specialKey == .upArrow && isAltPressed {
if let scrollView = collectionView.enclosingScrollView {
let currentOrigin = scrollView.contentView.bounds.origin
let pageHeight = scrollView.contentSize.height

// Calculate the new y position by subtracting the page height from the current y position.
let newY = max(currentOrigin.y - pageHeight, 0)
let newOrigin = NSPoint(x: currentOrigin.x, y: newY)

// Scroll to the new origin
scrollView.contentView.scroll(to: newOrigin)
scrollView.reflectScrolledClipView(scrollView.contentView)

DispatchQueue.main.async { [weak self] in
self?.setLoadThumbPriority(ifNeedVisable: true)
}
}
return nil
}


// 检查按键是否是 Alt+⬇️ 键
if specialKey == .downArrow && isAltPressed {
if let scrollView = collectionView.enclosingScrollView {
let currentOrigin = scrollView.contentView.bounds.origin
let pageHeight = scrollView.contentSize.height

// Calculate the new y position by adding the page height to the current y position.
let newY = min(currentOrigin.y + pageHeight, collectionView.bounds.height - pageHeight)
let newOrigin = NSPoint(x: currentOrigin.x, y: newY)

// Scroll to the new origin
scrollView.contentView.scroll(to: newOrigin)
scrollView.reflectScrolledClipView(scrollView.contentView)

DispatchQueue.main.async { [weak self] in
self?.setLoadThumbPriority(ifNeedVisable: true)
}
}
return nil
}

Expand Down

1 comment on commit f84c1d9

@lirenjie95
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Petting fish at work

Please sign in to comment.