Skip to content

Commit ef9d357

Browse files
authored
Merge pull request #3 from mshibanami/macos-inset-improvements
macOS: Make the padding inside the editable text view clickable
2 parents 00eb797 + 7360088 commit ef9d357

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

Sources/ResizingTextView/ResizingTextView.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,13 @@ 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
)
123-
.padding(.vertical, isEditable ? 8 : 0)
124-
.padding(.horizontal, isEditable ? 9 : 0)
125128
.background(isEditable ? Color(UXColor.controlBackgroundColor) : .clear)
126129
.roundedFilledBorder(
127130
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)