Skip to content

Latest commit

 

History

History
51 lines (40 loc) · 1.6 KB

File metadata and controls

51 lines (40 loc) · 1.6 KB

STTextView Source Code Syntax Highlighting with TreeSitter, Neon and CodeEditLanguages.

Most code in this repo is borrowed from STTextView-Plugin-Neon, with some adaptations to work with CodeEditLanguages.

Installation

Add the plugin package as a dependency of your application, then register/add it to the STTextView instance:

import NeonCodeEditLanguagesPlugin

textView.addPlugin(
    NeonCodeEditLanguagesPlugin(
        theme: .default,
        language: .go
    )
)

SwiftUI:

import SwiftUI
import STTextViewUI
import NeonCodeEditLanguagesPlugin

struct ContentView: View {
    @State private var text: AttributedString = ""
    @State private var selection: NSRange?
    var body: some View {
        STTextViewUI.TextView(
            text: $text,
            selection: $selection,
            options: [.wrapLines, .highlightSelectedLine],
            plugins: [NeonCodeEditLanguagesPlugin(theme: .default, language: .go)]
        )
        .textViewFont(.monospacedDigitSystemFont(ofSize: NSFont.systemFontSize, weight: .regular))
        .onAppear {
            loadContent()
        }
    }

    private func loadContent() {
        // (....)
        self.text = AttributedString(string)
    }
}
Default Theme