Git Product home page Git Product logo

textstory's Introduction

Build Status Platforms

TextStory

TextStory is a small set of classes and protocols for easier work with NSTextStorage and associated systems.

Integration

Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/ChimeHQ/TextStory")
]

TSYTextStorage

A minimal NSTextStorage subclass that provides hooks for much more powerful delegate behavior. Great for separating logic/behavior from your storage object. Because it is built to wrap another NSTextStorage instance, it is more easily composable.

Unfortunately, to date I've not been able to figure out a way to build this class in Swift. If you have experience working with NSTextStorage and Swift/ObjC automatic NSString/String bridging, I'd love to hear from you.

- (void)textStorage:(TSYTextStorage *)textStorage willReplaceCharactersInRange:(NSRange)range withString:(NSString *)string;
- (void)textStorage:(TSYTextStorage *)textStorage didReplaceCharactersInRange:(NSRange)range withString:(NSString *)string;
- (void)textStorageProcessEditingComplete:(TSYTextStorage *)textStorage;

// available for macOS only
- (NSRange)textStorage:(TSYTextStorage *)textStorage doubleClickRangeForLocation:(NSUInteger)location;
- (NSUInteger)textStorage:(TSYTextStorage *)textStorage nextWordIndexFromLocation:(NSUInteger)location direction:(BOOL)forward;

BufferingTextStorage

An NSTextStorage subclass that maintains a history of text changes with low memory and performance overhead. This class makes it possible to decouple text change processing from them Cocoa text display system, making them asynchronous with respect to each other. Very useful for keeping your UI fast and responsive even if the processing of changes can be slow.

// interact with the buffered view of text
func bufferedSubstring(from range: NSRange) -> String
var bufferedLength: Int

// commit one change in the queue, allowing precise control over how the buffered view changes
func applyNextChange()

TextStoring

A simple protocol that abstracts string storage. This is very useful for standardizing behavior across NSTextStorage and other objects you may use for text manipulation. Particularly handy for testing and decoupling systems from Apple's classes behaviors/APIs.

In order to maintain flexiblity and match NSTextStorage, TextStoring is not actor-isolated.

TextStorageAdapter

It isn't possible to make NSTextView/UITextView conform to TextStoring, because they are MainActor-isolated classes. This adapter exists to help use a view with TextStoring.

TextStoringMonitor

Standard interface for systems that need to observe and react to changes in a TextStoring instance.

LazyTextStoringMonitor

A concrete TextStoringMonitor class that implements progressive, on-demand access to a wrapped TextStoringMonitor. This makes it easy to add lazy semantics on top of an existing TextStoringMonitor, which can be very helpful for handling large documents.

CompositeTextStoringMonitor

An easy way to group together a collection of TextStoringMonitor instances and tread them as a single unit.

TextMutationEventRouter

This class can accept and route TSYTextStorage delegate callbacks to multiple TextStoringMonitor instances. This is super handy for faning-out these calls.

Contributing and Collaboration

I'd love to hear from you! Get in touch via an issue or pull request.

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.

textstory's People

Contributors

fcanas avatar mattmassicotte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

textstory's Issues

Support for SPM

I failed to add SPM support for this project, but sounds like that was just due to lack of effort. Numerous people have mentioned that a separate target for the ObjC stuff will work.

TSYTextStorage in Swift?

Originally, this library was all Swift. However, I ran into some terrible performance issues, that I eventually tracked down to interactions between NSString and Swift String conversions. This surprised me quite a bit, but it seems like the Cocoa text system heavily depends on string reference semantics for performance in this area.

I have to confess that I did some searches, found others with similar issues, and then just wrote the class in ObjC and moved on. It's a very straight-forward implementation. But, it would be pretty interesting to see if/how this could be done in Swift. It's been a while, so perhaps things have changed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.