@@ -45,6 +45,9 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
45
45
/// The editorOverscroll to use for the textView over scroll
46
46
public var editorOverscroll : Double
47
47
48
+ /// Whether lines wrap to the width of the editor
49
+ public var wrapLines : Bool
50
+
48
51
// MARK: - Highlighting
49
52
50
53
internal var highlighter : Highlighter ?
@@ -58,6 +61,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
58
61
font: NSFont ,
59
62
theme: EditorTheme ,
60
63
tabWidth: Int ,
64
+ wrapLines: Bool ,
61
65
cursorPosition: Published < ( Int , Int ) > . Publisher ? = nil ,
62
66
editorOverscroll: Double
63
67
) {
@@ -66,6 +70,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
66
70
self . font = font
67
71
self . theme = theme
68
72
self . tabWidth = tabWidth
73
+ self . wrapLines = wrapLines
69
74
self . cursorPosition = cursorPosition
70
75
self . editorOverscroll = editorOverscroll
71
76
super. init ( nibName: nil , bundle: nil )
@@ -78,23 +83,19 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
78
83
// MARK: VC Lifecycle
79
84
80
85
public override func loadView( ) {
81
- let scrollView = STTextView . scrollableTextView ( )
82
- textView = scrollView. documentView as? STTextView
83
-
84
- // By default this is always null but is required for a couple operations
85
- // during highlighting so we make a new one manually.
86
- textView. textContainer. replaceLayoutManager ( NSLayoutManager ( ) )
86
+ textView = STTextView ( )
87
87
88
+ let scrollView = NSScrollView ( )
88
89
scrollView. translatesAutoresizingMaskIntoConstraints = false
89
90
scrollView. hasVerticalScroller = true
91
+ scrollView. documentView = textView
90
92
91
93
rulerView = STLineNumberRulerView ( textView: textView, scrollView: scrollView)
92
94
rulerView. backgroundColor = theme. background
93
95
rulerView. textColor = . systemGray
94
96
rulerView. drawSeparator = false
95
97
rulerView. baselineOffset = baselineOffset
96
98
rulerView. font = NSFont . monospacedDigitSystemFont ( ofSize: 9.5 , weight: . regular)
97
-
98
99
scrollView. verticalRulerView = rulerView
99
100
scrollView. rulersVisible = true
100
101
@@ -107,7 +108,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
107
108
textView. selectionBackgroundColor = theme. selection
108
109
textView. selectedLineHighlightColor = theme. lineHighlight
109
110
textView. string = self . text. wrappedValue
110
- textView. widthTracksTextView = true
111
+ textView. widthTracksTextView = self . wrapLines
111
112
textView. highlightSelectedLine = true
112
113
textView. allowsUndo = true
113
114
textView. setupMenus ( )
0 commit comments