File tree 2 files changed +23
-10
lines changed
2 files changed +23
-10
lines changed Original file line number Diff line number Diff line change 20
20
@implementation SPTextView
21
21
22
22
- (instancetype )init {
23
-
24
- SPInteractiveTextStorage *textStorage = [[SPInteractiveTextStorage alloc ] init ];
25
-
26
- NSTextContainer *container = [self setupTextContainerWith: textStorage];
23
+ NSTextContainer *container = [self setupTextContainer ];
27
24
28
25
self = [super initWithFrame: CGRectZero textContainer: container];
29
26
if (self) {
30
- self.interactiveTextStorage = textStorage;
31
27
32
28
/*
33
29
Issue #188:
Original file line number Diff line number Diff line change 8
8
9
9
extension SPTextView {
10
10
@objc
11
- func setupTextContainer( with textStorage : SPInteractiveTextStorage ) -> NSTextContainer {
12
- let container = SPFallbackTextContainer ( size : . zero )
11
+ func setupTextContainer( ) -> NSTextContainer {
12
+ let container = makeContainer ( )
13
13
container. widthTracksTextView = true
14
14
container. heightTracksTextView = true
15
15
16
- // This value is set incase we need to fall back to text kit 1
17
- //
18
- container. textView = self
16
+ let textStorage = SPInteractiveTextStorage ( )
17
+ interactiveTextStorage = textStorage
19
18
20
19
// TextKit 2
21
20
//
@@ -27,12 +26,30 @@ extension SPTextView {
27
26
textLayoutManager. textContainer = container
28
27
29
28
} else {
29
+ let layoutManager = NSLayoutManager ( )
30
30
layoutManager. addTextContainer ( container)
31
31
textStorage. addLayoutManager ( layoutManager)
32
32
}
33
33
34
34
return container
35
35
}
36
+
37
+ private func makeContainer( ) -> NSTextContainer {
38
+ var container : NSTextContainer
39
+ if #available( iOS 17 . 0 , * ) {
40
+ let fallbackContainer = SPFallbackTextContainer ( size: . zero)
41
+
42
+ // This value is set incase we need to fall back to text kit 1
43
+ //
44
+ fallbackContainer. textView = self
45
+
46
+ container = fallbackContainer
47
+ } else {
48
+ container = NSTextContainer ( )
49
+ }
50
+
51
+ return container
52
+ }
36
53
}
37
54
38
55
// MARK: NSTextContentStorageDelegate
You can’t perform that action at this time.
0 commit comments