Skip to content

Commit 17fb0da

Browse files
authored
Merge pull request #43 from qwertyyb/fix/scroll-load
fix(view): 修复NSAttributedString导致渲染卡慢的问题;修复不会自动加载下一页的问题
2 parents 1071d6c + 9c5370a commit 17fb0da

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

YPaste/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>Explosion v1.0.0-alpha</string>
2121
<key>CFBundleVersion</key>
22-
<string>103046</string>
22+
<string>103067</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.utilities</string>
2525
<key>LSMinimumSystemVersion</key>

YPaste/PasteboardHandler.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,9 @@ extension PasteItem {
3131
if pType == .string {
3232
return NSAttributedString(string: String(data: data, encoding: .utf8) ?? "[error data]")
3333
}
34-
if pType == .html {
35-
// html使用nsattributedstring有渲染性能问题,先特殊处理
36-
let str = NSAttributedString(html: data, documentAttributes: nil)
37-
return NSAttributedString(string: str?.string ?? "[empty html data]")
38-
}
34+
// NSAttributedString 会有性能问题,导致应用卡死
3935
if let str = NSAttributedString(pasteboardPropertyList: data, ofType: pType) {
40-
return str
36+
return NSAttributedString(string: str.string)
4137
}
4238
if let url = URL(dataRepresentation: data, relativeTo: nil) {
4339
return NSAttributedString(string: url.absoluteString)

YPaste/Window/MainView.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,19 @@ class MainView: NSVisualEffectView {
164164
}
165165

166166
@objc private func scrollViewBoundsHandler(_ notification: Notification) {
167-
guard let documentView = scrollView.documentView else { return }
168-
169-
let clipView = scrollView.contentView
170-
let bottomDistance = documentView.bounds.height - (clipView.bounds.origin.y + clipView.bounds.height)
171-
if bottomDistance == 0 {
172-
let notification = Notification(
173-
name: MainView.reachBottomNotification,
174-
object: nil)
175-
NotificationCenter.default.post(notification)
167+
guard let documentBounds = scrollView.documentView?.frame else { return }
168+
let insets = scrollView.contentView.contentInsets
169+
170+
let clipBounds = scrollView.contentView.bounds
171+
172+
let bottomDistance = Config.shared.scrollDirection == .vertical
173+
? documentBounds.height - (clipBounds.origin.y + clipBounds.height) + insets.bottom
174+
: documentBounds.width - (clipBounds.origin.x + clipBounds.width) + insets.right
175+
if bottomDistance != 0 { return }
176176

177-
}
177+
let notification = Notification(
178+
name: MainView.reachBottomNotification,
179+
object: nil)
180+
NotificationCenter.default.post(notification)
178181
}
179182
}

0 commit comments

Comments
 (0)