@@ -28,6 +28,7 @@ public class TextViewController: NSViewController {
28
28
internal var highlightLayers : [ CALayer ] = [ ]
29
29
internal var systemAppearance : NSAppearance . Name ?
30
30
31
+ package var localEvenMonitor : Any ?
31
32
package var isPostingCursorNotification : Bool = false
32
33
33
34
/// The string contents.
@@ -172,15 +173,15 @@ public class TextViewController: NSViewController {
172
173
/// This will be `nil` if another highlighter provider is passed to the source editor.
173
174
internal( set) public var treeSitterClient : TreeSitterClient ?
174
175
175
- private var fontCharWidth : CGFloat { ( " " as NSString ) . size ( withAttributes: [ . font: font] ) . width }
176
+ package var fontCharWidth : CGFloat { ( " " as NSString ) . size ( withAttributes: [ . font: font] ) . width }
176
177
177
178
/// Filters used when applying edits..
178
179
internal var textFilters : [ TextFormation . Filter ] = [ ]
179
180
180
181
internal var cancellables = Set < AnyCancellable > ( )
181
182
182
183
/// ScrollView's bottom inset using as editor overscroll
183
- private var bottomContentInsets : CGFloat {
184
+ package var bottomContentInsets : CGFloat {
184
185
let height = view. frame. height
185
186
var inset = editorOverscroll * height
186
187
@@ -270,15 +271,7 @@ public class TextViewController: NSViewController {
270
271
// MARK: Paragraph Style
271
272
272
273
/// A default `NSParagraphStyle` with a set `lineHeight`
273
- internal lazy var paragraphStyle : NSMutableParagraphStyle = generateParagraphStyle ( )
274
-
275
- private func generateParagraphStyle( ) -> NSMutableParagraphStyle {
276
- // swiftlint:disable:next force_cast
277
- let paragraph = NSParagraphStyle . default. mutableCopy ( ) as! NSMutableParagraphStyle
278
- paragraph. tabStops. removeAll ( )
279
- paragraph. defaultTabInterval = CGFloat ( tabWidth) * fontCharWidth
280
- return paragraph
281
- }
274
+ package lazy var paragraphStyle : NSMutableParagraphStyle = generateParagraphStyle ( )
282
275
283
276
// MARK: - Reload UI
284
277
@@ -293,59 +286,6 @@ public class TextViewController: NSViewController {
293
286
highlighter? . invalidate ( )
294
287
}
295
288
296
- /// Style the text view.
297
- package func styleTextView( ) {
298
- textView. selectionManager. selectionBackgroundColor = theme. selection
299
- textView. selectionManager. selectedLineBackgroundColor = getThemeBackground ( )
300
- textView. selectionManager. highlightSelectedLine = isEditable
301
- textView. selectionManager. insertionPointColor = theme. insertionPoint
302
- paragraphStyle = generateParagraphStyle ( )
303
- textView. typingAttributes = attributesFor ( nil )
304
- }
305
-
306
- /// Finds the preferred use theme background.
307
- /// - Returns: The background color to use.
308
- private func getThemeBackground( ) -> NSColor {
309
- if useThemeBackground {
310
- return theme. lineHighlight
311
- }
312
-
313
- if systemAppearance == . darkAqua {
314
- return NSColor . quaternaryLabelColor
315
- }
316
-
317
- return NSColor . selectedTextBackgroundColor. withSystemEffect ( . disabled)
318
- }
319
-
320
- /// Style the gutter view.
321
- package func styleGutterView( ) {
322
- gutterView. frame. origin. y = - scrollView. contentInsets. top
323
- gutterView. selectedLineColor = useThemeBackground ? theme. lineHighlight : systemAppearance == . darkAqua
324
- ? NSColor . quaternaryLabelColor
325
- : NSColor . selectedTextBackgroundColor. withSystemEffect ( . disabled)
326
- gutterView. highlightSelectedLines = isEditable
327
- gutterView. font = font. rulerFont
328
- gutterView. backgroundColor = useThemeBackground ? theme. background : . textBackgroundColor
329
- if self . isEditable == false {
330
- gutterView. selectedLineTextColor = nil
331
- gutterView. selectedLineColor = . clear
332
- }
333
- }
334
-
335
- /// Style the scroll view.
336
- package func styleScrollView( ) {
337
- guard let scrollView = view as? NSScrollView else { return }
338
- scrollView. drawsBackground = useThemeBackground
339
- scrollView. backgroundColor = useThemeBackground ? theme. background : . clear
340
- if let contentInsets {
341
- scrollView. automaticallyAdjustsContentInsets = false
342
- scrollView. contentInsets = contentInsets
343
- } else {
344
- scrollView. automaticallyAdjustsContentInsets = true
345
- }
346
- scrollView. contentInsets. bottom = ( contentInsets? . bottom ?? 0 ) + bottomContentInsets
347
- }
348
-
349
289
deinit {
350
290
if let highlighter {
351
291
textView. removeStorageDelegate ( highlighter)
@@ -354,6 +294,10 @@ public class TextViewController: NSViewController {
354
294
highlightProvider = nil
355
295
NotificationCenter . default. removeObserver ( self )
356
296
cancellables. forEach { $0. cancel ( ) }
297
+ if let localEvenMonitor {
298
+ NSEvent . removeMonitor ( localEvenMonitor)
299
+ }
300
+ localEvenMonitor = nil
357
301
}
358
302
}
359
303
0 commit comments