Skip to content

Commit f77ae4a

Browse files
committed
Move some file for linter
1 parent f1888f0 commit f77ae4a

File tree

2 files changed

+43
-33
lines changed

2 files changed

+43
-33
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// TextView+SetText.swift
3+
// CodeEditTextView
4+
//
5+
// Created by Khan Winter on 1/12/25.
6+
//
7+
8+
import AppKit
9+
10+
extension TextView {
11+
/// Sets the text view's text to a new value.
12+
/// - Parameter text: The new contents of the text view.
13+
public func setText(_ text: String) {
14+
let newStorage = NSTextStorage(string: text)
15+
self.setTextStorage(newStorage)
16+
}
17+
18+
/// Set a new text storage object for the view.
19+
/// - Parameter textStorage: The new text storage to use.
20+
public func setTextStorage(_ textStorage: NSTextStorage) {
21+
self.textStorage = textStorage
22+
23+
subviews.forEach { view in
24+
view.removeFromSuperview()
25+
}
26+
27+
textStorage.addAttributes(typingAttributes, range: documentRange)
28+
layoutManager.textStorage = textStorage
29+
layoutManager.reset()
30+
31+
selectionManager.textStorage = textStorage
32+
selectionManager.setSelectedRanges(selectionManager.textSelections.map { $0.range })
33+
34+
_undoManager?.clearStack()
35+
36+
textStorage.delegate = storageDelegate
37+
needsDisplay = true
38+
needsLayout = true
39+
}
40+
}

Sources/CodeEditTextView/TextView/TextView.swift

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,11 @@ public class TextView: NSView, NSTextContent {
234234
/// - Warning: Do not update the text storage object directly. Doing so will very likely break the text view's
235235
/// layout system. Use methods like ``TextView/replaceCharacters(in:with:)-58mt7`` or
236236
/// ``TextView/insertText(_:)`` to modify content.
237-
private(set) public var textStorage: NSTextStorage!
237+
package(set) public var textStorage: NSTextStorage!
238238
/// The layout manager for the text view.
239-
private(set) public var layoutManager: TextLayoutManager!
239+
package(set) public var layoutManager: TextLayoutManager!
240240
/// The selection manager for the text view.
241-
private(set) public var selectionManager: TextSelectionManager!
241+
package(set) public var selectionManager: TextSelectionManager!
242242

243243
/// Empasizse text ranges in the text view
244244
public var emphasizeAPI: EmphasizeAPI?
@@ -325,36 +325,6 @@ public class TextView: NSView, NSTextContent {
325325
setUpDragGesture()
326326
}
327327

328-
/// Sets the text view's text to a new value.
329-
/// - Parameter text: The new contents of the text view.
330-
public func setText(_ text: String) {
331-
let newStorage = NSTextStorage(string: text)
332-
self.setTextStorage(newStorage)
333-
}
334-
335-
/// Set a new text storage object for the view.
336-
/// - Parameter textStorage: The new text storage to use.
337-
public func setTextStorage(_ textStorage: NSTextStorage) {
338-
self.textStorage = textStorage
339-
340-
subviews.forEach { view in
341-
view.removeFromSuperview()
342-
}
343-
344-
textStorage.addAttributes(typingAttributes, range: documentRange)
345-
layoutManager.textStorage = textStorage
346-
layoutManager.reset()
347-
348-
selectionManager.textStorage = textStorage
349-
selectionManager.setSelectedRanges(selectionManager.textSelections.map { $0.range })
350-
351-
_undoManager?.clearStack()
352-
353-
textStorage.delegate = storageDelegate
354-
needsDisplay = true
355-
needsLayout = true
356-
}
357-
358328
required init?(coder: NSCoder) {
359329
fatalError("init(coder:) has not been implemented")
360330
}

0 commit comments

Comments
 (0)