@@ -45,6 +45,9 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
4545 /// The editorOverscroll to use for the textView over scroll
4646 public var editorOverscroll : Double
4747
48+ /// Whether lines wrap to the width of the editor
49+ public var wrapLines : Bool
50+
4851 // MARK: - Highlighting
4952
5053 internal var highlighter : Highlighter ?
@@ -58,6 +61,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
5861 font: NSFont ,
5962 theme: EditorTheme ,
6063 tabWidth: Int ,
64+ wrapLines: Bool ,
6165 cursorPosition: Published < ( Int , Int ) > . Publisher ? = nil ,
6266 editorOverscroll: Double
6367 ) {
@@ -66,6 +70,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
6670 self . font = font
6771 self . theme = theme
6872 self . tabWidth = tabWidth
73+ self . wrapLines = wrapLines
6974 self . cursorPosition = cursorPosition
7075 self . editorOverscroll = editorOverscroll
7176 super. init ( nibName: nil , bundle: nil )
@@ -78,23 +83,19 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
7883 // MARK: VC Lifecycle
7984
8085 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 ( )
8787
88+ let scrollView = NSScrollView ( )
8889 scrollView. translatesAutoresizingMaskIntoConstraints = false
8990 scrollView. hasVerticalScroller = true
91+ scrollView. documentView = textView
9092
9193 rulerView = STLineNumberRulerView ( textView: textView, scrollView: scrollView)
9294 rulerView. backgroundColor = theme. background
9395 rulerView. textColor = . systemGray
9496 rulerView. drawSeparator = false
9597 rulerView. baselineOffset = baselineOffset
9698 rulerView. font = NSFont . monospacedDigitSystemFont ( ofSize: 9.5 , weight: . regular)
97-
9899 scrollView. verticalRulerView = rulerView
99100 scrollView. rulersVisible = true
100101
@@ -107,7 +108,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
107108 textView. selectionBackgroundColor = theme. selection
108109 textView. selectedLineHighlightColor = theme. lineHighlight
109110 textView. string = self . text. wrappedValue
110- textView. widthTracksTextView = true
111+ textView. widthTracksTextView = self . wrapLines
111112 textView. highlightSelectedLine = true
112113 textView. allowsUndo = true
113114 textView. setupMenus ( )
0 commit comments