ITADN
CodeEditApp/CodeEditTextView
CodeEditApp/CodeEditTextView · 文件 下载 ZIP
文件最后提交记录最后更新时间
README.md
以下内容由 AI 翻译,如有问题请点此提交 issue 反馈

CodeEditTextView

一款专门用于显示和编辑代码文档的文本编辑器。功能包括基础文本编辑、极快的初始布局、支持处理大型文档以及代码文档的自定义选项。

GitHub release Github Tests GitHub Repo stars GitHub forks Discord Badge

[!IMPORTANT] 此包包含一个适用于在特定情况下替换 NSTextView 的文本视图。如果你需要一个能够处理从右到左文本、自定义布局元素或与系统文本视图功能对等的文本视图,请考虑使用 STTextViewNSTextView。本库导出的 TextView 旨在布局由文本行组成的文档。它也不尝试推断文档的内容。如果你希望编辑源代码(缩进、语法高亮),请考虑使用父级库 CodeEditSourceEditor

Documentation

此包已在此处](https://codeeditapp.github.io/CodeEditTextView/documentation/codeedittextview/)完整记录。

Usage

此包导出一个主要的 TextView 类。TextView 类是一个 NSView 子类,可以嵌入到滚动视图中或独立使用。它解析并渲染文档的行,并处理用于文本编辑的鼠标和键盘事件。它还渲染样式字符串,用于语法高亮等用例。

import CodeEditTextView
import AppKit

/// # ViewController
/// 
/// An example view controller for displaying a text view embedded in a scroll view.
class ViewController: NSViewController, TextViewDelegate {
    private var scrollView: NSScrollView!
    private var textView: TextView!
    
    var text: String = "func helloWorld() {\n\tprint(\"hello world\")\n}"
    var font: NSFont!
    var textColor: NSColor!
    
    override func loadView() {
		textView = TextView(
            string: text,
            font: font,
            textColor: textColor,
            lineHeightMultiplier: 1.0,
            wrapLines: true,
            isEditable: true,
            isSelectable: true,
            letterSpacing: 1.0,
            delegate: self
        )
        textView.translatesAutoresizingMaskIntoConstraints = false

        scrollView = NSScrollView()
        scrollView.translatesAutoresizingMaskIntoConstraints = false
        scrollView.hasVerticalScroller = true
        scrollView.hasHorizontalScroller = true
        scrollView.documentView = textView
        self.view = scrollView
		NSLayoutConstraint.activate([
            scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
            scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
            scrollView.topAnchor.constraint(equalTo: view.topAnchor),
            scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
        ])

        textView.updateFrameIfNeeded()
    }
}

许可证

基于 MIT 许可证

依赖项

特别感谢 Matt Massicotte 所做的出色工作!

包名来源作者
TextStoryGitHubMatt Massicotte
swift-collectionsGitHubApple

相关仓库

        CodeEdit        

CodeEditSourceEditor

     CodeEditKit     

CodeEditLanguages

    CodeEdit CLI