@@ -18,19 +18,21 @@ struct TextView: NSViewRepresentable {
1818 var foregroundColor : Color
1919 var onFocusChanged : ( ( Bool ) -> Void ) ?
2020 var onInsertNewline : ( ( ) -> Bool ) ?
21+ var textContainerInset : CGSize
2122
2223 init ( _ text: Binding < String > ,
23- placeholder: String ? = nil ,
24- isEditable: Bool = true ,
25- isScrollable: Bool = false ,
26- isSelectable: Bool = true ,
27- lineLimit: Int = 0 ,
24+ placeholder: String ? ,
25+ isEditable: Bool ,
26+ isScrollable: Bool ,
27+ isSelectable: Bool ,
28+ lineLimit: Int ,
2829 font: NSFont ,
29- canHaveNewLineCharacters: Bool = true ,
30- focusesNextKeyViewByTabKey: Bool = true ,
31- foregroundColor: Color = defaultForegroundColor,
32- onFocusChanged: ( ( Bool ) -> Void ) ? = nil ,
33- onInsertNewline: ( ( ) -> Bool ) ? = nil
30+ canHaveNewLineCharacters: Bool ,
31+ focusesNextKeyViewByTabKey: Bool ,
32+ foregroundColor: Color ? ,
33+ onFocusChanged: ( ( Bool ) -> Void ) ? ,
34+ onInsertNewline: ( ( ) -> Bool ) ? ,
35+ textContainerInset: CGSize ?
3436 ) {
3537 self . _text = text
3638 self . placeholder = placeholder
@@ -40,23 +42,16 @@ struct TextView: NSViewRepresentable {
4042 self . lineLimit = lineLimit
4143 self . canHaveNewLineCharacters = canHaveNewLineCharacters
4244 self . focusesNextKeyViewByTabKey = focusesNextKeyViewByTabKey
43- self . foregroundColor = foregroundColor
45+ self . foregroundColor = foregroundColor ?? Self . defaultForegroundColor
4446 self . font = font
4547 self . onFocusChanged = onFocusChanged
4648 self . onInsertNewline = onInsertNewline
47- }
48-
49- init ( text: String ) {
50- self . init (
51- Binding< String> . constant( text) ,
52- isEditable: false ,
53- font: NSFont . preferredFont ( forTextStyle: . body) ,
54- foregroundColor: Self . defaultForegroundColor)
49+ self . textContainerInset = textContainerInset ?? CGSize ( width: - 5 , height: 0 )
5550 }
5651
5752 func makeNSView( context: Context ) -> TextEnclosingScrollView {
5853 let textView = CustomTextView ( )
59- textView. textContainerInset = . init ( width : - 5 , height : 0 )
54+ textView. textContainerInset = textContainerInset
6055 textView. delegate = context. coordinator
6156 textView. isRichText = false
6257 textView. allowsUndo = true
0 commit comments