The goal of this project is to build NSTextView replacement component utilizing TextKit 2. because many good reasons.
The component is developed to serve Swift Studio needs. (ST prefix stands for "Swift sTudio" because SS is not good prefix since 1939)
https://user-images.githubusercontent.com/758033/217397725-1e217c25-24ac-4d9b-9812-b3c7e324a1ca.mp4
TextKit 2 was announced during WWDC 2021 as a TextKit replacement for text layout and whatnot. Apple announced that NSTextView
, the view component specialized for text editing, will adopt TextKit2 and provide support along TextKit1 bits. As I started to learn more about NSTextView
+ TextKit2, I realized as of today (Feb 2022), neither NSTextView is fully functional, nor TextKit2 classes are fully functional. Along the way, I reported several bug reports to Apple requested DTS (support tickets). Eventually, I've got blocked by specific bugs that pushed me to start this project.
STTextView is distributed using the Swift Package Manager. Install it in a project by adding it as a dependency in your Package.swift
manifest or through “Package Dependencies” in Xcode project settings
let package = Package(
dependencies: [
.package(url: "https://github.com/krzyzanowskim/STTextView", from: "0.1.2")
]
)
The STTextView is a subclass of NSView and as such can be initialized like any other view. It has an API that is similar to the one of NSTextView.
let textView = STTextView()
view.addSubView(textView)
let textView = STTextView()
let scrollView = NSScrollView()
scrollView.documentView = textView
The text view can be customized in a variety of ways.
let paragraph = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
// Set the line-height to 110%
paragraph.lineHeightMultiple = 1.1
paragraph.defaultTabInterval = 28
// Default Paragraph
textView.defaultParagraphStyle = paragraph
// Set default font
textView.font = NSFont.monospacedSystemFont(ofSize: 14, weight: .regular)
// Set default text color
textView.textColor = NSColor.textColor
// Set text value
textView.string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ornare lobortis sem a vulputate."
textView.addAttributes([.foregroundColor: NSColor.red], range: NSRange(location: 10, length: 5))
// Set wrapping
textView.widthTracksTextView = true
// Highlight the selected line.
textView.highlightSelectedLine = true
Add line numbers using specialized STLineNumberRulerView
(specialized subclass of NSRulerView
)
let textView = STTextView()
let scrollView = NSScrollView()
scrollView.documentView = textView
// Line numbers
let rulerView = STLineNumberRulerView(textView: textView)
// Configure the ruler view
rulerView.drawHighlightedRuler = true
// Set text color of the selected line number
rulerView.highlightLineNumberColor = .textColor
// Add to NSScrollView containing STTextView
scrollView.verticalRulerView = rulerView
scrollView.rulersVisible = true
Enable an optional search-and-replace find interface inside a view, usually a scroll view.
textView.textFinder.isIncrementalSearchingEnabled = true
textView.textFinder.incrementalSearchingShouldDimContentView = true
List of issues I reported to Apple so far:
... I'm aware that the list of issues is not complete.
I'd love to hear from you! Get in touch via twitter @krzyzanowskim, or a pull request.
If you are creating an open source application under a license compatible with the GNU GPL license v3, you may use STTextView under the terms of the GPLv3.
Get one starting from $5.
If you want to use STTextView to develop non open sourced product, and applications, the Commercial license is the appropriate license. With this option, your source code is kept proprietary. Which means, you won't have to change your whole application source code to an open source license. Purchase a STTextView Commercial License
link |
Stars: 480 |
Last commit: 17 hours ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics