Wrapper
class Wrapper: NSView, ChordProEditorDelegate
A wrapper for
NSScrollViewNSTextViewNSRulerView
-
Init the
NSViewDeclaration
Swift
override init(frame frameRect: NSRect)Parameters
frameRectThe rect of the
NSView -
Init the
NSViewDeclaration
Swift
required init?(coder: NSCoder)Parameters
coderThe
NSCoder -
The delegate for the text editor
Declaration
Swift
weak var delegate: NSTextViewDelegate? -
The scroll view of the text editor
Declaration
Swift
private lazy var scrollView: NSScrollView = { let scrollView = NSScrollView() scrollView.drawsBackground = true scrollView.borderType = .noBorder scrollView.hasVerticalScroller = true scrollView.hasHorizontalScroller = false scrollView.hasHorizontalRuler = false scrollView.hasVerticalRuler = true scrollView.rulersVisible = true scrollView.autoresizingMask = [.width, .height] scrollView.translatesAutoresizingMaskIntoConstraints = false return scrollView }() -
The actual text view
Declaration
Swift
lazy var textView: TextView = { let contentSize = scrollView.contentSize let textStorage = NSTextStorage() let layoutManager = LayoutManager() textStorage.addLayoutManager(layoutManager) let textContainer = NSTextContainer(containerSize: scrollView.frame.size) textContainer.widthTracksTextView = true textContainer.containerSize = NSSize( width: contentSize.width, height: CGFloat.greatestFiniteMagnitude ) layoutManager.addTextContainer(textContainer) let textView = TextView(frame: .zero, textContainer: textContainer) textView.autoresizingMask = .width textView.backgroundColor = NSColor.textBackgroundColor textView.delegate = self.delegate textView.font = .systemFont(ofSize: 8) textView.isEditable = true textView.isHorizontallyResizable = false textView.isVerticallyResizable = true textView.maxSize = NSSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude) textView.minSize = NSSize(width: 0, height: contentSize.height) textView.textColor = NSColor.labelColor textView.allowsUndo = true textView.isAutomaticQuoteSubstitutionEnabled = false textView.isAutomaticTextCompletionEnabled = false textView.isAutomaticTextReplacementEnabled = false textView.isAutomaticDashSubstitutionEnabled = false textView.isAutomaticSpellingCorrectionEnabled = false textView.layoutManager?.delegate = layoutManager textView.chordProEditorDelegate = self textView.textContainerInset = .init(width: 2, height: 0) textView.drawsBackground = false return textView }() -
The
NSRulerViewfor the line numbersDeclaration
Swift
lazy private var lineNumbers = LineNumbersView() -
Override
viewWillDrawto setup the editorDeclaration
Swift
override func viewWillDraw() -
Setup the scroll view
Declaration
Swift
func setupScrollViewConstraints() -
Setup the text view
Declaration
Swift
func setupTextView()
-
A delegate function to update a view
Declaration
Swift
func selectionNeedsDisplay()
View on GitHub