Skip to content

Commit 4e433c5

Browse files
committed
Pass text wrapping configurations through to CodeEditTextView
1 parent 561fa9d commit 4e433c5

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

Sources/CodeEditTextView/CodeEditTextView.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public struct CodeEditTextView: NSViewControllerRepresentable {
2020
/// - font: The default font
2121
/// - tabWidth: The tab width
2222
/// - lineHeight: The line height multiplier (e.g. `1.2`)
23+
/// - wrapLines: Whether lines wrap to the width of the editor
24+
/// - wrappedIndent: The number of spaces to indent wrapped lines
2325
/// - editorOverscroll: The percentage for overscroll, between 0-1 (default: `0.0`)
2426
public init(
2527
_ text: Binding<String>,
@@ -28,6 +30,8 @@ public struct CodeEditTextView: NSViewControllerRepresentable {
2830
font: Binding<NSFont>,
2931
tabWidth: Binding<Int>,
3032
lineHeight: Binding<Double>,
33+
wrapLines: Binding<Bool>,
34+
wrappedIndent: Binding<Int>,
3135
editorOverscroll: Binding<Double> = .constant(0.0),
3236
cursorPosition: Published<(Int, Int)>.Publisher? = nil
3337
) {
@@ -37,6 +41,8 @@ public struct CodeEditTextView: NSViewControllerRepresentable {
3741
self._font = font
3842
self._tabWidth = tabWidth
3943
self._lineHeight = lineHeight
44+
self._wrapLines = wrapLines
45+
self._wrappedIndent = wrappedIndent
4046
self._editorOverscroll = editorOverscroll
4147
self.cursorPosition = cursorPosition
4248
}
@@ -47,6 +53,8 @@ public struct CodeEditTextView: NSViewControllerRepresentable {
4753
@Binding private var font: NSFont
4854
@Binding private var tabWidth: Int
4955
@Binding private var lineHeight: Double
56+
@Binding private var wrapLines: Bool
57+
@Binding private var wrappedIndent: Int
5058
@Binding private var editorOverscroll: Double
5159
private var cursorPosition: Published<(Int, Int)>.Publisher?
5260

@@ -59,6 +67,8 @@ public struct CodeEditTextView: NSViewControllerRepresentable {
5967
font: font,
6068
theme: theme,
6169
tabWidth: tabWidth,
70+
wrapLines: wrapLines,
71+
wrappedIndent: wrappedIndent,
6272
cursorPosition: cursorPosition,
6373
editorOverscroll: editorOverscroll
6474
)
@@ -71,6 +81,8 @@ public struct CodeEditTextView: NSViewControllerRepresentable {
7181
controller.language = language
7282
controller.theme = theme
7383
controller.tabWidth = tabWidth
84+
controller.wrapLines = wrapLines
85+
controller.wrappedIndent = wrappedIndent
7486
controller.lineHeightMultiple = lineHeight
7587
controller.editorOverscroll = editorOverscroll
7688
controller.reloadUI()

Sources/CodeEditTextView/STTextViewController.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
4444

4545
/// The editorOverscroll to use for the textView over scroll
4646
public var editorOverscroll: Double
47+
48+
/// Whether lines wrap to the width of the editor
49+
public var wrapLines: Bool
50+
51+
/// The number of spaces to indent wrapped lines
52+
public var wrappedIndent: Int
4753

4854
// MARK: - Highlighting
4955

@@ -58,6 +64,8 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
5864
font: NSFont,
5965
theme: EditorTheme,
6066
tabWidth: Int,
67+
wrapLines: Bool,
68+
wrappedIndent: Int,
6169
cursorPosition: Published<(Int, Int)>.Publisher? = nil,
6270
editorOverscroll: Double
6371
) {
@@ -66,6 +74,8 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
6674
self.font = font
6775
self.theme = theme
6876
self.tabWidth = tabWidth
77+
self.wrapLines = wrapLines
78+
self.wrappedIndent = wrappedIndent
6979
self.cursorPosition = cursorPosition
7080
self.editorOverscroll = editorOverscroll
7181
super.init(nibName: nil, bundle: nil)
@@ -83,7 +93,7 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt
8393

8494
// By default this is always null but is required for a couple operations
8595
// during highlighting so we make a new one manually.
86-
textView.textContainer.replaceLayoutManager(NSLayoutManager())
96+
// textView.textContainer.replaceLayoutManager(NSLayoutManager())
8797

8898
scrollView.translatesAutoresizingMaskIntoConstraints = false
8999
scrollView.hasVerticalScroller = true

0 commit comments

Comments
 (0)