CodeEditApp / CodeEditSourceEditor

A code editor view written in Swift powered by tree-sitter.
https://codeeditapp.github.io/CodeEditSourceEditor/documentation/codeeditsourceeditor
MIT License
497 stars 74 forks source link

Add NSTextStorage Initializer #248

Closed thecoolwinter closed 1 month ago

thecoolwinter commented 1 month ago

Description

Adds the ability to initialize the editor view using an NSTextStorage object, rather than a String binding. This allows users to use a more efficient method for storing text outside of the editor. It also means a developer who uses this API will avoid any extra string copying and can help avoid unnecessary view evaluations when using SwiftUI. That's because Bindings are compared to check if a new value was added when the value of the binding is set. Because a new value is set each keystroke, this results in the entire contents of the editor being compared character by character each keystroke.

This also adds a Text Coordinator called CombineCoordinator. This class passes on notifications to Combine streams and is a good example of a useful coordinator. This is necessary for the related issue. It could be implemented in CodeEdit but I felt it was useful as an example of a real-world coordinator and added documentation for it towards that purpose.

Additionally, I've updated the documentation for the package to reflect the current README as well as more information about coordinators.

Related Issues

Checklist

thecoolwinter commented 1 month ago

@CodeEditApp/maintainers can I get a review on this