Skip to content

Latest commit

 

History

History
75 lines (53 loc) · 3.75 KB

README.md

File metadata and controls

75 lines (53 loc) · 3.75 KB

Build Status Platforms Documentation Matrix

Ligature

A Swift package to aid in text selection, grouping, and manipulation.

Ligature includes aliases and implementations as needed to make parts of the UIKit and AppKit text interfaces source-compatible. The core types actually go futher than this and should be fully text system-agnostic.

You also might be interested in Glyph, a TextKit 1/2 abstraction system, as well as general AppKit/UIKit stuff like NSUI or KeyCodes.

Installation

dependencies: [
    .package(url: "https://github.com/ChimeHQ/Ligature", branch: "main")
],

Usage

The core protocol for the tokenization functionality is TextTokenizer. It is a little more abstract than UITextInputTokenizer, but ultimately compatible. With UIKit, TextInputStringTokenizer is just a typealias for UITextInputStringTokenizer. Ligature provides an implementation for use with AppKit.

Warning

While quite usable, there are features the TextTokenizer API supports that are not fully implemented by the AppKit implementation.

// on UIKit
let tokenizer = TextInputStringTokenizer(textInput: someUITextView)

// with AppKit
let tokenizer = TextInputStringTokenizer(textInput: someNSTextInputClient)

Ligature uses platform-independent aliases to represent many text-related structures. For the most part, these are based on their UIKit representations. Typically, AppKit doesn't have a source-compatible implementation, so wrappers and/or compatible implementations are provided.

typealias TextPosition = UITextPosition
typealias TextRange = UITextRange
typealias TextGranularity = UITextGranularity
typealias TextStorageDirection = UITextStorageDirection
typealias TextDirection = UITextDirection
typealias UserInterfaceLayoutDirection = UIUserInterfaceLayoutDirection

There are a variety of range/position models within AppKit, UIKit, and even between TextKit 1 and 2. Some abstraction is, unfortunately, required to model this, and that is not free. If it is important to operate within NSRange values, you can use UTF16CodePointTextViewTextTokenizer directly.

Contributing and Collaboration

I would love to hear from you! Issues or pull requests work great. Both a Matrix space and Discord are available for live help, but I have a strong bias towards answering in the form of documentation. You can also find me here.

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.