Skip to content

Commit 1226b56

Browse files
committed
macOS: Use textContainerInset for the paddings inside the editable text view
1 parent 00eb797 commit 1226b56

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

Sources/ResizingTextView/ResizingTextView.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,17 @@ public struct ResizingTextView: View, Equatable {
118118
}
119119
},
120120
onInsertNewline: onInsertNewline,
121-
textContainerInset: textContainerInset
121+
textContainerInset: textContainerInset ?? {
122+
var inset = CGSize(width: -5, height: 0)
123+
inset.width += (isEditable ? 9 : 0)
124+
inset.height += (isEditable ? 8 : 0)
125+
return inset
126+
}()
122127
)
128+
#if os(iOS)
123129
.padding(.vertical, isEditable ? 8 : 0)
124130
.padding(.horizontal, isEditable ? 9 : 0)
131+
#endif
125132
.background(isEditable ? Color(UXColor.controlBackgroundColor) : .clear)
126133
.roundedFilledBorder(
127134
isEditable ? Color(UXColor.separatorColor) : .clear,

Sources/ResizingTextView/TextView (AppKit).swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct TextView: NSViewRepresentable {
3333
foregroundColor: Color?,
3434
onFocusChanged: ((Bool) -> Void)?,
3535
onInsertNewline: (() -> Bool)?,
36-
textContainerInset: CGSize?
36+
textContainerInset: CGSize
3737
) {
3838
self._text = text
3939
self.placeholder = placeholder
@@ -47,7 +47,7 @@ struct TextView: NSViewRepresentable {
4747
self.font = font
4848
self.onFocusChanged = onFocusChanged
4949
self.onInsertNewline = onInsertNewline
50-
self.textContainerInset = textContainerInset ?? CGSize(width: -5, height: 0)
50+
self.textContainerInset = textContainerInset
5151
}
5252

5353
func makeNSView(context: Context) -> TextEnclosingScrollView {
@@ -138,6 +138,7 @@ struct TextView: NSViewRepresentable {
138138
textView.textContainer?.lineBreakMode = .byTruncatingTail
139139
}
140140
}
141+
141142
if !context.coordinator.selectedRanges.isEmpty,
142143
textView.selectedRanges != context.coordinator.selectedRanges {
143144
textView.selectedRanges = context.coordinator.selectedRanges

0 commit comments

Comments
 (0)