Skip to content

Commit

Permalink
Merge pull request #43 from qwertyyb/fix/scroll-load
Browse files Browse the repository at this point in the history
fix(view): 修复NSAttributedString导致渲染卡慢的问题;修复不会自动加载下一页的问题
  • Loading branch information
qwertyyb committed Nov 14, 2020
2 parents 1071d6c + 9c5370a commit 17fb0da
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion YPaste/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>Explosion v1.0.0-alpha</string>
<key>CFBundleVersion</key>
<string>103046</string>
<string>103067</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
8 changes: 2 additions & 6 deletions YPaste/PasteboardHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ extension PasteItem {
if pType == .string {
return NSAttributedString(string: String(data: data, encoding: .utf8) ?? "[error data]")
}
if pType == .html {
// html使用nsattributedstring有渲染性能问题,先特殊处理
let str = NSAttributedString(html: data, documentAttributes: nil)
return NSAttributedString(string: str?.string ?? "[empty html data]")
}
// NSAttributedString 会有性能问题,导致应用卡死
if let str = NSAttributedString(pasteboardPropertyList: data, ofType: pType) {
return str
return NSAttributedString(string: str.string)
}
if let url = URL(dataRepresentation: data, relativeTo: nil) {
return NSAttributedString(string: url.absoluteString)
Expand Down
23 changes: 13 additions & 10 deletions YPaste/Window/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,19 @@ class MainView: NSVisualEffectView {
}

@objc private func scrollViewBoundsHandler(_ notification: Notification) {
guard let documentView = scrollView.documentView else { return }

let clipView = scrollView.contentView
let bottomDistance = documentView.bounds.height - (clipView.bounds.origin.y + clipView.bounds.height)
if bottomDistance == 0 {
let notification = Notification(
name: MainView.reachBottomNotification,
object: nil)
NotificationCenter.default.post(notification)
guard let documentBounds = scrollView.documentView?.frame else { return }
let insets = scrollView.contentView.contentInsets

let clipBounds = scrollView.contentView.bounds

let bottomDistance = Config.shared.scrollDirection == .vertical
? documentBounds.height - (clipBounds.origin.y + clipBounds.height) + insets.bottom
: documentBounds.width - (clipBounds.origin.x + clipBounds.width) + insets.right
if bottomDistance != 0 { return }

}
let notification = Notification(
name: MainView.reachBottomNotification,
object: nil)
NotificationCenter.default.post(notification)
}
}

0 comments on commit 17fb0da

Please sign in to comment.