Skip to content

Text selection, grouping, indentation, and manipulation in Swift

License

Notifications You must be signed in to change notification settings

ChimeHQ/Ligature

Build Status Platforms Documentation Matrix

Ligature

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

Ligature includes aliases and implementations as needed to make parts of the UIKit and AppKit text interfaces source-compatible.

Warning

This is currently very WIP.

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.

// 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. This should be all automatically handled by the TextTokenizer protocol if you are using NSRange or NSTextRange. The cross-platform TextRange type cannot do this without additional work on your part, typically by involving the text view.

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 on mastodon.

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.

About

Text selection, grouping, indentation, and manipulation in Swift

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Languages