This project started as an experiment to see if it was actually even possible to use NSTextView
+ TextKit 2. Prior to macOS 13, the combination had major usability issues. As of macOS 14, it is starting to seem like it may work well.
The whole idea here is flexibility. The components in this library are built to be assembled together as part of the text system you need. You can pick and choose, including omitting or overriding as required. SourceView
is intended to be as subclass-able as NSTextView
.
Features:
BaseTextView
: a minimalNSTextView
subclass to support correct functionalityTextMovementProcessor
: uses thedoCommandBy
delegate callback to improve source navigation and selection
dependencies: [
.package(url: "https://github.com/ChimeHQ/SourceView")
]
SourceView
is a sublcass of BaseTextView
from TextViewPlus. That class includes many customization options that can be useful for building a source editor.
A number of functions have been customized to provide better behavior for code. However, these call all still be further controlled with NSTextViewDelegate.textView(_:, doCommandBy:) -> Bool
moveWordLeft
moveWordLeftAndModifySelection
moveWordRight
moveWordRightAndModifySelection
moveToLeftEndOfLine
moveToLeftEndOfLineAndModifySelection
These functions all consider leading/trailing whitespace. And, offer customizable intra-word boundaries for navigation.
Indentation turns out to be both very complex and potentially expensive. SourceView can be integrated with an indentation calculation system to provide automatic whitespace control for certain operations.
insertTab
: indentation
insertBacktab
: indentation
deleteBackward
: indentation
paste
: indentation
pasteAsRichText
: converts to plain text
pasteAsPlainText
: aliased to paste
// Restores text selection on undo
func withUndo(named name: String? = nil, _ block: () throws -> Void) rethrows {
I prefer collaboration, and would love to find ways to work together if you have a similar project.
I prefer indentation with tabs for improved accessibility. But, I'd rather you use the system you want and make a PR than hesitate because of whitespace.
I'd love to hear from you! Get in touch via an issue or pull request.
I prefer collaboration, and would love to find ways to work together if you have a similar project.
I prefer indentation with tabs for improved accessibility. But, I'd rather you use the system you want and make a PR than hesitate because of whitespace.
By participating in this project you agree to abide by the Contributor Code of Conduct.