|
6 | 6 | import SwiftUI |
7 | 7 | import AppKit |
8 | 8 |
|
| 9 | +// MARK: - Non-Scrolling Scroll View |
| 10 | + |
| 11 | +private class NonScrollingScrollView: NSScrollView { |
| 12 | + var scrollingEnabled: Bool = true |
| 13 | + |
| 14 | + override func scrollWheel(with event: NSEvent) { |
| 15 | + if scrollingEnabled { |
| 16 | + super.scrollWheel(with: event) |
| 17 | + } else { |
| 18 | + nextResponder?.scrollWheel(with: event) |
| 19 | + } |
| 20 | + } |
| 21 | +} |
| 22 | + |
9 | 23 | // MARK: - Custom Table View with Copy Support |
10 | 24 |
|
11 | 25 | private class ChatDiffTableView: NSTableView { |
@@ -172,8 +186,15 @@ struct SelectableDiffView: NSViewRepresentable { |
172 | 186 | let fontFamily: String |
173 | 187 | var scrollable: Bool = true |
174 | 188 |
|
| 189 | + static func calculateRowHeight(fontSize: Double, fontFamily: String) -> CGFloat { |
| 190 | + let font = NSFont(name: fontFamily, size: fontSize) ?? NSFont.monospacedSystemFont(ofSize: fontSize, weight: .regular) |
| 191 | + return ceil(font.ascender - font.descender + font.leading) + 4 |
| 192 | + } |
| 193 | + |
175 | 194 | func makeNSView(context: Context) -> NSScrollView { |
176 | | - let scrollView = NSScrollView() |
| 195 | + let scrollView = NonScrollingScrollView() |
| 196 | + scrollView.scrollingEnabled = scrollable |
| 197 | + |
177 | 198 | let tableView = ChatDiffTableView() |
178 | 199 | tableView.coordinator = context.coordinator |
179 | 200 |
|
@@ -220,6 +241,9 @@ struct SelectableDiffView: NSViewRepresentable { |
220 | 241 | } |
221 | 242 |
|
222 | 243 | func updateNSView(_ scrollView: NSScrollView, context: Context) { |
| 244 | + if let nonScrolling = scrollView as? NonScrollingScrollView { |
| 245 | + nonScrolling.scrollingEnabled = scrollable |
| 246 | + } |
223 | 247 | context.coordinator.updateData(lines: lines, fontSize: fontSize, fontFamily: fontFamily) |
224 | 248 | } |
225 | 249 |
|
|
0 commit comments